SameBoy | Accurate GB/GBC emulator |
| download: https://git.y1.nz/archives/sameboy.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit daf713132bc9596b2ae2db30aa435262ca351393 parent fef175dcc664d1d3794c0725c35c9666d31a93a3 Author: Lior Halphon <LIJI32@gmail.com> Date: Fri, 9 Jun 2023 16:28:58 +0300 ivar naming in Document.m Diffstat:
| M | Cocoa/Document.m | 924 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
1 file changed, 462 insertions(+), 462 deletions(-)
diff --git a/Cocoa/Document.m b/Cocoa/Document.m @@ -63,58 +63,58 @@ enum model { @implementation Document { - GB_gameboy_t gb; - volatile bool running; - volatile bool stopping; - NSConditionLock *has_debugger_input; - NSMutableArray *debugger_input_queue; - - NSMutableAttributedString *pending_console_output; - NSRecursiveLock *console_output_lock; - NSTimer *console_output_timer; - NSTimer *hex_timer; - - bool fullScreen; - bool in_sync_input; + GB_gameboy_t _gb; + volatile bool _running; + volatile bool _stopping; + NSConditionLock *_hasDebuggerInput; + NSMutableArray *_debuggerInputQueue; + + NSMutableAttributedString *_pendingConsoleOutput; + NSRecursiveLock *_consoleOutputLock; + NSTimer *_consoleOutputTimer; + NSTimer *_hexTimer; + + bool _fullScreen; + bool _inSyncInput; NSString *_debuggerCommandWhilePaused; - HFController *hex_controller; + HFController *_hexController; - NSString *lastConsoleInput; - HFLineCountingRepresenter *lineRep; + NSString *_lastConsoleInput; + HFLineCountingRepresenter *_lineRep; - CVImageBufferRef cameraImage; - AVCaptureSession *cameraSession; - AVCaptureConnection *cameraConnection; - AVCaptureStillImageOutput *cameraOutput; + CVImageBufferRef _cameraImage; + AVCaptureSession *_cameraSession; + AVCaptureConnection *_cameraConnection; + AVCaptureStillImageOutput *_cameraOutput; GB_oam_info_t _oamInfo[40]; - NSMutableData *currentPrinterImageData; + NSMutableData *_currentPrinterImageData; - bool rom_warning_issued; + bool _romWarningIssued; - NSMutableString *capturedOutput; - bool logToSideView; - bool shouldClearSideView; - enum model current_model; + NSMutableString *_capturedOutput; + bool _logToSideView; + bool _shouldClearSideView; + enum model _currentModel; - bool rewind; - bool modelsChanging; + bool _rewind; + bool _modelsChanging; - NSCondition *audioLock; - GB_sample_t *audioBuffer; - size_t audioBufferSize; - size_t audioBufferPosition; - size_t audioBufferNeeded; + NSCondition *_audioLock; + GB_sample_t *_audioBuffer; + size_t _audioBufferSize; + size_t _audioBufferPosition; + size_t _audioBufferNeeded; double _volume; - bool borderModeChanged; + bool _borderModeChanged; /* Link cable*/ - Document *master; - Document *slave; - signed linkOffset; - bool linkCableBit; + Document *_master; + Document *_slave; + signed _linkOffset; + bool _linkCableBit; NSSavePanel *_audioSavePanel; bool _isRecordingAudio; @@ -208,16 +208,16 @@ static void rumbleCallback(GB_gameboy_t *gb, double amp) } -static void linkCableBitStart(GB_gameboy_t *gb, bool bit_to_send) +static void _linkCableBitStart(GB_gameboy_t *gb, bool bit_to_send) { Document *self = (__bridge Document *)GB_get_user_data(gb); - [self linkCableBitStart:bit_to_send]; + [self _linkCableBitStart:bit_to_send]; } -static bool linkCableBitEnd(GB_gameboy_t *gb) +static bool _linkCableBitEnd(GB_gameboy_t *gb) { Document *self = (__bridge Document *)GB_get_user_data(gb); - return [self linkCableBitEnd]; + return [self _linkCableBitEnd]; } static void infraredStateChanged(GB_gameboy_t *gb, bool on) @@ -230,10 +230,10 @@ static void debuggerReloadCallback(GB_gameboy_t *gb) { Document *self = (__bridge Document *)GB_get_user_data(gb); dispatch_sync(dispatch_get_main_queue(), ^{ - bool wasRunning = self->running; - self->running = false; // Hack for output capture + bool wasRunning = self->_running; + self->_running = false; // Hack for output capture [self loadROM]; - self->running = wasRunning; + self->_running = wasRunning; GB_reset(gb); }); } @@ -242,10 +242,10 @@ static void debuggerReloadCallback(GB_gameboy_t *gb) { self = [super init]; if (self) { - has_debugger_input = [[NSConditionLock alloc] initWithCondition:0]; - debugger_input_queue = [[NSMutableArray alloc] init]; - console_output_lock = [[NSRecursiveLock alloc] init]; - audioLock = [[NSCondition alloc] init]; + _hasDebuggerInput = [[NSConditionLock alloc] initWithCondition:0]; + _debuggerInputQueue = [[NSMutableArray alloc] init]; + _consoleOutputLock = [[NSRecursiveLock alloc] init]; + _audioLock = [[NSCondition alloc] init]; _volume = [[NSUserDefaults standardUserDefaults] doubleForKey:@"GBVolume"]; } return self; @@ -268,7 +268,7 @@ static void debuggerReloadCallback(GB_gameboy_t *gb) - (GB_model_t)internalModel { - switch (current_model) { + switch (_currentModel) { case MODEL_DMG: return (GB_model_t)[[NSUserDefaults standardUserDefaults] integerForKey:@"GBDMGModel"]; @@ -295,54 +295,54 @@ static void debuggerReloadCallback(GB_gameboy_t *gb) - (void) updatePalette { - GB_set_palette(&gb, [GBPaletteEditorController userPalette]); + GB_set_palette(&_gb, [GBPaletteEditorController userPalette]); } - (void) updateBorderMode { - borderModeChanged = true; + _borderModeChanged = true; } - (void) updateRumbleMode { - GB_set_rumble_mode(&gb, [[NSUserDefaults standardUserDefaults] integerForKey:@"GBRumbleMode"]); + GB_set_rumble_mode(&_gb, [[NSUserDefaults standardUserDefaults] integerForKey:@"GBRumbleMode"]); } - (void) initCommon { - GB_init(&gb, [self internalModel]); - GB_set_user_data(&gb, (__bridge void *)(self)); - GB_set_boot_rom_load_callback(&gb, (GB_boot_rom_load_callback_t)boot_rom_load); - GB_set_vblank_callback(&gb, (GB_vblank_callback_t) vblank); - GB_set_log_callback(&gb, (GB_log_callback_t) consoleLog); - 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_light_temperature(&gb, [[NSUserDefaults standardUserDefaults] doubleForKey:@"GBLightTemperature"]); - GB_set_interference_volume(&gb, [[NSUserDefaults standardUserDefaults] doubleForKey:@"GBInterferenceVolume"]); - GB_set_border_mode(&gb, (GB_border_mode_t) [[NSUserDefaults standardUserDefaults] integerForKey:@"GBBorderMode"]); + GB_init(&_gb, [self internalModel]); + GB_set_user_data(&_gb, (__bridge void *)(self)); + GB_set_boot_rom_load_callback(&_gb, (GB_boot_rom_load_callback_t)boot_rom_load); + GB_set_vblank_callback(&_gb, (GB_vblank_callback_t) vblank); + GB_set_log_callback(&_gb, (GB_log_callback_t) consoleLog); + 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_light_temperature(&_gb, [[NSUserDefaults standardUserDefaults] doubleForKey:@"GBLightTemperature"]); + GB_set_interference_volume(&_gb, [[NSUserDefaults standardUserDefaults] doubleForKey:@"GBInterferenceVolume"]); + 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); - GB_set_camera_update_request_callback(&gb, cameraRequestUpdate); - GB_set_highpass_filter_mode(&gb, (GB_highpass_mode_t) [[NSUserDefaults standardUserDefaults] integerForKey:@"GBHighpassFilter"]); - GB_set_rewind_length(&gb, [[NSUserDefaults standardUserDefaults] integerForKey:@"GBRewindLength"]); - GB_set_rtc_mode(&gb, [[NSUserDefaults standardUserDefaults] integerForKey:@"GBRTCMode"]); - GB_apu_set_sample_callback(&gb, audioCallback); - GB_set_rumble_callback(&gb, rumbleCallback); - GB_set_infrared_callback(&gb, infraredStateChanged); - GB_set_debugger_reload_callback(&gb, debuggerReloadCallback); + GB_set_rgb_encode_callback(&_gb, rgbEncode); + GB_set_camera_get_pixel_callback(&_gb, cameraGetPixel); + GB_set_camera_update_request_callback(&_gb, cameraRequestUpdate); + GB_set_highpass_filter_mode(&_gb, (GB_highpass_mode_t) [[NSUserDefaults standardUserDefaults] integerForKey:@"GBHighpassFilter"]); + GB_set_rewind_length(&_gb, [[NSUserDefaults standardUserDefaults] integerForKey:@"GBRewindLength"]); + GB_set_rtc_mode(&_gb, [[NSUserDefaults standardUserDefaults] integerForKey:@"GBRTCMode"]); + GB_apu_set_sample_callback(&_gb, audioCallback); + GB_set_rumble_callback(&_gb, rumbleCallback); + GB_set_infrared_callback(&_gb, infraredStateChanged); + GB_set_debugger_reload_callback(&_gb, debuggerReloadCallback); [self updateRumbleMode]; } - (void) updateMinSize { - self.mainWindow.contentMinSize = NSMakeSize(GB_get_screen_width(&gb), GB_get_screen_height(&gb)); - if (self.mainWindow.contentView.bounds.size.width < GB_get_screen_width(&gb) || - self.mainWindow.contentView.bounds.size.width < GB_get_screen_height(&gb)) { + self.mainWindow.contentMinSize = NSMakeSize(GB_get_screen_width(&_gb), GB_get_screen_height(&_gb)); + if (self.mainWindow.contentView.bounds.size.width < GB_get_screen_width(&_gb) || + self.mainWindow.contentView.bounds.size.width < GB_get_screen_height(&_gb)) { [self.mainWindow zoom:nil]; } - self.osdView.usesSGBScale = GB_get_screen_width(&gb) == 256; + self.osdView.usesSGBScale = GB_get_screen_width(&_gb) == 256; } - (void) vblankWithType:(GB_vblank_type_t)type @@ -354,18 +354,18 @@ static void debuggerReloadCallback(GB_gameboy_t *gb) } if (type != GB_VBLANK_TYPE_REPEAT) { [self.view flip]; - if (borderModeChanged) { + 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) { + 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]; [self updateMinSize]; } }); - borderModeChanged = false; + _borderModeChanged = false; } - GB_set_pixels_output(&gb, self.view.pixels); + GB_set_pixels_output(&_gb, self.view.pixels); } if (self.vramWindow.isVisible) { @@ -375,7 +375,7 @@ static void debuggerReloadCallback(GB_gameboy_t *gb) }); } if (self.view.isRewinding) { - rewind = true; + _rewind = true; [self.osdView displayText:@"Rewinding…"]; } } @@ -385,34 +385,34 @@ static void debuggerReloadCallback(GB_gameboy_t *gb) if (_gbsVisualizer) { [_gbsVisualizer addSample:sample]; } - [audioLock lock]; + [_audioLock lock]; if (_audioClient.isPlaying) { - if (audioBufferPosition == audioBufferSize) { - if (audioBufferSize >= 0x4000) { - audioBufferPosition = 0; - [audioLock unlock]; + if (_audioBufferPosition == _audioBufferSize) { + if (_audioBufferSize >= 0x4000) { + _audioBufferPosition = 0; + [_audioLock unlock]; return; } - if (audioBufferSize == 0) { - audioBufferSize = 512; + if (_audioBufferSize == 0) { + _audioBufferSize = 512; } else { - audioBufferSize += audioBufferSize >> 2; + _audioBufferSize += _audioBufferSize >> 2; } - audioBuffer = realloc(audioBuffer, sizeof(*sample) * audioBufferSize); + _audioBuffer = realloc(_audioBuffer, sizeof(*sample) * _audioBufferSize); } if (_volume != 1) { sample->left *= _volume; sample->right *= _volume; } - audioBuffer[audioBufferPosition++] = *sample; + _audioBuffer[_audioBufferPosition++] = *sample; } - if (audioBufferPosition == audioBufferNeeded) { - [audioLock signal]; - audioBufferNeeded = 0; + if (_audioBufferPosition == _audioBufferNeeded) { + [_audioLock signal]; + _audioBufferNeeded = 0; } - [audioLock unlock]; + [_audioLock unlock]; } - (void)rumbleChanged:(double)amp @@ -422,44 +422,44 @@ static void debuggerReloadCallback(GB_gameboy_t *gb) - (void) preRun { - GB_set_pixels_output(&gb, self.view.pixels); - GB_set_sample_rate(&gb, 96000); + GB_set_pixels_output(&_gb, self.view.pixels); + GB_set_sample_rate(&_gb, 96000); _audioClient = [[GBAudioClient alloc] initWithRendererBlock:^(UInt32 sampleRate, UInt32 nFrames, GB_sample_t *buffer) { - [audioLock lock]; + [_audioLock lock]; - if (audioBufferPosition < nFrames) { - audioBufferNeeded = nFrames; - [audioLock waitUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.125]]; + if (_audioBufferPosition < nFrames) { + _audioBufferNeeded = nFrames; + [_audioLock waitUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.125]]; } - if (stopping || GB_debugger_is_stopped(&gb)) { + if (_stopping || GB_debugger_is_stopped(&_gb)) { memset(buffer, 0, nFrames * sizeof(*buffer)); - [audioLock unlock]; + [_audioLock unlock]; return; } - if (audioBufferPosition < nFrames) { + if (_audioBufferPosition < nFrames) { // Not enough audio - memset(buffer, 0, (nFrames - audioBufferPosition) * sizeof(*buffer)); - memcpy(buffer, audioBuffer, audioBufferPosition * sizeof(*buffer)); - audioBufferPosition = 0; + memset(buffer, 0, (nFrames - _audioBufferPosition) * sizeof(*buffer)); + memcpy(buffer, _audioBuffer, _audioBufferPosition * sizeof(*buffer)); + _audioBufferPosition = 0; } - else if (audioBufferPosition < nFrames + 4800) { - memcpy(buffer, audioBuffer, nFrames * sizeof(*buffer)); - memmove(audioBuffer, audioBuffer + nFrames, (audioBufferPosition - nFrames) * sizeof(*buffer)); - audioBufferPosition = audioBufferPosition - nFrames; + else if (_audioBufferPosition < nFrames + 4800) { + memcpy(buffer, _audioBuffer, nFrames * sizeof(*buffer)); + memmove(_audioBuffer, _audioBuffer + nFrames, (_audioBufferPosition - nFrames) * sizeof(*buffer)); + _audioBufferPosition = _audioBufferPosition - nFrames; } else { - memcpy(buffer, audioBuffer + (audioBufferPosition - nFrames), nFrames * sizeof(*buffer)); - audioBufferPosition = 0; + memcpy(buffer, _audioBuffer + (_audioBufferPosition - nFrames), nFrames * sizeof(*buffer)); + _audioBufferPosition = 0; } - [audioLock unlock]; + [_audioLock unlock]; } andSampleRate:96000]; if (![[NSUserDefaults standardUserDefaults] boolForKey:@"Mute"]) { [_audioClient start]; } - hex_timer = [NSTimer timerWithTimeInterval:0.25 target:self selector:@selector(reloadMemoryView) userInfo:nil repeats:true]; - [[NSRunLoop mainRunLoop] addTimer:hex_timer forMode:NSDefaultRunLoopMode]; + _hexTimer = [NSTimer timerWithTimeInterval:0.25 target:self selector:@selector(reloadMemoryView) userInfo:nil repeats:true]; + [[NSRunLoop mainRunLoop] addTimer:_hexTimer forMode:NSDefaultRunLoopMode]; /* Clear pending alarms, don't play alarms while playing */ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"GBNotificationsUsed"]) { @@ -491,18 +491,18 @@ static unsigned *multiplication_table_for_frequency(unsigned frequency) - (void)run { - assert(!master); + assert(!_master); [self preRun]; - if (slave) { - [slave preRun]; - unsigned *masterTable = multiplication_table_for_frequency(GB_get_clock_rate(&gb)); - unsigned *slaveTable = multiplication_table_for_frequency(GB_get_clock_rate(&slave->gb)); - while (running) { - if (linkOffset <= 0) { - linkOffset += slaveTable[GB_run(&gb)]; + if (_slave) { + [_slave preRun]; + unsigned *masterTable = multiplication_table_for_frequency(GB_get_clock_rate(&_gb)); + unsigned *slaveTable = multiplication_table_for_frequency(GB_get_clock_rate(&_slave->_gb)); + while (_running) { + if (_linkOffset <= 0) { + _linkOffset += slaveTable[GB_run(&_gb)]; } else { - linkOffset -= masterTable[GB_run(&slave->gb)]; + _linkOffset -= masterTable[GB_run(&_slave->_gb)]; } if (unlikely(_pendingAtomicBlock)) { _pendingAtomicBlock(); @@ -511,19 +511,19 @@ static unsigned *multiplication_table_for_frequency(unsigned frequency) } free(masterTable); free(slaveTable); - [slave postRun]; + [_slave postRun]; } else { - while (running) { - if (rewind) { - rewind = false; - GB_rewind_pop(&gb); - if (!GB_rewind_pop(&gb)) { - rewind = self.view.isRewinding; + while (_running) { + if (_rewind) { + _rewind = false; + GB_rewind_pop(&_gb); + if (!GB_rewind_pop(&_gb)) { + _rewind = self.view.isRewinding; } } else { - GB_run(&gb); + GB_run(&_gb); } if (unlikely(_pendingAtomicBlock)) { _pendingAtomicBlock(); @@ -532,23 +532,23 @@ static unsigned *multiplication_table_for_frequency(unsigned frequency) } } [self postRun]; - stopping = false; + _stopping = false; } - (void)postRun { - [hex_timer invalidate]; - [audioLock lock]; - memset(audioBuffer, 0, (audioBufferSize - audioBufferPosition) * sizeof(*audioBuffer)); - audioBufferPosition = audioBufferNeeded; - [audioLock signal]; - [audioLock unlock]; + [_hexTimer invalidate]; + [_audioLock lock]; + memset(_audioBuffer, 0, (_audioBufferSize - _audioBufferPosition) * sizeof(*_audioBuffer)); + _audioBufferPosition = _audioBufferNeeded; + [_audioLock signal]; + [_audioLock unlock]; [_audioClient stop]; _audioClient = nil; self.view.mouseHidingEnabled = false; - GB_save_battery(&gb, self.savPath.UTF8String); - GB_save_cheats(&gb, self.chtPath.UTF8String); - unsigned time_to_alarm = GB_time_to_alarm(&gb); + GB_save_battery(&_gb, self.savPath.UTF8String); + GB_save_cheats(&_gb, self.chtPath.UTF8String); + unsigned time_to_alarm = GB_time_to_alarm(&_gb); if (time_to_alarm) { [NSUserNotificationCenter defaultUserNotificationCenter].delegate = (id)[NSApp delegate]; @@ -573,16 +573,16 @@ static unsigned *multiplication_table_for_frequency(unsigned frequency) { dispatch_async(dispatch_get_main_queue(), ^{ [self updateDebuggerButtons]; - [slave updateDebuggerButtons]; + [_slave updateDebuggerButtons]; }); self.gbsPlayPauseButton.state = true; self.view.mouseHidingEnabled = (self.mainWindow.styleMask & NSWindowStyleMaskFullScreen) != 0; - if (master) { - [master start]; + if (_master) { + [_master start]; return; } - if (running) return; - running = true; + if (_running) return; + _running = true; [[[NSThread alloc] initWithTarget:self selector:@selector(run) object:nil] start]; } @@ -590,35 +590,35 @@ static unsigned *multiplication_table_for_frequency(unsigned frequency) { dispatch_async(dispatch_get_main_queue(), ^{ [self updateDebuggerButtons]; - [slave updateDebuggerButtons]; + [_slave updateDebuggerButtons]; }); self.gbsPlayPauseButton.state = false; - if (master) { - if (!master->running) return; - GB_debugger_set_disabled(&gb, true); - if (GB_debugger_is_stopped(&gb)) { + if (_master) { + if (!_master->_running) return; + GB_debugger_set_disabled(&_gb, true); + if (GB_debugger_is_stopped(&_gb)) { [self interruptDebugInputRead]; } - [master stop]; - GB_debugger_set_disabled(&gb, false); + [_master stop]; + GB_debugger_set_disabled(&_gb, false); return; } - if (!running) return; - GB_debugger_set_disabled(&gb, true); - if (GB_debugger_is_stopped(&gb)) { + if (!_running) return; + GB_debugger_set_disabled(&_gb, true); + if (GB_debugger_is_stopped(&_gb)) { [self interruptDebugInputRead]; } - [audioLock lock]; - stopping = true; - [audioLock signal]; - [audioLock unlock]; - running = false; - while (stopping) { - [audioLock lock]; - [audioLock signal]; - [audioLock unlock]; + [_audioLock lock]; + _stopping = true; + [_audioLock signal]; + [_audioLock unlock]; + _running = false; + while (_stopping) { + [_audioLock lock]; + [_audioLock signal]; + [_audioLock unlock]; } - GB_debugger_set_disabled(&gb, false); + GB_debugger_set_disabled(&_gb, false); } - (void) loadBootROM: (GB_boot_rom_t)type @@ -633,26 +633,26 @@ static unsigned *multiplication_table_for_frequency(unsigned frequency) [GB_BOOT_ROM_CGB] = @"cgb_boot", [GB_BOOT_ROM_AGB] = @"agb_boot", }; - GB_load_boot_rom(&gb, [[self bootROMPathForName:names[type]] UTF8String]); + GB_load_boot_rom(&_gb, [[self bootROMPathForName:names[type]] UTF8String]); } - (IBAction)reset:(id)sender { [self stop]; - size_t old_width = GB_get_screen_width(&gb); + size_t old_width = GB_get_screen_width(&_gb); if ([sender tag] != MODEL_NONE) { - current_model = (enum model)[sender tag]; + _currentModel = (enum model)[sender tag]; } if ([sender tag] == MODEL_QUICK_RESET) { - GB_quick_reset(&gb); + GB_quick_reset(&_gb); } else { - GB_switch_model_and_reset(&gb, [self internalModel]); + GB_switch_model_and_reset(&_gb, [self internalModel]); } - if (old_width != GB_get_screen_width(&gb)) { + if (old_width != GB_get_screen_width(&_gb)) { [self.view screenSizeChanged]; } @@ -660,10 +660,10 @@ static unsigned *multiplication_table_for_frequency(unsigned frequency) if ([sender tag] > MODEL_NONE) { /* User explictly selected a model, save the preference */ - [[NSUserDefaults standardUserDefaults] setBool:current_model == MODEL_DMG forKey:@"EmulateDMG"]; - [[NSUserDefaults standardUserDefaults] setBool:current_model == MODEL_SGB forKey:@"EmulateSGB"]; - [[NSUserDefaults standardUserDefaults] setBool:current_model == MODEL_AGB forKey:@"EmulateAGB"]; - [[NSUserDefaults standardUserDefaults] setBool:current_model == MODEL_MGB forKey:@"EmulateMGB"]; + [[NSUserDefaults standardUserDefaults] setBool:_currentModel == MODEL_DMG forKey:@"EmulateDMG"]; + [[NSUserDefaults standardUserDefaults] setBool:_currentModel == MODEL_SGB forKey:@"EmulateSGB"]; + [[NSUserDefaults standardUserDefaults] setBool:_currentModel == MODEL_AGB forKey:@"EmulateAGB"]; + [[NSUserDefaults standardUserDefaults] setBool:_currentModel == MODEL_MGB forKey:@"EmulateMGB"]; } /* Reload the ROM, SAV and SYM files */ @@ -671,24 +671,24 @@ static unsigned *multiplication_table_for_frequency(unsigned frequency) [self start]; - if (hex_controller) { + if (_hexController) { /* Verify bank sanity, especially when switching models. */ - [(GBMemoryByteArray *)(hex_controller.byteArray) setSelectedBank:0]; + [(GBMemoryByteArray *)(_hexController.byteArray) setSelectedBank:0]; [self hexUpdateBank:self.memoryBankInput ignoreErrors:true]; } char title[17]; - GB_get_rom_title(&gb, title); - [self.osdView displayText:[NSString stringWithFormat:@"SameBoy v" GB_VERSION "\n%s\n%08X", title, GB_get_rom_crc32(&gb)]]; + GB_get_rom_title(&_gb, title); + [self.osdView displayText:[NSString stringWithFormat:@"SameBoy v" GB_VERSION "\n%s\n%08X", title, GB_get_rom_crc32(&_gb)]]; } - (IBAction)togglePause:(id)sender { - if (master) { - [master togglePause:sender]; + if (_master) { + [_master togglePause:sender]; return; } - if (running) { + if (_running) { [self stop]; } else { @@ -698,14 +698,14 @@ static unsigned *multiplication_table_for_frequency(unsigned frequency) - (void)dealloc { - [cameraSession stopRunning]; + [_cameraSession stopRunning]; self.view.gb = NULL; - GB_free(&gb); - if (cameraImage) { - CVBufferRelease(cameraImage); + GB_free(&_gb); + if (_cameraImage) { + CVBufferRelease(_cameraImage); } - if (audioBuffer) { - free(audioBuffer); + if (_audioBuffer) { + free(_audioBuffer); } } @@ -728,7 +728,7 @@ static unsigned *multiplication_table_for_frequency(unsigned frequency) self.debuggerSideViewInput.textColor = [NSColor whiteColor]; self.debuggerSideViewInput.defaultParagraphStyle = paragraph_style; [self.debuggerSideViewInput setString:@"registers\nbacktrace\n"]; - ((GBTerminalTextFieldCell *)self.consoleInput.cell).gb = &gb; + ((GBTerminalTextFieldCell *)self.consoleInput.cell).gb = &_gb; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateSideView) name:NSTextDidChangeNotification @@ -765,7 +765,7 @@ static unsigned *multiplication_table_for_frequency(unsigned frequency) [NSImage imageWithSystemSymbolName:@"printer" accessibilityDescription:@"Print"]; } - + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateHighpassFilter) name:@"GBHighpassFilterChanged" @@ -844,20 +844,20 @@ static unsigned *multiplication_table_for_frequency(unsigned frequency) object:nil]; if ([[NSUserDefaults standardUserDefaults] boolForKey:@"EmulateDMG"]) { - current_model = MODEL_DMG; + _currentModel = MODEL_DMG; } else if ([[NSUserDefaults standardUserDefaults] boolForKey:@"EmulateSGB"]) { - current_model = MODEL_SGB; + _currentModel = MODEL_SGB; } else if ([[NSUserDefaults standardUserDefaults] boolForKey:@"EmulateMGB"]) { - current_model = MODEL_MGB; + _currentModel = MODEL_MGB; } else { - current_model = [[NSUserDefaults standardUserDefaults] boolForKey:@"EmulateAGB"]? MODEL_AGB : MODEL_CGB; + _currentModel = [[NSUserDefaults standardUserDefaults] boolForKey:@"EmulateAGB"]? MODEL_AGB : MODEL_CGB; } [self initCommon]; - self.view.gb = &gb; + self.view.gb = &_gb; self.view.osdView = _osdView; [self.view screenSizeChanged]; if ([self loadROM]) { @@ -873,35 +873,35 @@ static unsigned *multiplication_table_for_frequency(unsigned frequency) - (void) initMemoryView { - hex_controller = [[HFController alloc] init]; - [hex_controller setBytesPerColumn:1]; - [hex_controller setEditMode:HFOverwriteMode]; + _hexController = [[HFController alloc] init]; + [_hexController setBytesPerColumn:1]; + [_hexController setEditMode:HFOverwriteMode]; - [hex_controller setByteArray:[[GBMemoryByteArray alloc] initWithDocument:self]]; + [_hexController setByteArray:[[GBMemoryByteArray alloc] initWithDocument:self]]; /* Here we're going to make three representers - one for the hex, one for the ASCII, and one for the scrollbar. To lay these all out properly, we'll use a fourth HFLayoutRepresenter. */ HFLayoutRepresenter *layoutRep = [[HFLayoutRepresenter alloc] init]; HFHexTextRepresenter *hexRep = [[HFHexTextRepresenter alloc] init]; HFStringEncodingTextRepresenter *asciiRep = [[HFStringEncodingTextRepresenter alloc] init]; HFVerticalScrollerRepresenter *scrollRep = [[HFVerticalScrollerRepresenter alloc] init]; - lineRep = [[HFLineCountingRepresenter alloc] init]; + _lineRep = [[HFLineCountingRepresenter alloc] init]; HFStatusBarRepresenter *statusRep = [[HFStatusBarRepresenter alloc] init]; - lineRep.lineNumberFormat = HFLineNumberFormatHexadecimal; + _lineRep.lineNumberFormat = HFLineNumberFormatHexadecimal; /* Add all our reps to the controller. */ - [hex_controller addRepresenter:layoutRep]; - [hex_controller addRepresenter:hexRep]; - [hex_controller addRepresenter:asciiRep]; - [hex_controller addRepresenter:scrollRep]; - [hex_controller addRepresenter:lineRep]; - [hex_controller addRepresenter:statusRep]; + [_hexController addRepresenter:layoutRep]; + [_hexController addRepresenter:hexRep]; + [_hexController addRepresenter:asciiRep]; + [_hexController addRepresenter:scrollRep]; + [_hexController addRepresenter:_lineRep]; + [_hexController addRepresenter:statusRep]; /* Tell the layout rep which reps it should lay out. */ [layoutRep addRepresenter:hexRep]; [layoutRep addRepresenter:scrollRep]; [layoutRep addRepresenter:asciiRep]; - [layoutRep addRepresenter:lineRep]; + [layoutRep addRepresenter:_lineRep]; [layoutRep addRepresenter:statusRep]; @@ -937,11 +937,11 @@ static unsigned *multiplication_table_for_frequency(unsigned frequency) - (IBAction)changeGBSTrack:(id)sender { - if (!running) { + if (!_running) { [self start]; } [self performAtomicBlock:^{ - GB_gbs_switch_track(&gb, self.gbsTracks.indexOfSelectedItem); + GB_gbs_switch_track(&_gb, self.gbsTracks.indexOfSelectedItem); }]; } - (IBAction)gbsNextPrevPushed:(id)sender @@ -969,7 +969,7 @@ static unsigned *multiplication_table_for_frequency(unsigned frequency) - (void)prepareGBSInterface: (GB_gbs_info_t *)info { - GB_set_rendering_disabled(&gb, true); + GB_set_rendering_disabled(&_gb, true); _view = nil; for (NSView *view in [_mainWindow.contentView.subviews copy]) { [view removeFromSuperview]; @@ -1107,33 +1107,33 @@ static bool is_path_writeable(const char *path) } NSString *rom_warnings = [self captureOutputForBlock:^{ - GB_debugger_clear_symbols(&gb); + GB_debugger_clear_symbols(&_gb); if ([[[fileName pathExtension] lowercaseString] isEqualToString:@"isx"]) { - ret = GB_load_isx(&gb, fileName.UTF8String); + ret = GB_load_isx(&_gb, fileName.UTF8String); if (!self.isCartContainer) { - GB_load_battery(&gb, [[self.fileURL URLByDeletingPathExtension] URLByAppendingPathExtension:@"ram"].path.UTF8String); + GB_load_battery(&_gb, [[self.fileURL URLByDeletingPathExtension] URLByAppendingPathExtension:@"ram"].path.UTF8String); } } else if ([[[fileName pathExtension] lowercaseString] isEqualToString:@"gbs"]) { __block GB_gbs_info_t info; - ret = GB_load_gbs(&gb, fileName.UTF8String, &info); + ret = GB_load_gbs(&_gb, fileName.UTF8String, &info); [self prepareGBSInterface:&info]; } else { - ret = GB_load_rom(&gb, [fileName UTF8String]); + ret = GB_load_rom(&_gb, [fileName UTF8String]); } - if (GB_save_battery_size(&gb)) { + if (GB_save_battery_size(&_gb)) { if (!is_path_writeable(self.savPath.UTF8String)) { - GB_log(&gb, "The save path for this ROM is not writeable, progress will not be saved.\n"); + GB_log(&_gb, "The save path for this ROM is not writeable, progress will not be saved.\n"); } } - GB_load_battery(&gb, self.savPath.UTF8String); - GB_load_cheats(&gb, self.chtPath.UTF8String); + GB_load_battery(&_gb, self.savPath.UTF8String); + GB_load_cheats(&_gb, self.chtPath.UTF8String); dispatch_async(dispatch_get_main_queue(), ^{ [self.cheatWindowController cheatsUpdated]; }); - GB_debugger_load_symbol_file(&gb, [[[NSBundle mainBundle] pathForResource:@"registers" ofType:@"sym"] UTF8String]); - GB_debugger_load_symbol_file(&gb, [[fileName stringByDeletingPathExtension] stringByAppendingPathExtension:@"sym"].UTF8String); + GB_debugger_load_symbol_file(&_gb, [[[NSBundle mainBundle] pathForResource:@"registers" ofType:@"sym"] UTF8String]); + GB_debugger_load_symbol_file(&_gb, [[fileName stringByDeletingPathExtension] stringByAppendingPathExtension:@"sym"].UTF8String); }]; if (ret) { NSAlert *alert = [[NSAlert alloc] init]; @@ -1141,8 +1141,8 @@ static bool is_path_writeable(const char *path) [alert setAlertStyle:NSAlertStyleCritical]; [alert runModal]; } - else if (rom_warnings && !rom_warning_issued) { - rom_warning_issued = true; + else if (rom_warnings && !_romWarningIssued) { + _romWarningIssued = true; [GBWarningPopover popoverWithContents:rom_warnings onWindow:self.mainWindow]; } _fileModificationTime = [[NSFileManager defaultManager] attributesOfItemAtPath:fileName error:nil][NSFileModificationDate]; @@ -1151,7 +1151,7 @@ static bool is_path_writeable(const char *path) - (void)showWindows { - if (GB_is_inited(&gb)) { + if (GB_is_inited(&_gb)) { if (![_fileModificationTime isEqualToDate:[[NSFileManager defaultManager] attributesOfItemAtPath:self.fileName error:nil][NSFileModificationDate]]) { [self reset:nil]; } @@ -1167,9 +1167,9 @@ static bool is_path_writeable(const char *path) [[NSUserDefaults standardUserDefaults] setInteger:self.mainWindow.frame.size.height forKey:@"LastWindowHeight"]; } [self stop]; - [console_output_lock lock]; - [console_output_timer invalidate]; - [console_output_lock unlock]; + [_consoleOutputLock lock]; + [_consoleOutputTimer invalidate]; + [_consoleOutputLock unlock]; [self.consoleWindow close]; [self.memoryWindow close]; [self.vramWindow close]; @@ -1181,7 +1181,7 @@ static bool is_path_writeable(const char *path) - (IBAction) interrupt:(id)sender { [self log:"^C\n"]; - GB_debugger_break(&gb); + GB_debugger_break(&_gb); [self start]; [self.consoleWindow makeKeyAndOrderFront:nil]; [self.consoleInput becomeFirstResponder]; @@ -1204,9 +1204,9 @@ static bool is_path_writeable(const char *path) - (bool) isPaused { if (self.partner) { - return !self.partner->running || GB_debugger_is_stopped(&gb) || GB_debugger_is_stopped(&self.partner->gb); + return !self.partner->_running || GB_debugger_is_stopped(&_gb) || GB_debugger_is_stopped(&self.partner->_gb); } - return (!running) || GB_debugger_is_stopped(&gb); + return (!_running) || GB_debugger_is_stopped(&_gb); } - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)anItem @@ -1216,10 +1216,10 @@ static bool is_path_writeable(const char *path) } else if ([anItem action] == @selector(togglePause:)) { [(NSMenuItem *)anItem setState:self.isPaused]; - return !GB_debugger_is_stopped(&gb); + return !GB_debugger_is_stopped(&_gb); } else if ([anItem action] == @selector(reset:) && anItem.tag != MODEL_NONE && anItem.tag != MODEL_QUICK_RESET) { - [(NSMenuItem *)anItem setState:anItem.tag == current_model]; + [(NSMenuItem *)anItem setState:anItem.tag == _currentModel]; } else if ([anItem action] == @selector(interrupt:)) { if (![[NSUserDefaults standardUserDefaults] boolForKey:@"DeveloperMode"]) { @@ -1227,32 +1227,32 @@ static bool is_path_writeable(const char *path) } } else if ([anItem action] == @selector(disconnectAllAccessories:)) { - [(NSMenuItem *)anItem setState:GB_get_built_in_accessory(&gb) == GB_ACCESSORY_NONE && !self.partner]; + [(NSMenuItem *)anItem setState:GB_get_built_in_accessory(&_gb) == GB_ACCESSORY_NONE && !self.partner]; } else if ([anItem action] == @selector(connectPrinter:)) { - [(NSMenuItem *)anItem setState:GB_get_built_in_accessory(&gb) == GB_ACCESSORY_PRINTER]; + [(NSMenuItem *)anItem setState:GB_get_built_in_accessory(&_gb) == GB_ACCESSORY_PRINTER]; } else if ([anItem action] == @selector(connectWorkboy:)) { - [(NSMenuItem *)anItem setState:GB_get_built_in_accessory(&gb) == GB_ACCESSORY_WORKBOY]; + [(NSMenuItem *)anItem setState:GB_get_built_in_accessory(&_gb) == GB_ACCESSORY_WORKBOY]; } else if ([anItem action] == @selector(connectLinkCable:)) { - [(NSMenuItem *)anItem setState:[(NSMenuItem *)anItem representedObject] == master || - [(NSMenuItem *)anItem representedObject] == slave]; + [(NSMenuItem *)anItem setState:[(NSMenuItem *)anItem representedObject] == _master || + [(NSMenuItem *)anItem representedObject] == _slave]; } else if ([anItem action] == @selector(toggleCheats:)) { - [(NSMenuItem *)anItem setState:GB_cheats_enabled(&gb)]; + [(NSMenuItem *)anItem setState:GB_cheats_enabled(&_gb)]; } else if ([anItem action] == @selector(toggleDisplayBackground:)) { - [(NSMenuItem *)anItem setState:!GB_is_background_rendering_disabled(&gb)]; + [(NSMenuItem *)anItem setState:!GB_is_background_rendering_disabled(&_gb)]; } else if ([anItem action] == @selector(toggleDisplayObjects:)) { - [(NSMenuItem *)anItem setState:!GB_is_object_rendering_disabled(&gb)]; + [(NSMenuItem *)anItem setState:!GB_is_object_rendering_disabled(&_gb)]; } else if ([anItem action] == @selector(toggleAudioRecording:)) { [(NSMenuItem *)anItem setTitle:_isRecordingAudio? @"Stop Audio Recording" : @"Start Audio Recording…"]; } else if ([anItem action] == @selector(toggleAudioChannel:)) { - [(NSMenuItem *)anItem setState:!GB_is_channel_muted(&gb, [anItem tag])]; + [(NSMenuItem *)anItem setState:!GB_is_channel_muted(&_gb, [anItem tag])]; } return [super validateUserInterfaceItem:anItem]; @@ -1261,23 +1261,23 @@ static bool is_path_writeable(const char *path) - (void) windowWillEnterFullScreen:(NSNotification *)notification { - fullScreen = true; - self.view.mouseHidingEnabled = running; + _fullScreen = true; + self.view.mouseHidingEnabled = _running; } - (void) windowWillExitFullScreen:(NSNotification *)notification { - fullScreen = false; + _fullScreen = false; self.view.mouseHidingEnabled = false; } - (NSRect)windowWillUseStandardFrame:(NSWindow *)window defaultFrame:(NSRect)newFrame { - if (fullScreen) { + if (_fullScreen) { return newFrame; } - size_t width = GB_get_screen_width(&gb), - height = GB_get_screen_height(&gb); + size_t width = GB_get_screen_width(&_gb), + height = GB_get_screen_height(&_gb); NSRect rect = window.contentView.frame; @@ -1304,32 +1304,32 @@ static bool is_path_writeable(const char *path) - (void) appendPendingOutput { - [console_output_lock lock]; - if (shouldClearSideView) { - shouldClearSideView = false; + [_consoleOutputLock lock]; + if (_shouldClearSideView) { + _shouldClearSideView = false; [self.debuggerSideView setString:@""]; } - if (pending_console_output) { - NSTextView *textView = logToSideView? self.debuggerSideView : self.consoleOutput; + if (_pendingConsoleOutput) { + NSTextView *textView = _logToSideView? self.debuggerSideView : self.consoleOutput; - [hex_controller reloadData]; + [_hexController reloadData]; [self reloadVRAMData: nil]; - [textView.textStorage appendAttributedString:pending_console_output]; + [textView.textStorage appendAttributedString:_pendingConsoleOutput]; [textView scrollToEndOfDocument:nil]; if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DeveloperMode"]) { [self.consoleWindow orderFront:nil]; } - pending_console_output = nil; + _pendingConsoleOutput = nil; } - [console_output_lock unlock]; + [_consoleOutputLock unlock]; } - (void) log: (const char *) string withAttributes: (GB_log_attributes) attributes { NSString *nsstring = @(string); // For ref-counting - if (capturedOutput) { - [capturedOutput appendString:nsstring]; + if (_capturedOutput) { + [_capturedOutput appendString:nsstring]; return; } @@ -1353,20 +1353,20 @@ static bool is_path_writeable(const char *path) NSUnderlineStyleAttributeName: @(underline), NSParagraphStyleAttributeName: paragraph_style}]; - [console_output_lock lock]; - if (!pending_console_output) { - pending_console_output = attributed; + [_consoleOutputLock lock]; + if (!_pendingConsoleOutput) { + _pendingConsoleOutput = attributed; } else { - [pending_console_output appendAttributedString:attributed]; + [_pendingConsoleOutput appendAttributedString:attributed]; } - if (![console_output_timer isValid]) { - console_output_timer = [NSTimer timerWithTimeInterval:(NSTimeInterval)0.05 target:self selector:@selector(appendPendingOutput) userInfo:nil repeats:false]; - [[NSRunLoop mainRunLoop] addTimer:console_output_timer forMode:NSDefaultRunLoopMode]; + if (![_consoleOutputTimer isValid]) { + _consoleOutputTimer = [NSTimer timerWithTimeInterval:(NSTimeInterval)0.05 target:self selector:@selector(appendPendingOutput) userInfo:nil repeats:false]; + [[NSRunLoop mainRunLoop] addTimer:_consoleOutputTimer forMode:NSDefaultRunLoopMode]; } - [console_output_lock unlock]; + [_consoleOutputLock unlock]; /* Make sure mouse is not hidden while debugging */ self.view.mouseHidingEnabled = false; @@ -1379,31 +1379,31 @@ static bool is_path_writeable(const char *path) - (void)queueDebuggerCommand:(NSString *)command { - if (!master && !running && !GB_debugger_is_stopped(&gb)) { + if (!_master && !_running && !GB_debugger_is_stopped(&_gb)) { _debuggerCommandWhilePaused = command; - GB_debugger_break(&gb); + GB_debugger_break(&_gb); [self start]; return; } - if (!in_sync_input) { + if (!_inSyncInput) { [self log:">"]; } [self log:[command UTF8String]]; [self log:"\n"]; - [has_debugger_input lock]; - [debugger_input_queue addObject:command]; - [has_debugger_input unlockWithCondition:1]; + [_hasDebuggerInput lock]; + [_debuggerInputQueue addObject:command]; + [_hasDebuggerInput unlockWithCondition:1]; } - (IBAction)consoleInput:(NSTextField *)sender { NSString *line = [sender stringValue]; - if ([line isEqualToString:@""] && lastConsoleInput) { - line = lastConsoleInput; + if ([line isEqualToString:@""] && _lastConsoleInput) { + line = _lastConsoleInput; } else if (line) { - lastConsoleInput = line; + _lastConsoleInput = line; } else { line = @""; @@ -1416,14 +1416,14 @@ static bool is_path_writeable(const char *path) - (void) interruptDebugInputRead { - [has_debugger_input lock]; - [debugger_input_queue addObject:[NSNull null]]; - [has_debugger_input unlockWithCondition:1]; + [_hasDebuggerInput lock]; + [_debuggerInputQueue addObject:[NSNull null]]; + [_hasDebuggerInput unlockWithCondition:1]; } - (void) updateSideView { - if (!GB_debugger_is_stopped(&gb)) { + if (!GB_debugger_is_stopped(&_gb)) { return; } @@ -1434,27 +1434,27 @@ static bool is_path_writeable(const char *path) return; } - [console_output_lock lock]; - shouldClearSideView = true; + [_consoleOutputLock lock]; + _shouldClearSideView = true; [self appendPendingOutput]; - logToSideView = true; - [console_output_lock unlock]; + _logToSideView = true; + [_consoleOutputLock unlock]; for (NSString *line in [self.debuggerSideViewInput.string componentsSeparatedByString:@"\n"]) { NSString *stripped = [line stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; if ([stripped length]) { char *dupped = strdup([stripped UTF8String]); - GB_attributed_log(&gb, GB_LOG_BOLD, "%s:\n", dupped); - GB_debugger_execute_command(&gb, dupped); - GB_log(&gb, "\n"); + GB_attributed_log(&_gb, GB_LOG_BOLD, "%s:\n", dupped); + GB_debugger_execute_command(&_gb, dupped); + GB_log(&_gb, "\n"); free(dupped); } } - [console_output_lock lock]; + [_consoleOutputLock lock]; [self appendPendingOutput]; - logToSideView = false; - [console_output_lock unlock]; + _logToSideView = false; + [_consoleOutputLock unlock]; } - (char *)getDebuggerInput @@ -1463,10 +1463,10 @@ static bool is_path_writeable(const char *path) if (isPlaying) { [_audioClient stop]; } - [audioLock lock]; - [audioLock signal]; - [audioLock unlock]; - in_sync_input = true; + [_audioLock lock]; + [_audioLock signal]; + [_audioLock unlock]; + _inSyncInput = true; [self updateSideView]; dispatch_async(dispatch_get_main_queue(), ^{ [self updateDebuggerButtons]; @@ -1480,15 +1480,15 @@ static bool is_path_writeable(const char *path) [self queueDebuggerCommand:command]; }); } - [has_debugger_input lockWhenCondition:1]; - NSString *input = [debugger_input_queue firstObject]; - [debugger_input_queue removeObjectAtIndex:0]; - [has_debugger_input unlockWithCondition:[debugger_input_queue count] != 0]; - in_sync_input = false; - shouldClearSideView = true; + [_hasDebuggerInput lockWhenCondition:1]; + NSString *input = [_debuggerInputQueue firstObject]; + [_debuggerInputQueue removeObjectAtIndex:0]; + [_hasDebuggerInput unlockWithCondition:[_debuggerInputQueue count] != 0]; + _inSyncInput = false; + _shouldClearSideView = true; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(NSEC_PER_SEC / 10)), dispatch_get_main_queue(), ^{ - if (shouldClearSideView) { - shouldClearSideView = false; + if (_shouldClearSideView) { + _shouldClearSideView = false; [self.debuggerSideView setString:@""]; } [self updateDebuggerButtons]; @@ -1505,12 +1505,12 @@ static bool is_path_writeable(const char *path) - (char *) getAsyncDebuggerInput { - [has_debugger_input lock]; - NSString *input = [debugger_input_queue firstObject]; + [_hasDebuggerInput lock]; + NSString *input = [_debuggerInputQueue firstObject]; if (input) { - [debugger_input_queue removeObjectAtIndex:0]; + [_debuggerInputQueue removeObjectAtIndex:0]; } - [has_debugger_input unlockWithCondition:[debugger_input_queue count] != 0]; + [_hasDebuggerInput unlockWithCondition:[_debuggerInputQueue count] != 0]; if ((id)input == [NSNull null]) { return NULL; } @@ -1521,7 +1521,7 @@ static bool is_path_writeable(const char *path) { bool __block success = false; [self performAtomicBlock:^{ - success = GB_save_state(&gb, [self saveStatePath:[sender tag]].UTF8String) == 0; + success = GB_save_state(&_gb, [self saveStatePath:[sender tag]].UTF8String) == 0; }]; if (!success) { @@ -1538,7 +1538,7 @@ static bool is_path_writeable(const char *path) int __block result = false; NSString *error = [self captureOutputForBlock:^{ - result = GB_load_state(&gb, path); + result = GB_load_state(&_gb, path); }]; if (result == ENOENT && noErrorOnFileNotFound) { @@ -1577,30 +1577,30 @@ static bool is_path_writeable(const char *path) - (uint8_t) readMemory:(uint16_t)addr { - while (!GB_is_inited(&gb)); - return GB_safe_read_memory(&gb, addr); + while (!GB_is_inited(&_gb)); + return GB_safe_read_memory(&_gb, addr); } - (void) writeMemory:(uint16_t)addr value:(uint8_t)value { - while (!GB_is_inited(&gb)); - GB_write_memory(&gb, addr, value); + while (!GB_is_inited(&_gb)); + GB_write_memory(&_gb, addr, value); } - (void) performAtomicBlock: (void (^)())block { - while (!GB_is_inited(&gb)); - bool isRunning = running && !GB_debugger_is_stopped(&gb); - if (master) { - isRunning |= master->running; + while (!GB_is_inited(&_gb)); + bool isRunning = _running && !GB_debugger_is_stopped(&_gb); + if (_master) { + isRunning |= _master->_running; } if (!isRunning) { block(); return; } - if (master) { - [master performAtomicBlock:block]; + if (_master) { + [_master performAtomicBlock:block]; return; } @@ -1610,10 +1610,10 @@ static bool is_path_writeable(const char *path) - (NSString *)captureOutputForBlock: (void (^)())block { - capturedOutput = [[NSMutableString alloc] init]; + _capturedOutput = [[NSMutableString alloc] init]; [self performAtomicBlock:block]; - NSString *ret = [capturedOutput stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]]; - capturedOutput = nil; + NSString *ret = [_capturedOutput stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]]; + _capturedOutput = nil; return [ret length]? ret : nil; } @@ -1640,14 +1640,14 @@ static bool is_path_writeable(const char *path) - (void) reloadMemoryView { if (self.memoryWindow.isVisible) { - [hex_controller reloadData]; + [_hexController reloadData]; } } - (IBAction) reloadVRAMData: (id) sender { if (self.vramWindow.isVisible) { - uint8_t *io_regs = GB_get_direct_access(&gb, GB_DIRECT_ACCESS_IO, NULL, NULL); + uint8_t *io_regs = GB_get_direct_access(&_gb, GB_DIRECT_ACCESS_IO, NULL, NULL); switch ([self.vramTabView.tabViewItems indexOfObject:self.vramTabView.selectedTabViewItem]) { case 0: /* Tileset */ @@ -1660,7 +1660,7 @@ static bool is_path_writeable(const char *path) size_t bufferLength = 256 * 192 * 4; NSMutableData *data = [NSMutableData dataWithCapacity:bufferLength]; data.length = bufferLength; - GB_draw_tileset(&gb, (uint32_t *)data.mutableBytes, palette_type, (palette_menu_index - 1) & 7); + GB_draw_tileset(&_gb, (uint32_t *)data.mutableBytes, palette_type, (palette_menu_index - 1) & 7); self.tilesetImageView.image = [Document imageFromData:data width:256 height:192 scale:1.0]; self.tilesetImageView.layer.magnificationFilter = kCAFilterNearest; @@ -1682,7 +1682,7 @@ static bool is_path_writeable(const char *path) size_t bufferLength = 256 * 256 * 4; NSMutableData *data = [NSMutableData dataWithCapacity:bufferLength]; data.length = bufferLength; - GB_draw_tilemap(&gb, (uint32_t *)data.mutableBytes, palette_type, (palette_menu_index - 2) & 7, + GB_draw_tilemap(&_gb, (uint32_t *)data.mutableBytes, palette_type, (palette_menu_index - 2) & 7, (GB_map_type_t) self.tilemapMapButton.indexOfSelectedItem, (GB_tileset_type_t) self.TilemapSetButton.indexOfSelectedItem); @@ -1697,7 +1697,7 @@ static bool is_path_writeable(const char *path) case 2: /* OAM */ { - _oamCount = GB_get_oam_info(&gb, _oamInfo, &_oamHeight); + _oamCount = GB_get_oam_info(&_gb, _oamInfo, &_oamHeight); dispatch_async(dispatch_get_main_queue(), ^{ [self.objectView reloadData:self]; }); @@ -1718,7 +1718,7 @@ static bool is_path_writeable(const char *path) - (IBAction) showMemory:(id)sender { - if (!hex_controller) { + if (!_hexController) { [self initMemoryView]; } [self.memoryWindow makeKeyAndOrderFront:sender]; @@ -1728,19 +1728,19 @@ static bool is_path_writeable(const char *path) { NSString *error = [self captureOutputForBlock:^{ uint16_t addr; - if (GB_debugger_evaluate(&gb, [[sender stringValue] UTF8String], &addr, NULL)) { + if (GB_debugger_evaluate(&_gb, [[sender stringValue] UTF8String], &addr, NULL)) { return; } - addr -= lineRep.valueOffset; - if (addr >= hex_controller.byteArray.length) { - GB_log(&gb, "Value $%04x is out of range.\n", addr); + addr -= _lineRep.valueOffset; + if (addr >= _hexController.byteArray.length) { + GB_log(&_gb, "Value $%04x is out of range.\n", addr); return; } dispatch_async(dispatch_get_main_queue(), ^{ - [hex_controller setSelectedContentsRanges:@[[HFRangeWrapper withRange:HFRangeMake(addr, 0)]]]; - [hex_controller _ensureVisibilityOfLocation:addr]; - for (HFRepresenter *representer in hex_controller.representers) { + [_hexController setSelectedContentsRanges:@[[HFRangeWrapper withRange:HFRangeMake(addr, 0)]]]; + [_hexController _ensureVisibilityOfLocation:addr]; + for (HFRepresenter *representer in _hexController.representers) { if ([representer isKindOfClass:[HFHexTextRepresenter class]]) { [self.memoryWindow makeFirstResponder:representer.view]; break; @@ -1758,7 +1758,7 @@ static bool is_path_writeable(const char *path) { NSString *error = [self captureOutputForBlock:^{ uint16_t addr, bank; - if (GB_debugger_evaluate(&gb, [[sender stringValue] UTF8String], &addr, &bank)) { + if (GB_debugger_evaluate(&_gb, [[sender stringValue] UTF8String], &addr, &bank)) { return; } @@ -1767,24 +1767,24 @@ static bool is_path_writeable(const char *path) } uint16_t n_banks = 1; - switch ([(GBMemoryByteArray *)(hex_controller.byteArray) mode]) { + switch ([(GBMemoryByteArray *)(_hexController.byteArray) mode]) { case GBMemoryROM: { size_t rom_size; - GB_get_direct_access(&gb, GB_DIRECT_ACCESS_ROM, &rom_size, NULL); + GB_get_direct_access(&_gb, GB_DIRECT_ACCESS_ROM, &rom_size, NULL); n_banks = rom_size / 0x4000; break; } case GBMemoryVRAM: - n_banks = GB_is_cgb(&gb) ? 2 : 1; + n_banks = GB_is_cgb(&_gb) ? 2 : 1; break; case GBMemoryExternalRAM: { size_t ram_size; - GB_get_direct_access(&gb, GB_DIRECT_ACCESS_CART_RAM, &ram_size, NULL); + GB_get_direct_access(&_gb, GB_DIRECT_ACCESS_CART_RAM, &ram_size, NULL); n_banks = (ram_size + 0x1FFF) / 0x2000; break; } case GBMemoryRAM: - n_banks = GB_is_cgb(&gb) ? 8 : 1; + n_banks = GB_is_cgb(&_gb) ? 8 : 1; break; case GBMemoryEntireSpace: break; @@ -1793,9 +1793,9 @@ static bool is_path_writeable(const char *path) bank %= n_banks; [sender setStringValue:[NSString stringWithFormat:@"$%x", bank]]; - [(GBMemoryByteArray *)(hex_controller.byteArray) setSelectedBank:bank]; + [(GBMemoryByteArray *)(_hexController.byteArray) setSelectedBank:bank]; dispatch_async(dispatch_get_main_queue(), ^{ - [hex_controller reloadData]; + [_hexController reloadData]; }); }]; @@ -1813,34 +1813,34 @@ static bool is_path_writeable(const char *path) - (IBAction)hexUpdateSpace:(NSPopUpButtonCell *)sender { self.memoryBankItem.enabled = [sender indexOfSelectedItem] != GBMemoryEntireSpace; - GBMemoryByteArray *byteArray = (GBMemoryByteArray *)(hex_controller.byteArray); + GBMemoryByteArray *byteArray = (GBMemoryByteArray *)(_hexController.byteArray); [byteArray setMode:(GB_memory_mode_t)[sender indexOfSelectedItem]]; uint16_t bank; switch ((GB_memory_mode_t)[sender indexOfSelectedItem]) { case GBMemoryEntireSpace: case GBMemoryROM: - lineRep.valueOffset = 0; - GB_get_direct_access(&gb, GB_DIRECT_ACCESS_ROM, NULL, &bank); + _lineRep.valueOffset = 0; + GB_get_direct_access(&_gb, GB_DIRECT_ACCESS_ROM, NULL, &bank); byteArray.selectedBank = bank; break; case GBMemoryVRAM: - lineRep.valueOffset = 0x8000; - GB_get_direct_access(&gb, GB_DIRECT_ACCESS_VRAM, NULL, &bank); + _lineRep.valueOffset = 0x8000; + GB_get_direct_access(&_gb, GB_DIRECT_ACCESS_VRAM, NULL, &bank); byteArray.selectedBank = bank; break; case GBMemoryExternalRAM: - lineRep.valueOffset = 0xA000; - GB_get_direct_access(&gb, GB_DIRECT_ACCESS_CART_RAM, NULL, &bank); + _lineRep.valueOffset = 0xA000; + GB_get_direct_access(&_gb, GB_DIRECT_ACCESS_CART_RAM, NULL, &bank); byteArray.selectedBank = bank; break; case GBMemoryRAM: - lineRep.valueOffset = 0xC000; - GB_get_direct_access(&gb, GB_DIRECT_ACCESS_RAM, NULL, &bank); + _lineRep.valueOffset = 0xC000; + GB_get_direct_access(&_gb, GB_DIRECT_ACCESS_RAM, NULL, &bank); byteArray.selectedBank = bank; break; } [self.memoryBankInput setStringValue:[NSString stringWithFormat:@"$%x", byteArray.selectedBank]]; - [hex_controller reloadData]; + [_hexController reloadData]; for (NSView *view in self.memoryView.subviews) { [view setNeedsDisplay:true]; } @@ -1848,7 +1848,7 @@ static bool is_path_writeable(const char *path) - (GB_gameboy_t *) gameboy { - return &gb; + return &_gb; } + (BOOL)canConcurrentlyReadDocumentsOfType:(NSString *)typeName @@ -1860,7 +1860,7 @@ static bool is_path_writeable(const char *path) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ @try { - if (!cameraSession) { + if (!_cameraSession) { if (@available(macOS 10.14, *)) { switch ([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]) { case AVAuthorizationStatusAuthorized: @@ -1873,7 +1873,7 @@ static bool is_path_writeable(const char *path) } case AVAuthorizationStatusDenied: case AVAuthorizationStatusRestricted: - GB_camera_updated(&gb); + GB_camera_updated(&_gb); return; } } @@ -1884,62 +1884,62 @@ static bool is_path_writeable(const char *path) CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions([[[device formats] lastObject] formatDescription]); if (!input) { - GB_camera_updated(&gb); + GB_camera_updated(&_gb); return; } double ratio = MAX(130.0 / dimensions.width, 114.0 / dimensions.height); - cameraOutput = [[AVCaptureStillImageOutput alloc] init]; + _cameraOutput = [[AVCaptureStillImageOutput alloc] init]; /* Greyscale is not widely supported, so we use YUV, whose first element is the brightness. */ - [cameraOutput setOutputSettings: @{(id)kCVPixelBufferPixelFormatTypeKey: @(kYUVSPixelFormat), + [_cameraOutput setOutputSettings: @{(id)kCVPixelBufferPixelFormatTypeKey: @(kYUVSPixelFormat), (id)kCVPixelBufferWidthKey: @(round(dimensions.width * ratio)), (id)kCVPixelBufferHeightKey: @(round(dimensions.height * ratio)),}]; - cameraSession = [AVCaptureSession new]; - cameraSession.sessionPreset = AVCaptureSessionPresetPhoto; + _cameraSession = [AVCaptureSession new]; + _cameraSession.sessionPreset = AVCaptureSessionPresetPhoto; - [cameraSession addInput: input]; - [cameraSession addOutput: cameraOutput]; - [cameraSession startRunning]; - cameraConnection = [cameraOutput connectionWithMediaType: AVMediaTypeVideo]; + [_cameraSession addInput: input]; + [_cameraSession addOutput: _cameraOutput]; + [_cameraSession startRunning]; + _cameraConnection = [_cameraOutput connectionWithMediaType: AVMediaTypeVideo]; } - [cameraOutput captureStillImageAsynchronouslyFromConnection: cameraConnection completionHandler: ^(CMSampleBufferRef sampleBuffer, NSError *error) { + [_cameraOutput captureStillImageAsynchronouslyFromConnection: _cameraConnection completionHandler: ^(CMSampleBufferRef sampleBuffer, NSError *error) { if (error) { - GB_camera_updated(&gb); + GB_camera_updated(&_gb); } else { - if (cameraImage) { - CVBufferRelease(cameraImage); - cameraImage = NULL; + if (_cameraImage) { + CVBufferRelease(_cameraImage); + _cameraImage = NULL; } - cameraImage = CVBufferRetain(CMSampleBufferGetImageBuffer(sampleBuffer)); + _cameraImage = CVBufferRetain(CMSampleBufferGetImageBuffer(sampleBuffer)); /* We only need the actual buffer, no need to ever unlock it. */ - CVPixelBufferLockBaseAddress(cameraImage, 0); + CVPixelBufferLockBaseAddress(_cameraImage, 0); } - GB_camera_updated(&gb); + GB_camera_updated(&_gb); }]; } @catch (NSException *exception) { /* I have not tested camera support on many devices, so we catch exceptions just in case. */ - GB_camera_updated(&gb); + GB_camera_updated(&_gb); } }); } - (uint8_t)cameraGetPixelAtX:(unsigned)x andY:(unsigned)y { - if (!cameraImage) { + if (!_cameraImage) { return 0; } - uint8_t *baseAddress = (uint8_t *)CVPixelBufferGetBaseAddress(cameraImage); - size_t bytesPerRow = CVPixelBufferGetBytesPerRow(cameraImage); - unsigned offsetX = (CVPixelBufferGetWidth(cameraImage) - 128) / 2; - unsigned offsetY = (CVPixelBufferGetHeight(cameraImage) - 112) / 2; + uint8_t *baseAddress = (uint8_t *)CVPixelBufferGetBaseAddress(_cameraImage); + size_t bytesPerRow = CVPixelBufferGetBytesPerRow(_cameraImage); + unsigned offsetX = (CVPixelBufferGetWidth(_cameraImage) - 128) / 2; + unsigned offsetY = (CVPixelBufferGetHeight(_cameraImage) - 112) / 2; uint8_t ret = baseAddress[(x + offsetX) * 2 + (y + offsetY) * bytesPerRow]; return ret; @@ -2024,8 +2024,8 @@ static bool is_path_writeable(const char *path) uint16_t map_base = 0x1800; GB_map_type_t map_type = (GB_map_type_t) self.tilemapMapButton.indexOfSelectedItem; GB_tileset_type_t tileset_type = (GB_tileset_type_t) self.TilemapSetButton.indexOfSelectedItem; - uint8_t lcdc = ((uint8_t *)GB_get_direct_access(&gb, GB_DIRECT_ACCESS_IO, NULL, NULL))[GB_IO_LCDC]; - uint8_t *vram = GB_get_direct_access(&gb, GB_DIRECT_ACCESS_VRAM, NULL, NULL); + uint8_t lcdc = ((uint8_t *)GB_get_direct_access(&_gb, GB_DIRECT_ACCESS_IO, NULL, NULL))[GB_IO_LCDC]; + uint8_t *vram = GB_get_direct_access(&_gb, GB_DIRECT_ACCESS_VRAM, NULL, NULL); if (map_type == GB_MAP_9C00 || (map_type == GB_MAP_AUTO && lcdc & GB_LCDC_BG_MAP)) { map_base = 0x1C00; @@ -2044,7 +2044,7 @@ static bool is_path_writeable(const char *path) tile_address = 0x9000 + (int8_t)tile * 0x10; } - if (GB_is_cgb(&gb)) { + if (GB_is_cgb(&_gb)) { uint8_t attributes = vram[map_base + map_offset + 0x2000]; self.vramStatusLabel.stringValue = [NSString stringWithFormat:@"Tile number $%02x (%d:$%04x) at map address $%04x (Attributes: %c%c%c%d%d)", tile, @@ -2088,15 +2088,15 @@ static bool is_path_writeable(const char *path) memset(paddedImage, 0xFF, sizeof(paddedImage)); memcpy(paddedImage + (160 * topMargin), imageBytes, 160 * height * sizeof(imageBytes[0])); if (!self.printerFeedWindow.isVisible) { - currentPrinterImageData = [[NSMutableData alloc] init]; + _currentPrinterImageData = [[NSMutableData alloc] init]; } - [currentPrinterImageData appendBytes:paddedImage length:sizeof(paddedImage)]; + [_currentPrinterImageData appendBytes:paddedImage length:sizeof(paddedImage)]; /* UI related code must run on main thread. */ dispatch_async(dispatch_get_main_queue(), ^{ [_printerSpinner startAnimation:nil]; - self.feedImageView.image = [Document imageFromData:currentPrinterImageData + self.feedImageView.image = [Document imageFromData:_currentPrinterImageData width:160 - height:currentPrinterImageData.length / 160 / sizeof(imageBytes[0]) + height:_currentPrinterImageData.length / 160 / sizeof(imageBytes[0]) scale:2.0]; NSRect frame = self.printerFeedWindow.frame; frame.size = self.feedImageView.image.size; @@ -2127,7 +2127,7 @@ static bool is_path_writeable(const char *path) - (IBAction)savePrinterFeed:(id)sender { - bool shouldResume = running; + bool shouldResume = _running; [self stop]; NSSavePanel *savePanel = [NSSavePanel savePanel]; [savePanel setAllowedFileTypes:@[@"png"]]; @@ -2153,7 +2153,7 @@ static bool is_path_writeable(const char *path) { [self disconnectLinkCable]; [self performAtomicBlock:^{ - GB_disconnect_serial(&gb); + GB_disconnect_serial(&_gb); }]; } @@ -2161,7 +2161,7 @@ static bool is_path_writeable(const char *path) { [self disconnectLinkCable]; [self performAtomicBlock:^{ - GB_connect_printer(&gb, printImage, printDone); + GB_connect_printer(&_gb, printImage, printDone); }]; } @@ -2169,7 +2169,7 @@ static bool is_path_writeable(const char *path) { [self disconnectLinkCable]; [self performAtomicBlock:^{ - GB_connect_workboy(&gb, setWorkboyTime, getWorkboyTime); + GB_connect_workboy(&_gb, setWorkboyTime, getWorkboyTime); }]; } @@ -2180,29 +2180,29 @@ static bool is_path_writeable(const char *path) - (void) updateHighpassFilter { - if (GB_is_inited(&gb)) { - GB_set_highpass_filter_mode(&gb, (GB_highpass_mode_t) [[NSUserDefaults standardUserDefaults] integerForKey:@"GBHighpassFilter"]); + if (GB_is_inited(&_gb)) { + GB_set_highpass_filter_mode(&_gb, (GB_highpass_mode_t) [[NSUserDefaults standardUserDefaults] integerForKey:@"GBHighpassFilter"]); } } - (void) updateColorCorrectionMode { - if (GB_is_inited(&gb)) { - GB_set_color_correction_mode(&gb, (GB_color_correction_mode_t) [[NSUserDefaults standardUserDefaults] integerForKey:@"GBColorCorrection"]); + if (GB_is_inited(&_gb)) { + GB_set_color_correction_mode(&_gb, (GB_color_correction_mode_t) [[NSUserDefaults standardUserDefaults] integerForKey:@"GBColorCorrection"]); } } - (void) updateLightTemperature { - if (GB_is_inited(&gb)) { - GB_set_light_temperature(&gb, [[NSUserDefaults standardUserDefaults] doubleForKey:@"GBLightTemperature"]); + if (GB_is_inited(&_gb)) { + GB_set_light_temperature(&_gb, [[NSUserDefaults standardUserDefaults] doubleForKey:@"GBLightTemperature"]); } } - (void) updateInterferenceVolume { - if (GB_is_inited(&gb)) { - GB_set_interference_volume(&gb, [[NSUserDefaults standardUserDefaults] doubleForKey:@"GBInterferenceVolume"]); + if (GB_is_inited(&_gb)) { + GB_set_interference_volume(&_gb, [[NSUserDefaults standardUserDefaults] doubleForKey:@"GBInterferenceVolume"]); } } @@ -2214,53 +2214,53 @@ static bool is_path_writeable(const char *path) - (void) updateRewindLength { [self performAtomicBlock:^{ - if (GB_is_inited(&gb)) { - GB_set_rewind_length(&gb, [[NSUserDefaults standardUserDefaults] integerForKey:@"GBRewindLength"]); + if (GB_is_inited(&_gb)) { + GB_set_rewind_length(&_gb, [[NSUserDefaults standardUserDefaults] integerForKey:@"GBRewindLength"]); } }]; } - (void) updateRTCMode { - if (GB_is_inited(&gb)) { - GB_set_rtc_mode(&gb, [[NSUserDefaults standardUserDefaults] integerForKey:@"GBRTCMode"]); + if (GB_is_inited(&_gb)) { + GB_set_rtc_mode(&_gb, [[NSUserDefaults standardUserDefaults] integerForKey:@"GBRTCMode"]); } } - (void)dmgModelChanged { - modelsChanging = true; - if (current_model == MODEL_DMG) { + _modelsChanging = true; + if (_currentModel == MODEL_DMG) { [self reset:nil]; } - modelsChanging = false; + _modelsChanging = false; } - (void)sgbModelChanged { - modelsChanging = true; - if (current_model == MODEL_SGB) { + _modelsChanging = true; + if (_currentModel == MODEL_SGB) { [self reset:nil]; } - modelsChanging = false; + _modelsChanging = false; } - (void)cgbModelChanged { - modelsChanging = true; - if (current_model == MODEL_CGB) { + _modelsChanging = true; + if (_currentModel == MODEL_CGB) { [self reset:nil]; } - modelsChanging = false; + _modelsChanging = false; } - (void)agbModelChanged { - modelsChanging = true; - if (current_model == MODEL_AGB) { + _modelsChanging = true; + if (_currentModel == MODEL_AGB) { [self reset:nil]; } - modelsChanging = false; + _modelsChanging = false; } - (void)setFileURL:(NSURL *)fileURL @@ -2311,26 +2311,26 @@ static bool is_path_writeable(const char *path) - (IBAction)toggleCheats:(id)sender { - GB_set_cheats_enabled(&gb, !GB_cheats_enabled(&gb)); + GB_set_cheats_enabled(&_gb, !GB_cheats_enabled(&_gb)); } - (void)disconnectLinkCable { - bool wasRunning = self->running; - Document *partner = master ?: slave; + bool wasRunning = self->_running; + Document *partner = _master ?: _slave; if (partner) { - wasRunning |= partner->running; + wasRunning |= partner->_running; [self stop]; - partner->master = nil; - partner->slave = nil; - master = nil; - slave = nil; + partner->_master = nil; + partner->_slave = nil; + _master = nil; + _slave = nil; if (wasRunning) { [partner start]; [self start]; } - GB_set_turbo_mode(&gb, false, false); - GB_set_turbo_mode(&partner->gb, false, false); + GB_set_turbo_mode(&_gb, false, false); + GB_set_turbo_mode(&partner->_gb, false, false); } } @@ -2340,54 +2340,54 @@ static bool is_path_writeable(const char *path) Document *partner = [sender representedObject]; [partner disconnectAllAccessories:sender]; - bool wasRunning = self->running; + bool wasRunning = self->_running; [self stop]; [partner stop]; - GB_set_turbo_mode(&partner->gb, true, true); - slave = partner; - partner->master = self; - linkOffset = 0; - GB_set_serial_transfer_bit_start_callback(&gb, linkCableBitStart); - GB_set_serial_transfer_bit_start_callback(&partner->gb, linkCableBitStart); - GB_set_serial_transfer_bit_end_callback(&gb, linkCableBitEnd); - GB_set_serial_transfer_bit_end_callback(&partner->gb, linkCableBitEnd); + GB_set_turbo_mode(&partner->_gb, true, true); + _slave = partner; + partner->_master = self; + _linkOffset = 0; + GB_set_serial_transfer_bit_start_callback(&_gb, _linkCableBitStart); + GB_set_serial_transfer_bit_start_callback(&partner->_gb, _linkCableBitStart); + GB_set_serial_transfer_bit_end_callback(&_gb, _linkCableBitEnd); + GB_set_serial_transfer_bit_end_callback(&partner->_gb, _linkCableBitEnd); if (wasRunning) { [self start]; } } -- (void)linkCableBitStart:(bool)bit +- (void)_linkCableBitStart:(bool)bit { - linkCableBit = bit; + _linkCableBit = bit; } --(bool)linkCableBitEnd +-(bool)_linkCableBitEnd { - bool ret = GB_serial_get_data_bit(&self.partner->gb); - GB_serial_set_data_bit(&self.partner->gb, linkCableBit); + bool ret = GB_serial_get_data_bit(&self.partner->_gb); + GB_serial_set_data_bit(&self.partner->_gb, _linkCableBit); return ret; } - (void)infraredStateChanged:(bool)state { if (self.partner) { - GB_set_infrared_input(&self.partner->gb, state); + GB_set_infrared_input(&self.partner->_gb, state); } } -(Document *)partner { - return slave ?: master; + return _slave ?: _master; } - (bool)isSlave { - return master; + return _master; } - (GB_gameboy_t *)gb { - return &gb; + return &_gb; } - (NSImage *)takeScreenshot @@ -2404,10 +2404,10 @@ static bool is_path_writeable(const char *path) } if (!ret) { ret = [Document imageFromData:[NSData dataWithBytesNoCopy:_view.currentBuffer - length:GB_get_screen_width(&gb) * GB_get_screen_height(&gb) * 4 + length:GB_get_screen_width(&_gb) * GB_get_screen_height(&_gb) * 4 freeWhenDone:false] - width:GB_get_screen_width(&gb) - height:GB_get_screen_height(&gb) + width:GB_get_screen_width(&_gb) + height:GB_get_screen_height(&_gb) scale:1.0]; } return ret; @@ -2433,7 +2433,7 @@ static bool is_path_writeable(const char *path) [[NSFileManager defaultManager] fileExistsAtPath:folder isDirectory:&isDirectory]; } if (!folder) { - bool shouldResume = running; + bool shouldResume = _running; [self stop]; NSOpenPanel *openPanel = [NSOpenPanel openPanel]; openPanel.canChooseFiles = false; @@ -2471,7 +2471,7 @@ static bool is_path_writeable(const char *path) - (IBAction)saveScreenshotAs:(id)sender { - bool shouldResume = running; + bool shouldResume = _running; [self stop]; NSImage *image = [self takeScreenshot]; NSSavePanel *savePanel = [NSSavePanel savePanel]; @@ -2502,17 +2502,17 @@ static bool is_path_writeable(const char *path) - (IBAction)toggleDisplayBackground:(id)sender { - GB_set_background_rendering_disabled(&gb, !GB_is_background_rendering_disabled(&gb)); + GB_set_background_rendering_disabled(&_gb, !GB_is_background_rendering_disabled(&_gb)); } - (IBAction)toggleDisplayObjects:(id)sender { - GB_set_object_rendering_disabled(&gb, !GB_is_object_rendering_disabled(&gb)); + GB_set_object_rendering_disabled(&_gb, !GB_is_object_rendering_disabled(&_gb)); } - (IBAction)newCartridgeInstance:(id)sender { - bool shouldResume = running; + bool shouldResume = _running; [self stop]; NSSavePanel *savePanel = [NSSavePanel savePanel]; [savePanel setAllowedFileTypes:@[@"gbcart"]]; @@ -2538,11 +2538,11 @@ static bool is_path_writeable(const char *path) - (IBAction)toggleAudioRecording:(id)sender { - bool shouldResume = running; + bool shouldResume = _running; [self stop]; if (_isRecordingAudio) { _isRecordingAudio = false; - int error = GB_stop_audio_recording(&gb); + int error = GB_stop_audio_recording(&_gb); if (error) { NSAlert *alert = [[NSAlert alloc] init]; [alert setMessageText:[NSString stringWithFormat:@"Could not finalize recording: %s", strerror(error)]]; @@ -2567,7 +2567,7 @@ static bool is_path_writeable(const char *path) [_audioSavePanel beginSheetModalForWindow:self.mainWindow completionHandler:^(NSInteger result) { if (result == NSModalResponseOK) { [_audioSavePanel orderOut:self]; - int error = GB_start_audio_recording(&gb, _audioSavePanel.URL.fileSystemRepresentation, self.audioFormatButton.selectedTag); + int error = GB_start_audio_recording(&_gb, _audioSavePanel.URL.fileSystemRepresentation, self.audioFormatButton.selectedTag); if (error) { NSAlert *alert = [[NSAlert alloc] init]; [alert setMessageText:[NSString stringWithFormat:@"Could not start recording: %s", strerror(error)]]; @@ -2603,12 +2603,12 @@ static bool is_path_writeable(const char *path) - (IBAction)toggleAudioChannel:(NSMenuItem *)sender { - GB_set_channel_muted(&gb, sender.tag, !GB_is_channel_muted(&gb, sender.tag)); + GB_set_channel_muted(&_gb, sender.tag, !GB_is_channel_muted(&_gb, sender.tag)); } - (IBAction)cartSwap:(id)sender { - bool wasRunning = running; + bool wasRunning = _running; if (wasRunning) { [self stop]; } @@ -2627,7 +2627,7 @@ static bool is_path_writeable(const char *path) } } if (ok) { - GB_save_battery(&gb, self.savPath.UTF8String); + GB_save_battery(&_gb, self.savPath.UTF8String); self.fileURL = urls.firstObject; [self loadROM]; }
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.