diff --git a/Cocoa/Document.m b/Cocoa/Document.m
index e74b24f..6b9915c 100644
--- a/Cocoa/Document.m
+++ b/Cocoa/Document.m
@@ -61,6 +61,8 @@ enum model {
size_t audioBufferSize;
size_t audioBufferPosition;
size_t audioBufferNeeded;
+
+ bool borderModeChanged;
}
@property GBAudioClient *audioClient;
@@ -212,6 +214,11 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample)
}
}
+- (void) updateBorderMode
+{
+ borderModeChanged = true;
+}
+
- (void) initCommon
{
GB_init(&gb, [self internalModel]);
@@ -222,6 +229,7 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample)
GB_set_input_callback(&gb, (GB_input_callback_t) consoleInput);
GB_set_async_input_callback(&gb, (GB_input_callback_t) asyncConsoleInput);
GB_set_color_correction_mode(&gb, (GB_color_correction_mode_t) [[NSUserDefaults standardUserDefaults] integerForKey:@"GBColorCorrection"]);
+ GB_set_border_mode(&gb, (GB_border_mode_t) [[NSUserDefaults standardUserDefaults] integerForKey:@"GBBorderMode"]);
[self updatePalette];
GB_set_rgb_encode_callback(&gb, rgbEncode);
GB_set_camera_get_pixel_callback(&gb, cameraGetPixel);
@@ -234,6 +242,16 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample)
- (void) vblank
{
[self.view flip];
+ if (borderModeChanged) {
+ dispatch_sync(dispatch_get_main_queue(), ^{
+ size_t previous_width = GB_get_screen_width(&gb);
+ GB_set_border_mode(&gb, (GB_border_mode_t) [[NSUserDefaults standardUserDefaults] integerForKey:@"GBBorderMode"]);
+ if (GB_get_screen_width(&gb) != previous_width) {
+ [self.view screenSizeChanged];
+ }
+ });
+ borderModeChanged = false;
+ }
GB_set_pixels_output(&gb, self.view.pixels);
if (self.vramWindow.isVisible) {
dispatch_async(dispatch_get_main_queue(), ^{
@@ -493,6 +511,10 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample)
name:@"GBColorPaletteChanged"
object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(updateBorderMode)
+ name:@"GBBorderModeChanged"
+ object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(updateRewindLength)
diff --git a/Cocoa/GBPreferencesWindow.h b/Cocoa/GBPreferencesWindow.h
index b34aafa..2d6b0fc 100644
--- a/Cocoa/GBPreferencesWindow.h
+++ b/Cocoa/GBPreferencesWindow.h
@@ -7,7 +7,8 @@
@property (strong) IBOutlet NSButton *aspectRatioCheckbox;
@property (strong) IBOutlet NSPopUpButton *highpassFilterPopupButton;
@property (strong) IBOutlet NSPopUpButton *colorCorrectionPopupButton;
-@property (nonatomic, strong) IBOutlet NSPopUpButton *colorPalettePopupButton;
+@property (strong) IBOutlet NSPopUpButton *colorPalettePopupButton;
+@property (strong) IBOutlet NSPopUpButton *displayBorderPopupButton;
@property (strong) IBOutlet NSPopUpButton *rewindPopupButton;
@property (strong) IBOutlet NSButton *configureJoypadButton;
@property (strong) IBOutlet NSButton *skipButton;
diff --git a/Cocoa/GBPreferencesWindow.m b/Cocoa/GBPreferencesWindow.m
index 5c5d375..0303771 100644
--- a/Cocoa/GBPreferencesWindow.m
+++ b/Cocoa/GBPreferencesWindow.m
@@ -15,6 +15,7 @@
NSPopUpButton *_highpassFilterPopupButton;
NSPopUpButton *_colorCorrectionPopupButton;
NSPopUpButton *_colorPalettePopupButton;
+ NSPopUpButton *_displayBorderPopupButton;
NSPopUpButton *_rewindPopupButton;
NSButton *_aspectRatioCheckbox;
NSEventModifierFlags previousModifiers;
@@ -98,6 +99,18 @@
return _colorPalettePopupButton;
}
+- (void)setDisplayBorderPopupButton:(NSPopUpButton *)displayBorderPopupButton
+{
+ _displayBorderPopupButton = displayBorderPopupButton;
+ NSInteger mode = [[NSUserDefaults standardUserDefaults] integerForKey:@"GBBorderMode"];
+ [_displayBorderPopupButton selectItemWithTag:mode];
+}
+
+- (NSPopUpButton *)displayBorderPopupButton
+{
+ return _displayBorderPopupButton;
+}
+
- (void)setRewindPopupButton:(NSPopUpButton *)rewindPopupButton
{
_rewindPopupButton = rewindPopupButton;
@@ -221,6 +234,14 @@
}
+- (IBAction)displayBorderChanged:(id)sender
+{
+ [[NSUserDefaults standardUserDefaults] setObject:@([sender selectedItem].tag)
+ forKey:@"GBBorderMode"];
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"GBBorderModeChanged" object:nil];
+
+}
+
- (IBAction)rewindLengthChanged:(id)sender
{
[[NSUserDefaults standardUserDefaults] setObject:@([sender selectedTag])
diff --git a/Cocoa/GBView.m b/Cocoa/GBView.m
index 5a851f3..e3026fd 100644
--- a/Cocoa/GBView.m
+++ b/Cocoa/GBView.m
@@ -65,9 +65,9 @@
size_t buffer_size = sizeof(image_buffers[0][0]) * GB_get_screen_width(_gb) * GB_get_screen_height(_gb);
- image_buffers[0] = malloc(buffer_size);
- image_buffers[1] = malloc(buffer_size);
- image_buffers[2] = malloc(buffer_size);
+ image_buffers[0] = calloc(1, buffer_size);
+ image_buffers[1] = calloc(1, buffer_size);
+ image_buffers[2] = calloc(1, buffer_size);
dispatch_async(dispatch_get_main_queue(), ^{
[self setFrame:self.superview.frame];
diff --git a/Cocoa/Preferences.xib b/Cocoa/Preferences.xib
index 1062dae..e7d96aa 100644
--- a/Cocoa/Preferences.xib
+++ b/Cocoa/Preferences.xib
@@ -67,6 +67,7 @@
+
@@ -79,34 +80,34 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -148,9 +149,9 @@
-
-
-
+
+
+
@@ -159,16 +160,16 @@
-
+
-
+
-
+
@@ -188,10 +189,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -233,7 +263,7 @@
-
+
@@ -251,12 +281,12 @@
-
+