diff --git a/Cocoa/AppDelegate.m b/Cocoa/AppDelegate.m
index a9c5a9e2..96331a6e 100644
--- a/Cocoa/AppDelegate.m
+++ b/Cocoa/AppDelegate.m
@@ -35,7 +35,11 @@
@"GBFilter": @"NearestNeighbor",
@"GBColorCorrection": @(GB_COLOR_CORRECTION_EMULATE_HARDWARE),
@"GBHighpassFilter": @(GB_HIGHPASS_REMOVE_DC_OFFSET),
- @"GBRewindLength": @(10)
+ @"GBRewindLength": @(10),
+
+ @"GBDMGModel": @(GB_MODEL_DMG_B),
+ @"GBCGBModel": @(GB_MODEL_CGB_E),
+ @"GBSGBModel": @(GB_MODEL_SGB2),
}];
}
diff --git a/Cocoa/Document.m b/Cocoa/Document.m
index c65b69e5..30284ba9 100644
--- a/Cocoa/Document.m
+++ b/Cocoa/Document.m
@@ -19,14 +19,6 @@ enum model {
MODEL_SGB,
};
-static const GB_model_t cocoa_to_internal_model[] =
-{
- [MODEL_DMG] = GB_MODEL_DMG_B,
- [MODEL_CGB] = GB_MODEL_CGB_E,
- [MODEL_AGB] = GB_MODEL_AGB,
- [MODEL_SGB] = GB_MODEL_SGB,
-};
-
@interface Document ()
{
@@ -62,6 +54,7 @@ static const GB_model_t cocoa_to_internal_model[] =
enum model current_model;
bool rewind;
+ bool modelsChanging;
}
@property GBAudioClient *audioClient;
@@ -159,9 +152,27 @@ static void printImage(GB_gameboy_t *gb, uint32_t *image, uint8_t height,
return [[NSBundle mainBundle] pathForResource:name ofType:@"bin"];
}
+- (GB_model_t)internalModel
+{
+ switch (current_model) {
+ case MODEL_DMG:
+ return (GB_model_t)[[NSUserDefaults standardUserDefaults] integerForKey:@"GBDMGModel"];
+
+ case MODEL_NONE:
+ case MODEL_CGB:
+ return (GB_model_t)[[NSUserDefaults standardUserDefaults] integerForKey:@"GBCGBModel"];
+
+ case MODEL_SGB:
+ return (GB_model_t)[[NSUserDefaults standardUserDefaults] integerForKey:@"GBSGBModel"];
+
+ case MODEL_AGB:
+ return GB_MODEL_AGB;
+ }
+}
+
- (void) initCommon
{
- GB_init(&gb, cocoa_to_internal_model[current_model]);
+ GB_init(&gb, [self internalModel]);
GB_set_user_data(&gb, (__bridge void *)(self));
GB_set_vblank_callback(&gb, (GB_vblank_callback_t) vblank);
GB_set_log_callback(&gb, (GB_log_callback_t) consoleLog);
@@ -253,17 +264,18 @@ static void printImage(GB_gameboy_t *gb, uint32_t *image, uint8_t height,
{
[self stop];
size_t old_width = GB_get_screen_width(&gb);
- [self loadBootROM];
if ([sender tag] != MODEL_NONE) {
current_model = (enum model)[sender tag];
}
- if ([sender tag] == MODEL_NONE) {
+ [self loadBootROM];
+
+ if (!modelsChanging && [sender tag] == MODEL_NONE) {
GB_reset(&gb);
}
else {
- GB_switch_model_and_reset(&gb, cocoa_to_internal_model[current_model]);
+ GB_switch_model_and_reset(&gb, [self internalModel]);
}
if (old_width != GB_get_screen_width(&gb)) {
@@ -366,6 +378,21 @@ static void printImage(GB_gameboy_t *gb, uint32_t *image, uint8_t height,
name:@"GBRewindLengthChanged"
object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(dmgModelChanged)
+ name:@"GBDMGModelChanged"
+ object:nil];
+
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(sgbModelChanged)
+ name:@"GBSGBModelChanged"
+ object:nil];
+
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(cgbModelChanged)
+ name:@"GBCGBModelChanged"
+ object:nil];
+
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"EmulateDMG"]) {
current_model = MODEL_DMG;
}
@@ -1416,6 +1443,33 @@ static void printImage(GB_gameboy_t *gb, uint32_t *image, uint8_t height,
}];
}
+- (void)dmgModelChanged
+{
+ modelsChanging = true;
+ if (current_model == MODEL_DMG) {
+ [self reset:nil];
+ }
+ modelsChanging = false;
+}
+
+- (void)sgbModelChanged
+{
+ modelsChanging = true;
+ if (current_model == MODEL_SGB) {
+ [self reset:nil];
+ }
+ modelsChanging = false;
+}
+
+- (void)cgbModelChanged
+{
+ modelsChanging = true;
+ if (current_model == MODEL_CGB) {
+ [self reset:nil];
+ }
+ modelsChanging = false;
+}
+
- (void)setFileURL:(NSURL *)fileURL
{
[super setFileURL:fileURL];
diff --git a/Cocoa/GBPreferencesWindow.h b/Cocoa/GBPreferencesWindow.h
index 14d3a33f..b1284851 100644
--- a/Cocoa/GBPreferencesWindow.h
+++ b/Cocoa/GBPreferencesWindow.h
@@ -12,4 +12,9 @@
@property (strong) IBOutlet NSButton *skipButton;
@property (strong) IBOutlet NSMenuItem *bootROMsFolderItem;
@property (strong) IBOutlet NSPopUpButtonCell *bootROMsButton;
+
+@property (weak) IBOutlet NSPopUpButton *dmgPopupButton;
+@property (weak) IBOutlet NSPopUpButton *sgbPopupButton;
+@property (weak) IBOutlet NSPopUpButton *cgbPopupButton;
+
@end
diff --git a/Cocoa/GBPreferencesWindow.m b/Cocoa/GBPreferencesWindow.m
index 97f37d74..ae4b59fc 100644
--- a/Cocoa/GBPreferencesWindow.m
+++ b/Cocoa/GBPreferencesWindow.m
@@ -17,6 +17,8 @@
NSPopUpButton *_rewindPopupButton;
NSButton *_aspectRatioCheckbox;
NSEventModifierFlags previousModifiers;
+
+ NSPopUpButton *_dmgPopupButton, *_sgbPopupButton, *_cgbPopupButton;
}
+ (NSArray *)filterList
@@ -362,4 +364,59 @@
[self updateBootROMFolderButton];
}
+- (void)setDmgPopupButton:(NSPopUpButton *)dmgPopupButton
+{
+ _dmgPopupButton = dmgPopupButton;
+ [_dmgPopupButton selectItemWithTag:[[NSUserDefaults standardUserDefaults] integerForKey:@"GBDMGModel"]];
+}
+
+- (NSPopUpButton *)dmgPopupButton
+{
+ return _dmgPopupButton;
+}
+
+- (void)setSgbPopupButton:(NSPopUpButton *)sgbPopupButton
+{
+ _sgbPopupButton = sgbPopupButton;
+ [_sgbPopupButton selectItemWithTag:[[NSUserDefaults standardUserDefaults] integerForKey:@"GBSGBModel"]];
+}
+
+- (NSPopUpButton *)sgbPopupButton
+{
+ return _sgbPopupButton;
+}
+
+- (void)setCgbPopupButton:(NSPopUpButton *)cgbPopupButton
+{
+ _cgbPopupButton = cgbPopupButton;
+ [_cgbPopupButton selectItemWithTag:[[NSUserDefaults standardUserDefaults] integerForKey:@"GBCGBModel"]];
+}
+
+- (NSPopUpButton *)cgbPopupButton
+{
+ return _cgbPopupButton;
+}
+
+- (IBAction)dmgModelChanged:(id)sender
+{
+ [[NSUserDefaults standardUserDefaults] setObject:@([sender selectedTag])
+ forKey:@"GBDMGModel"];
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"GBDMGModelChanged" object:nil];
+
+}
+
+- (IBAction)sgbModelChanged:(id)sender
+{
+ [[NSUserDefaults standardUserDefaults] setObject:@([sender selectedTag])
+ forKey:@"GBSGBModel"];
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"GBSGBModelChanged" object:nil];
+}
+
+- (IBAction)cgbModelChanged:(id)sender
+{
+ [[NSUserDefaults standardUserDefaults] setObject:@([sender selectedTag])
+ forKey:@"GBCGBModel"];
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"GBCGBModelChanged" object:nil];
+}
+
@end
diff --git a/Cocoa/Preferences.xib b/Cocoa/Preferences.xib
index ff0df586..245bca88 100644
--- a/Cocoa/Preferences.xib
+++ b/Cocoa/Preferences.xib
@@ -61,13 +61,16 @@
+
+
+
@@ -166,11 +169,11 @@
-
+
-
+
@@ -194,7 +197,7 @@
-
+
@@ -203,7 +206,7 @@
-
+
@@ -212,7 +215,7 @@
-
+
@@ -235,8 +238,97 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -292,7 +384,7 @@
-
+