diff --git a/BootROMs/pb8.c b/BootROMs/pb8.c index 03a196e..4ee4524 100644 --- a/BootROMs/pb8.c +++ b/BootROMs/pb8.c @@ -97,7 +97,8 @@ LoadTileset: * @param blocklength size of an independent input block in bytes * @return 0 for reaching infp end of file, or EOF for error */ -int pb8(FILE *infp, FILE *outfp, size_t blocklength) { +int pb8(FILE *infp, FILE *outfp, size_t blocklength) +{ blocklength >>= 3; // convert bytes to blocks assert(blocklength > 0); while (1) { @@ -113,7 +114,8 @@ int pb8(FILE *infp, FILE *outfp, size_t blocklength) { control_byte <<= 1; if (c == last_byte) { control_byte |= 0x01; - } else { + } + else { literals[nliterals++] = last_byte = c; } } @@ -143,7 +145,8 @@ int pb8(FILE *infp, FILE *outfp, size_t blocklength) { * @param outfp output stream * @return 0 for reaching infp end of file, or EOF for error */ -int unpb8(FILE *infp, FILE *outfp) { +int unpb8(FILE *infp, FILE *outfp) +{ int last_byte = 0; while (1) { int control_byte = fgetc(infp); @@ -165,7 +168,8 @@ int unpb8(FILE *infp, FILE *outfp) { /* CLI frontend ****************************************************/ -static inline void set_fd_binary(unsigned int fd) { +static inline void set_fd_binary(unsigned int fd) +{ #ifdef _WIN32 _setmode(fd, _O_BINARY); #else @@ -197,7 +201,8 @@ static const char *version_msg = static const char *toomanyfilenames_msg = "pb8: too many filenames; try pb8 --help\n"; -int main(int argc, char **argv) { +int main(int argc, char **argv) +{ const char *infilename = NULL; const char *outfilename = NULL; bool decompress = false; @@ -248,11 +253,14 @@ int main(int argc, char **argv) { fprintf(stderr, "pb8: unknown option -%c\n", argtype); return EXIT_FAILURE; } - } else if (!infilename) { + } + else if (!infilename) { infilename = argv[i]; - } else if (!outfilename) { + } + else if (!outfilename) { outfilename = argv[i]; - } else { + } + else { fputs(toomanyfilenames_msg, stderr); return EXIT_FAILURE; } @@ -282,7 +290,8 @@ int main(int argc, char **argv) { perror("for reading"); return EXIT_FAILURE; } - } else { + } + else { infp = stdin; set_fd_binary(0); } @@ -296,7 +305,8 @@ int main(int argc, char **argv) { fclose(infp); return EXIT_FAILURE; } - } else { + } + else { outfp = stdout; set_fd_binary(1); } @@ -305,7 +315,8 @@ int main(int argc, char **argv) { int has_ferror = 0; if (decompress) { compfailed = unpb8(infp, outfp); - } else { + } + else { compfailed = pb8(infp, outfp, blocklength); } fflush(outfp); diff --git a/Cocoa/Document.m b/Cocoa/Document.m index 10ba510..ed3eaaf 100644 --- a/Cocoa/Document.m +++ b/Cocoa/Document.m @@ -150,7 +150,8 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) NSMutableArray *debugger_input_queue; } -- (instancetype)init { +- (instancetype)init +{ self = [super init]; if (self) { has_debugger_input = [[NSConditionLock alloc] initWithCondition:0]; @@ -470,7 +471,8 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) } } -- (void)windowControllerDidLoadNib:(NSWindowController *)aController { +- (void)windowControllerDidLoadNib:(NSWindowController *)aController +{ [super windowControllerDidLoadNib:aController]; // Interface Builder bug? [self.consoleWindow setContentSize:self.consoleWindow.minSize]; @@ -625,11 +627,13 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) self.memoryBankItem.enabled = false; } -+ (BOOL)autosavesInPlace { ++ (BOOL)autosavesInPlace +{ return YES; } -- (NSString *)windowNibName { +- (NSString *)windowNibName +{ // Override returning the nib file name of the document // If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead. return @"Document"; @@ -690,7 +694,7 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) - (BOOL)validateUserInterfaceItem:(id)anItem { - if([anItem action] == @selector(mute:)) { + if ([anItem action] == @selector(mute:)) { [(NSMenuItem*)anItem setState:!self.audioClient.isPlaying]; } else if ([anItem action] == @selector(togglePause:)) { @@ -837,7 +841,8 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) [self.consoleWindow orderBack:nil]; } -- (IBAction)consoleInput:(NSTextField *)sender { +- (IBAction)consoleInput:(NSTextField *)sender +{ NSString *line = [sender stringValue]; if ([line isEqualToString:@""] && lastConsoleInput) { line = lastConsoleInput; @@ -1475,7 +1480,7 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) NSUInteger columnIndex = [[tableView tableColumns] indexOfObject:tableColumn]; if (tableView == self.paletteTableView) { if (columnIndex == 0) { - return [NSString stringWithFormat:@"%s %u", row >=8 ? "Object" : "Background", (unsigned)(row & 7)]; + return [NSString stringWithFormat:@"%s %u", row >= 8 ? "Object" : "Background", (unsigned)(row & 7)]; } uint8_t *palette_data = GB_get_direct_access(&gb, row >= 8? GB_DIRECT_ACCESS_OBP : GB_DIRECT_ACCESS_BGP, NULL, NULL); @@ -1572,7 +1577,7 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) [self stop]; NSSavePanel * savePanel = [NSSavePanel savePanel]; [savePanel setAllowedFileTypes:@[@"png"]]; - [savePanel beginSheetModalForWindow:self.printerFeedWindow completionHandler:^(NSInteger result){ + [savePanel beginSheetModalForWindow:self.printerFeedWindow completionHandler:^(NSInteger result) { if (result == NSFileHandlingPanelOKButton) { [savePanel orderOut:self]; CGImageRef cgRef = [self.feedImageView.image CGImageForProposedRect:NULL @@ -1681,11 +1686,13 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) return 600; } -- (CGFloat)splitView:(GBSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMaximumPosition ofSubviewAt:(NSInteger)dividerIndex { +- (CGFloat)splitView:(GBSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMaximumPosition ofSubviewAt:(NSInteger)dividerIndex +{ return splitView.frame.size.width - 321; } -- (BOOL)splitView:(GBSplitView *)splitView shouldAdjustSizeOfSubview:(NSView *)view { +- (BOOL)splitView:(GBSplitView *)splitView shouldAdjustSizeOfSubview:(NSView *)view +{ if ([[splitView arrangedSubviews] lastObject] == view) { return NO; } diff --git a/Cocoa/GBAudioClient.m b/Cocoa/GBAudioClient.m index 81ddec4..7f2115d 100644 --- a/Cocoa/GBAudioClient.m +++ b/Cocoa/GBAudioClient.m @@ -26,8 +26,7 @@ static OSStatus render( -(id) initWithRendererBlock:(void (^)(UInt32 sampleRate, UInt32 nFrames, GB_sample_t *buffer)) block andSampleRate:(UInt32) rate { - if(!(self = [super init])) - { + if (!(self = [super init])) { return nil; } @@ -102,7 +101,8 @@ static OSStatus render( _playing = NO; } --(void) dealloc { +-(void) dealloc +{ [self stop]; AudioUnitUninitialize(audioUnit); AudioComponentInstanceDispose(audioUnit); diff --git a/Cocoa/GBGLShader.m b/Cocoa/GBGLShader.m index d57f43d..920226b 100644 --- a/Cocoa/GBGLShader.m +++ b/Cocoa/GBGLShader.m @@ -169,7 +169,7 @@ void main(void) {\n\ + (GLuint)shaderWithContents:(NSString*)contents type:(GLenum)type { - const GLchar* source = [contents UTF8String]; + const GLchar *source = [contents UTF8String]; // Create the shader object GLuint shader = glCreateShader(type); // Load the shader source diff --git a/Cocoa/GBImageView.m b/Cocoa/GBImageView.m index 47efa00..3525e72 100644 --- a/Cocoa/GBImageView.m +++ b/Cocoa/GBImageView.m @@ -93,7 +93,7 @@ - (void)updateTrackingAreas { - if(trackingArea != nil) { + if (trackingArea != nil) { [self removeTrackingArea:trackingArea]; } diff --git a/Cocoa/GBOpenGLView.m b/Cocoa/GBOpenGLView.m index 8831b62..90ebf8d 100644 --- a/Cocoa/GBOpenGLView.m +++ b/Cocoa/GBOpenGLView.m @@ -4,7 +4,8 @@ @implementation GBOpenGLView -- (void)drawRect:(NSRect)dirtyRect { +- (void)drawRect:(NSRect)dirtyRect +{ if (!self.shader) { self.shader = [[GBGLShader alloc] initWithName:[[NSUserDefaults standardUserDefaults] objectForKey:@"GBFilter"]]; } diff --git a/Cocoa/GBSplitView.m b/Cocoa/GBSplitView.m index 0fb3bc4..a56c24e 100644 --- a/Cocoa/GBSplitView.m +++ b/Cocoa/GBSplitView.m @@ -5,12 +5,14 @@ NSColor *_dividerColor; } -- (void)setDividerColor:(NSColor *)color { +- (void)setDividerColor:(NSColor *)color +{ _dividerColor = color; [self setNeedsDisplay:YES]; } -- (NSColor *)dividerColor { +- (NSColor *)dividerColor +{ if (_dividerColor) { return _dividerColor; } @@ -22,7 +24,8 @@ { if (@available(macOS 10.11, *)) { return [super arrangedSubviews]; - } else { + } + else { return [self subviews]; } } diff --git a/Cocoa/GBTerminalTextFieldCell.m b/Cocoa/GBTerminalTextFieldCell.m index 47a3a35..e95e785 100644 --- a/Cocoa/GBTerminalTextFieldCell.m +++ b/Cocoa/GBTerminalTextFieldCell.m @@ -173,7 +173,8 @@ [super setSelectedRanges:ranges affinity:affinity stillSelecting:stillSelectingFlag]; } -- (BOOL)resignFirstResponder { +- (BOOL)resignFirstResponder +{ reverse_search_mode = false; return [super resignFirstResponder]; } diff --git a/Cocoa/GBView.m b/Cocoa/GBView.m index 0e52811..6f26a03 100644 --- a/Cocoa/GBView.m +++ b/Cocoa/GBView.m @@ -114,8 +114,7 @@ } - (instancetype)initWithCoder:(NSCoder *)coder { - if (!(self = [super initWithCoder:coder])) - { + if (!(self = [super initWithCoder:coder])) { return self; } [self _init]; @@ -124,8 +123,7 @@ - (instancetype)initWithFrame:(NSRect)frameRect { - if (!(self = [super initWithFrame:frameRect])) - { + if (!(self = [super initWithFrame:frameRect])) { return self; } [self _init]; diff --git a/Cocoa/GBViewMetal.m b/Cocoa/GBViewMetal.m index 62deadc..9a1c78b 100644 --- a/Cocoa/GBViewMetal.m +++ b/Cocoa/GBViewMetal.m @@ -159,8 +159,7 @@ static const vector_float2 rect[] = MTLRenderPassDescriptor *render_pass_descriptor = view.currentRenderPassDescriptor; id command_buffer = [command_queue commandBuffer]; - if (render_pass_descriptor != nil) - { + if (render_pass_descriptor != nil) { *(GB_frame_blending_mode_t *)[frame_blending_mode_buffer contents] = [self frameBlendingMode]; *(vector_float2 *)[output_resolution_buffer contents] = output_resolution; diff --git a/Cocoa/joypad.m b/Cocoa/joypad.m index 2ffe56b..fd9fe70 100755 --- a/Cocoa/joypad.m +++ b/Cocoa/joypad.m @@ -295,7 +295,8 @@ AddHIDElements(CFArrayRef array, recDevice *pDevice) } static bool -ElementAlreadyAdded(const IOHIDElementCookie cookie, const recElement *listitem) { +ElementAlreadyAdded(const IOHIDElementCookie cookie, const recElement *listitem) +{ while (listitem) { if (listitem->cookie == cookie) { return true; @@ -431,7 +432,8 @@ AddHIDElement(const void *value, void *parameter) } if (elementPrevious) { elementPrevious->pNext = element; - } else { + } + else { *headElement = element; } @@ -519,7 +521,8 @@ GetDeviceInfo(IOHIDDeviceRef hidDevice, recDevice *pDevice) *guid16++ = 0; *guid16++ = version; *guid16++ = 0; - } else { + } + else { *guid16++ = BUS_BLUETOOTH; *guid16++ = 0; strlcpy((char*)guid16, pDevice->product, sizeof(pDevice->guid.data) - 4); @@ -582,7 +585,8 @@ SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) value = GetHIDElementState(device, element) - element->min; if (range == 4) { /* 4 position hatswitch - scale up value */ value *= 2; - } else if (range != 8) { /* Neither a 4 nor 8 positions - fall back to default position (centered) */ + } + else if (range != 8) { /* Neither a 4 nor 8 positions - fall back to default position (centered) */ value = -1; } if ((unsigned)value >= 8) { diff --git a/Cocoa/main.m b/Cocoa/main.m index 8a6799b..662469a 100644 --- a/Cocoa/main.m +++ b/Cocoa/main.m @@ -1,5 +1,6 @@ #import -int main(int argc, const char * argv[]) { +int main(int argc, const char * argv[]) +{ return NSApplicationMain(argc, argv); } diff --git a/Core/apu.c b/Core/apu.c index feda3c8..e63d89f 100644 --- a/Core/apu.c +++ b/Core/apu.c @@ -139,7 +139,7 @@ static double smooth(double x) static void render(GB_gameboy_t *gb) { - GB_sample_t output = {0,0}; + GB_sample_t output = {0, 0}; UNROLL for (unsigned i = 0; i < GB_N_CHANNELS; i++) { @@ -907,7 +907,7 @@ void GB_apu_write(GB_gameboy_t *gb, uint8_t reg, uint8_t value) gb->apu.is_active[GB_NOISE] = false; update_sample(gb, GB_NOISE, 0, 0); } - else if (gb->apu.is_active[GB_NOISE]){ + else if (gb->apu.is_active[GB_NOISE]) { nrx2_glitch(&gb->apu.noise_channel.current_volume, value, gb->io_registers[reg]); update_sample(gb, GB_NOISE, gb->apu.current_lfsr_sample ? diff --git a/Core/debugger.c b/Core/debugger.c index 94fae80..ee27e88 100644 --- a/Core/debugger.c +++ b/Core/debugger.c @@ -298,13 +298,15 @@ static void write_lvalue(GB_gameboy_t *gb, lvalue_t lvalue, uint16_t value) static value_t add(value_t a, value_t b) {return FIX_BANK(a.value + b.value);} static value_t sub(value_t a, value_t b) {return FIX_BANK(a.value - b.value);} static value_t mul(value_t a, value_t b) {return FIX_BANK(a.value * b.value);} -static value_t _div(value_t a, value_t b) { +static value_t _div(value_t a, value_t b) +{ if (b.value == 0) { return FIX_BANK(0); } return FIX_BANK(a.value / b.value); }; -static value_t mod(value_t a, value_t b) { +static value_t mod(value_t a, value_t b) +{ if (b.value == 0) { return FIX_BANK(0); } @@ -380,8 +382,7 @@ static lvalue_t debugger_evaluate_lvalue(GB_gameboy_t *gb, const char *string, while (length && (string[length-1] == ' ' || string[length-1] == '\n' || string[length-1] == '\r' || string[length-1] == '\t')) { length--; } - if (length == 0) - { + if (length == 0) { GB_log(gb, "Expected expression.\n"); *error = true; return (lvalue_t){0,}; @@ -487,8 +488,7 @@ value_t debugger_evaluate(GB_gameboy_t *gb, const char *string, while (length && (string[length-1] == ' ' || string[length-1] == '\n' || string[length-1] == '\r' || string[length-1] == '\t')) { length--; } - if (length == 0) - { + if (length == 0) { GB_log(gb, "Expected expression.\n"); *error = true; goto exit; @@ -1167,7 +1167,7 @@ static bool unwatch(GB_gameboy_t *gb, char *arguments, char *modifiers, const de memmove(&gb->watchpoints[index], &gb->watchpoints[index + 1], (gb->n_watchpoints - index - 1) * sizeof(gb->watchpoints[0])); gb->n_watchpoints--; - gb->watchpoints = realloc(gb->watchpoints, gb->n_watchpoints* sizeof(gb->watchpoints[0])); + gb->watchpoints = realloc(gb->watchpoints, gb->n_watchpoints *sizeof(gb->watchpoints[0])); GB_log(gb, "Watchpoint removed from %s\n", debugger_value_to_string(gb, result, true)); return true; @@ -1216,7 +1216,7 @@ static bool list(GB_gameboy_t *gb, char *arguments, char *modifiers, const debug gb->watchpoints[i].condition); } else { - GB_log(gb, " %d. %s (%c%c)\n", i + 1, debugger_value_to_string(gb,addr, addr.has_bank), + GB_log(gb, " %d. %s (%c%c)\n", i + 1, debugger_value_to_string(gb, addr, addr.has_bank), (gb->watchpoints[i].flags & GB_WATCHPOINT_R)? 'r' : '-', (gb->watchpoints[i].flags & GB_WATCHPOINT_W)? 'w' : '-'); } @@ -1581,7 +1581,7 @@ static bool lcd(GB_gameboy_t *gb, char *arguments, char *modifiers, const debugg } GB_log(gb, "LY: %d\n", gb->io_registers[GB_IO_LY]); GB_log(gb, "LYC: %d\n", gb->io_registers[GB_IO_LYC]); - GB_log(gb, "Window position: %d, %d\n", (signed) gb->io_registers[GB_IO_WX] - 7 , gb->io_registers[GB_IO_WY]); + GB_log(gb, "Window position: %d, %d\n", (signed) gb->io_registers[GB_IO_WX] - 7, gb->io_registers[GB_IO_WY]); GB_log(gb, "Interrupt line: %s\n", gb->stat_interrupt_line? "On" : "Off"); return true; @@ -1730,7 +1730,7 @@ static bool wave(GB_gameboy_t *gb, char *arguments, char *modifiers, const debug uint8_t shift_amount = 1, mask; if (modifiers) { - switch(modifiers[0]) { + switch (modifiers[0]) { case 'c': shift_amount = 2; break; @@ -1826,7 +1826,7 @@ static const debugger_command_t *find_command(const char *string) static void print_command_shortcut(GB_gameboy_t *gb, const debugger_command_t *command) { GB_attributed_log(gb, GB_LOG_BOLD | GB_LOG_UNDERLINE, "%.*s", command->min_length, command->command); - GB_attributed_log(gb, GB_LOG_BOLD , "%s", command->command + command->min_length); + GB_attributed_log(gb, GB_LOG_BOLD, "%s", command->command + command->min_length); } static void print_command_description(GB_gameboy_t *gb, const debugger_command_t *command) diff --git a/Core/display.c b/Core/display.c index 67a9fc4..b5c0a0a 100644 --- a/Core/display.c +++ b/Core/display.c @@ -530,7 +530,7 @@ static void render_pixel_if_possible(GB_gameboy_t *gb) *dest = gb->sprite_palettes_rgb[oam_fifo_item->palette * 4 + pixel]; } } - + if (gb->model & GB_MODEL_NO_SFC_BIT) { if (gb->icd_pixel_callback) { gb->icd_pixel_callback(gb, icd_pixel); diff --git a/Core/gb.c b/Core/gb.c index 3b834dd..f6174b9 100644 --- a/Core/gb.c +++ b/Core/gb.c @@ -119,7 +119,7 @@ static void load_default_border(GB_gameboy_t *gb) }\ }\ }\ - } while(false); + } while (false); if (gb->model == GB_MODEL_AGB) { #include "graphics/agb_border.inc" @@ -658,8 +658,8 @@ void GB_set_async_input_callback(GB_gameboy_t *gb, GB_input_callback_t callback) #endif } -const GB_palette_t GB_PALETTE_GREY = {{{0x00, 0x00, 0x00}, {0x55, 0x55, 0x55}, {0xaa, 0xaa, 0xaa}, {0xff ,0xff, 0xff}, {0xff ,0xff, 0xff}}}; -const GB_palette_t GB_PALETTE_DMG = {{{0x08, 0x18, 0x10}, {0x39, 0x61, 0x39}, {0x84, 0xa5, 0x63}, {0xc6, 0xde, 0x8c}, {0xd2 ,0xe6 ,0xa6}}}; +const GB_palette_t GB_PALETTE_GREY = {{{0x00, 0x00, 0x00}, {0x55, 0x55, 0x55}, {0xaa, 0xaa, 0xaa}, {0xff, 0xff, 0xff}, {0xff, 0xff, 0xff}}}; +const GB_palette_t GB_PALETTE_DMG = {{{0x08, 0x18, 0x10}, {0x39, 0x61, 0x39}, {0x84, 0xa5, 0x63}, {0xc6, 0xde, 0x8c}, {0xd2, 0xe6, 0xa6}}}; const GB_palette_t GB_PALETTE_MGB = {{{0x07, 0x10, 0x0e}, {0x3a, 0x4c, 0x3a}, {0x81, 0x8d, 0x66}, {0xc2, 0xce, 0x93}, {0xcf, 0xda, 0xac}}}; const GB_palette_t GB_PALETTE_GBL = {{{0x0a, 0x1c, 0x15}, {0x35, 0x78, 0x62}, {0x56, 0xb4, 0x95}, {0x7f, 0xe2, 0xc3}, {0x91, 0xea, 0xd0}}}; diff --git a/Core/gb.h b/Core/gb.h index 03abfa1..01b79e8 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -53,7 +53,7 @@ typedef struct { struct { - uint8_t r,g,b; + uint8_t r, g, b; } colors[5]; } GB_palette_t; @@ -254,11 +254,11 @@ typedef enum { #define INTERNAL_DIV_CYCLES (0x40000) #if !defined(MIN) -#define MIN(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; }) +#define MIN(A, B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; }) #endif #if !defined(MAX) -#define MAX(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; }) +#define MAX(A, B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; }) #endif #endif diff --git a/Core/memory.c b/Core/memory.c index 58b96bb..ca9c179 100644 --- a/Core/memory.c +++ b/Core/memory.c @@ -277,7 +277,7 @@ static uint8_t read_high_memory(GB_gameboy_t *gb, uint16_t addr) case GB_MODEL_SGB_PAL_NO_SFC: case GB_MODEL_SGB2: case GB_MODEL_SGB2_NO_SFC: - ; + break; } } diff --git a/Core/save_state.c b/Core/save_state.c index a53ccba..11024df 100644 --- a/Core/save_state.c +++ b/Core/save_state.c @@ -361,7 +361,7 @@ int GB_load_state_from_buffer(GB_gameboy_t *gb, const uint8_t *buffer, size_t le return -1; } - if (buffer_read(gb->vram,gb->vram_size, &buffer, &length) != gb->vram_size) { + if (buffer_read(gb->vram, gb->vram_size, &buffer, &length) != gb->vram_size) { return -1; } diff --git a/Core/sgb.c b/Core/sgb.c index 271b681..c77b0db 100644 --- a/Core/sgb.c +++ b/Core/sgb.c @@ -151,7 +151,7 @@ static void command_ready(GB_gameboy_t *gb) 0xE content bytes. The last command, FB, is padded with zeros, so information past the header is not sent. */ if ((gb->sgb->command[0] & 0xF1) == 0xF1) { - if(gb->boot_rom_finished) return; + if (gb->boot_rom_finished) return; uint8_t checksum = 0; for (unsigned i = 2; i < 0x10; i++) { @@ -247,7 +247,7 @@ static void command_ready(GB_gameboy_t *gb) gb->sgb->attribute_map[x + 20 * y] = inside_palette; } } - else if(middle) { + else if (middle) { gb->sgb->attribute_map[x + 20 * y] = middle_palette; } } diff --git a/Core/sm83_cpu.c b/Core/sm83_cpu.c index 2b7b1dd..13f05df 100644 --- a/Core/sm83_cpu.c +++ b/Core/sm83_cpu.c @@ -452,7 +452,7 @@ static void ld_da16_sp(GB_gameboy_t *gb, uint8_t opcode) addr = cycle_read_inc_oam_bug(gb, gb->pc++); addr |= cycle_read_inc_oam_bug(gb, gb->pc++) << 8; cycle_write(gb, addr, gb->registers[GB_REGISTER_SP] & 0xFF); - cycle_write(gb, addr+1, gb->registers[GB_REGISTER_SP] >> 8); + cycle_write(gb, addr + 1, gb->registers[GB_REGISTER_SP] >> 8); } static void add_hl_rr(GB_gameboy_t *gb, uint8_t opcode) @@ -1222,7 +1222,7 @@ static void ld_a_da16(GB_gameboy_t *gb, uint8_t opcode) uint16_t addr; gb->registers[GB_REGISTER_AF] &= 0xFF; addr = cycle_read_inc_oam_bug(gb, gb->pc++); - addr |= cycle_read_inc_oam_bug(gb, gb->pc++) << 8 ; + addr |= cycle_read_inc_oam_bug(gb, gb->pc++) << 8; gb->registers[GB_REGISTER_AF] |= cycle_read(gb, addr) << 8; } @@ -1410,10 +1410,10 @@ static void bit_r(GB_gameboy_t *gb, uint8_t opcode) } } else if ((opcode & 0xC0) == 0x80) { /* res */ - set_src_value(gb, opcode, value & ~bit) ; + set_src_value(gb, opcode, value & ~bit); } else if ((opcode & 0xC0) == 0xC0) { /* set */ - set_src_value(gb, opcode, value | bit) ; + set_src_value(gb, opcode, value | bit); } } @@ -1567,7 +1567,7 @@ void GB_cpu_run(GB_gameboy_t *gb) GB_debugger_call_hook(gb, call_addr); } /* Run mode */ - else if(!gb->halted) { + else if (!gb->halted) { gb->last_opcode_read = cycle_read_inc_oam_bug(gb, gb->pc++); if (gb->halt_bug) { gb->pc--; diff --git a/Core/sm83_disassembler.c b/Core/sm83_disassembler.c index 96aec00..7dacd9e 100644 --- a/Core/sm83_disassembler.c +++ b/Core/sm83_disassembler.c @@ -97,7 +97,8 @@ static void rla(GB_gameboy_t *gb, uint8_t opcode, uint16_t *pc) GB_log(gb, "RLA\n"); } -static void ld_da16_sp(GB_gameboy_t *gb, uint8_t opcode, uint16_t *pc){ +static void ld_da16_sp(GB_gameboy_t *gb, uint8_t opcode, uint16_t *pc) +{ uint16_t addr; (*pc)++; addr = GB_read_memory(gb, (*pc)++); diff --git a/Core/timing.c b/Core/timing.c index 1f3f654..9eb9c91 100644 --- a/Core/timing.c +++ b/Core/timing.c @@ -274,19 +274,14 @@ void GB_rtc_run(GB_gameboy_t *gb) time_t current_time = time(NULL); while (gb->last_rtc_second < current_time) { gb->last_rtc_second++; - if (++gb->rtc_real.seconds == 60) - { + if (++gb->rtc_real.seconds == 60) { gb->rtc_real.seconds = 0; - if (++gb->rtc_real.minutes == 60) - { + if (++gb->rtc_real.minutes == 60) { gb->rtc_real.minutes = 0; - if (++gb->rtc_real.hours == 24) - { + if (++gb->rtc_real.hours == 24) { gb->rtc_real.hours = 0; - if (++gb->rtc_real.days == 0) - { - if (gb->rtc_real.high & 1) /* Bit 8 of days*/ - { + if (++gb->rtc_real.days == 0) { + if (gb->rtc_real.high & 1) { /* Bit 8 of days*/ gb->rtc_real.high |= 0x80; /* Overflow bit */ } gb->rtc_real.high ^= 1; diff --git a/OpenDialog/gtk.c b/OpenDialog/gtk.c index 7947ea2..d9163fc 100644 --- a/OpenDialog/gtk.c +++ b/OpenDialog/gtk.c @@ -88,8 +88,7 @@ char *do_open_rom_dialog(void) int res = gtk_dialog_run (dialog); char *ret = NULL; - if (res == GTK_RESPONSE_ACCEPT) - { + if (res == GTK_RESPONSE_ACCEPT) { char *filename; filename = gtk_file_chooser_get_filename(dialog); ret = strdup(filename); diff --git a/OpenDialog/windows.c b/OpenDialog/windows.c index 75fe767..6bf9b89 100644 --- a/OpenDialog/windows.c +++ b/OpenDialog/windows.c @@ -17,8 +17,7 @@ char *do_open_rom_dialog(void) dialog.lpstrInitialDir = NULL; dialog.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; - if (GetOpenFileNameW(&dialog) == TRUE) - { + if (GetOpenFileNameW(&dialog) == TRUE) { char *ret = malloc(MAX_PATH * 4); WideCharToMultiByte(CP_UTF8, 0, filename, sizeof(filename), ret, MAX_PATH * 4, NULL, NULL); return ret; diff --git a/QuickLook/generator.m b/QuickLook/generator.m index 1aa0087..c3c13dc 100644 --- a/QuickLook/generator.m +++ b/QuickLook/generator.m @@ -79,7 +79,7 @@ static OSStatus render(CGContextRef cgContext, CFURLRef url, bool showBorder) } /* Mask it with the template (The middle part of the template image is transparent) */ - [effectiveTemplate drawInRect:(NSRect){{0,0},template.size}]; + [effectiveTemplate drawInRect:(NSRect){{0, 0}, template.size}]; } CGColorSpaceRelease(colorSpaceRef); diff --git a/QuickLook/main.c b/QuickLook/main.c index 8566e32..1d1676a 100644 --- a/QuickLook/main.c +++ b/QuickLook/main.c @@ -43,8 +43,8 @@ typedef struct __QuickLookGeneratorPluginType QuickLookGeneratorPluginType *AllocQuickLookGeneratorPluginType(CFUUIDRef inFactoryID); void DeallocQuickLookGeneratorPluginType(QuickLookGeneratorPluginType *thisInstance); -HRESULT QuickLookGeneratorQueryInterface(void *thisInstance,REFIID iid,LPVOID *ppv); -void *QuickLookGeneratorPluginFactory(CFAllocatorRef allocator,CFUUIDRef typeID); +HRESULT QuickLookGeneratorQueryInterface(void *thisInstance, REFIID iid, LPVOID *ppv); +void *QuickLookGeneratorPluginFactory(CFAllocatorRef allocator, CFUUIDRef typeID); ULONG QuickLookGeneratorPluginAddRef(void *thisInstance); ULONG QuickLookGeneratorPluginRelease(void *thisInstance); @@ -77,11 +77,11 @@ QuickLookGeneratorPluginType *AllocQuickLookGeneratorPluginType(CFUUIDRef inFact QuickLookGeneratorPluginType *theNewInstance; theNewInstance = (QuickLookGeneratorPluginType *)malloc(sizeof(QuickLookGeneratorPluginType)); - memset(theNewInstance,0,sizeof(QuickLookGeneratorPluginType)); + memset(theNewInstance, 0, sizeof(QuickLookGeneratorPluginType)); /* Point to the function table Malloc enough to store the stuff and copy the filler from myInterfaceFtbl over */ theNewInstance->conduitInterface = malloc(sizeof(QLGeneratorInterfaceStruct)); - memcpy(theNewInstance->conduitInterface,&myInterfaceFtbl,sizeof(QLGeneratorInterfaceStruct)); + memcpy(theNewInstance->conduitInterface,&myInterfaceFtbl, sizeof(QLGeneratorInterfaceStruct)); /* Retain and keep an open instance refcount for each factory. */ theNewInstance->factoryID = CFRetain(inFactoryID); @@ -110,7 +110,7 @@ void DeallocQuickLookGeneratorPluginType(QuickLookGeneratorPluginType *thisInsta /* Free the instance structure */ free(thisInstance); - if (theFactoryID){ + if (theFactoryID) { CFPlugInRemoveInstanceForFactory(theFactoryID); CFRelease(theFactoryID); } @@ -121,13 +121,13 @@ void DeallocQuickLookGeneratorPluginType(QuickLookGeneratorPluginType *thisInsta // ----------------------------------------------------------------------------- // Implementation of the IUnknown QueryInterface function. // -HRESULT QuickLookGeneratorQueryInterface(void *thisInstance,REFIID iid,LPVOID *ppv) +HRESULT QuickLookGeneratorQueryInterface(void *thisInstance, REFIID iid, LPVOID *ppv) { CFUUIDRef interfaceID; - interfaceID = CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault,iid); + interfaceID = CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault, iid); - if (CFEqual(interfaceID,kQLGeneratorCallbacksInterfaceID)){ + if (CFEqual(interfaceID, kQLGeneratorCallbacksInterfaceID)) { /* If the Right interface was requested, bump the ref count, * set the ppv parameter equal to the instance, and * return good status. @@ -138,7 +138,8 @@ HRESULT QuickLookGeneratorQueryInterface(void *thisInstance,REFIID iid,LPVOID *p *ppv = thisInstance; CFRelease(interfaceID); return S_OK; - }else{ + } + else { /* Requested interface unknown, bail with error. */ *ppv = NULL; CFRelease(interfaceID); @@ -168,10 +169,11 @@ ULONG QuickLookGeneratorPluginAddRef(void *thisInstance) ULONG QuickLookGeneratorPluginRelease(void *thisInstance) { ((QuickLookGeneratorPluginType*)thisInstance)->refCount -= 1; - if (((QuickLookGeneratorPluginType*)thisInstance)->refCount == 0){ + if (((QuickLookGeneratorPluginType*)thisInstance)->refCount == 0) { DeallocQuickLookGeneratorPluginType((QuickLookGeneratorPluginType*)thisInstance ); return 0; - }else{ + } + else { return ((QuickLookGeneratorPluginType*) thisInstance )->refCount; } } @@ -179,7 +181,7 @@ ULONG QuickLookGeneratorPluginRelease(void *thisInstance) // ----------------------------------------------------------------------------- // QuickLookGeneratorPluginFactory // ----------------------------------------------------------------------------- -void *QuickLookGeneratorPluginFactory(CFAllocatorRef allocator,CFUUIDRef typeID) +void *QuickLookGeneratorPluginFactory(CFAllocatorRef allocator, CFUUIDRef typeID) { QuickLookGeneratorPluginType *result; CFUUIDRef uuid; @@ -187,8 +189,8 @@ void *QuickLookGeneratorPluginFactory(CFAllocatorRef allocator,CFUUIDRef typeID) /* If correct type is being requested, allocate an * instance of kQLGeneratorTypeID and return the IUnknown interface. */ - if (CFEqual(typeID,kQLGeneratorTypeID)){ - uuid = CFUUIDCreateFromString(kCFAllocatorDefault,CFSTR(PLUGIN_ID)); + if (CFEqual(typeID, kQLGeneratorTypeID)) { + uuid = CFUUIDCreateFromString(kCFAllocatorDefault, CFSTR(PLUGIN_ID)); result = AllocQuickLookGeneratorPluginType(uuid); CFRelease(uuid); return result; diff --git a/SDL/gui.c b/SDL/gui.c index 201452a..5650d9b 100644 --- a/SDL/gui.c +++ b/SDL/gui.c @@ -338,7 +338,7 @@ static void cycle_model_backwards(unsigned index) const char *current_model_string(unsigned index) { - return (const char *[]){"Game Boy", "Game Boy Color", "Game Boy Advance" , "Super Game Boy"} + return (const char *[]){"Game Boy", "Game Boy Color", "Game Boy Advance", "Super Game Boy"} [configuration.model]; } @@ -800,7 +800,7 @@ static void cycle_joypads(unsigned index) SDL_JoystickClose(joystick); joystick = NULL; } - if ((controller = SDL_GameControllerOpen(joypad_index))){ + if ((controller = SDL_GameControllerOpen(joypad_index))) { joystick = SDL_GameControllerGetJoystick(controller); } else { @@ -822,7 +822,7 @@ static void cycle_joypads_backwards(unsigned index) SDL_JoystickClose(joystick); joystick = NULL; } - if ((controller = SDL_GameControllerOpen(joypad_index))){ + if ((controller = SDL_GameControllerOpen(joypad_index))) { joystick = SDL_GameControllerGetJoystick(controller); } else { @@ -886,7 +886,7 @@ void connect_joypad(void) } } else if (!joystick && SDL_NumJoysticks()) { - if ((controller = SDL_GameControllerOpen(0))){ + if ((controller = SDL_GameControllerOpen(0))) { joystick = SDL_GameControllerGetJoystick(controller); } else { diff --git a/SDL/main.c b/SDL/main.c index 4b6afea..4ce2e59 100644 --- a/SDL/main.c +++ b/SDL/main.c @@ -149,8 +149,7 @@ static void open_menu(void) static void handle_events(GB_gameboy_t *gb) { SDL_Event event; - while (SDL_PollEvent(&event)) - { + while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: pending_command = GB_SDL_QUIT_COMMAND; @@ -603,7 +602,7 @@ static bool get_arg_flag(const char *flag, int *argc, char **argv) int main(int argc, char **argv) { #ifdef _WIN32 - SetProcessDPIAware(); + SetProcessDPIAware(); #endif #define str(x) #x #define xstr(x) str(x) diff --git a/SDL/opengl_compat.h b/SDL/opengl_compat.h index 15b2a17..4b79b0c 100644 --- a/SDL/opengl_compat.h +++ b/SDL/opengl_compat.h @@ -10,7 +10,7 @@ #define GL_COMPAT_WRAPPER(func) \ ({ extern typeof(func) *GL_COMPAT_NAME(func); \ -if(!GL_COMPAT_NAME(func)) GL_COMPAT_NAME(func) = SDL_GL_GetProcAddress(#func); \ +if (!GL_COMPAT_NAME(func)) GL_COMPAT_NAME(func) = SDL_GL_GetProcAddress(#func); \ GL_COMPAT_NAME(func); \ }) diff --git a/Tester/main.c b/Tester/main.c index e3b662c..27250a6 100755 --- a/Tester/main.c +++ b/Tester/main.c @@ -300,7 +300,7 @@ int main(int argc, char **argv) if (max_forks > 1) { while (current_forks >= max_forks) { int wait_out; - while(wait(&wait_out) == -1); + while (wait(&wait_out) == -1); current_forks--; } @@ -433,7 +433,7 @@ int main(int argc, char **argv) } #ifndef _WIN32 int wait_out; - while(wait(&wait_out) != -1); + while (wait(&wait_out) != -1); #endif return 0; } diff --git a/Windows/stdio.h b/Windows/stdio.h index 0595b01..ef21ea4 100755 --- a/Windows/stdio.h +++ b/Windows/stdio.h @@ -24,7 +24,8 @@ static inline int vasprintf(char **str, const char *fmt, va_list args) #endif /* This code is public domain -- Will Hartung 4/9/09 */ -static inline size_t getline(char **lineptr, size_t *n, FILE *stream) { +static inline size_t getline(char **lineptr, size_t *n, FILE *stream) +{ char *bufptr = NULL; char *p = bufptr; size_t size; diff --git a/libretro/libretro.c b/libretro/libretro.c index 8cd1324..2cb3ef7 100644 --- a/libretro/libretro.c +++ b/libretro/libretro.c @@ -195,7 +195,7 @@ static bool serial_end2(GB_gameboy_t *gb) static uint32_t rgb_encode(GB_gameboy_t *gb, uint8_t r, uint8_t g, uint8_t b) { - return r<<16|g<<8|b; + return r <<16 | g <<8 | b; } static retro_environment_t environ_cb; @@ -323,15 +323,13 @@ static struct retro_input_descriptor descriptors_4p[] = { static void set_link_cable_state(bool state) { - if (state && emulated_devices == 2) - { + if (state && emulated_devices == 2) { GB_set_serial_transfer_bit_start_callback(&gameboy[0], serial_start1); GB_set_serial_transfer_bit_end_callback(&gameboy[0], serial_end1); GB_set_serial_transfer_bit_start_callback(&gameboy[1], serial_start2); GB_set_serial_transfer_bit_end_callback(&gameboy[1], serial_end2); } - else if (!state) - { + else if (!state) { GB_set_serial_transfer_bit_start_callback(&gameboy[0], NULL); GB_set_serial_transfer_bit_end_callback(&gameboy[0], NULL); GB_set_serial_transfer_bit_start_callback(&gameboy[1], NULL); @@ -375,8 +373,7 @@ static void init_for_current_model(unsigned id) /* todo: attempt to make these more generic */ GB_set_vblank_callback(&gameboy[0], (GB_vblank_callback_t) vblank1); - if (emulated_devices == 2) - { + if (emulated_devices == 2) { GB_set_vblank_callback(&gameboy[1], (GB_vblank_callback_t) vblank2); if (link_cable_emulation) set_link_cable_state(true); @@ -428,17 +425,17 @@ static void init_for_current_model(unsigned id) descs[8].ptr = GB_get_direct_access(&gameboy[i], GB_DIRECT_ACCESS_OAM, &size, &bank); descs[8].start = 0xFE00; descs[8].len = 0x00A0; - descs[8].select= 0xFFFFFF00; + descs[8].select = 0xFFFFFF00; descs[9].ptr = descs[2].ptr + 0x2000; /* GBC RAM bank 2 */ descs[9].start = 0x10000; descs[9].len = GB_is_cgb(&gameboy[i]) ? 0x6000 : 0; /* 0x1000 per bank (2-7), unmapped on GB */ - descs[9].select= 0xFFFF0000; + descs[9].select = 0xFFFF0000; descs[10].ptr = GB_get_direct_access(&gameboy[i], GB_DIRECT_ACCESS_IO, &size, &bank); descs[10].start = 0xFF00; descs[10].len = 0x0080; - descs[10].select= 0xFFFFFF00; + descs[10].select = 0xFFFFFF00; struct retro_memory_map mmaps; mmaps.descriptors = descs; @@ -446,8 +443,7 @@ static void init_for_current_model(unsigned id) environ_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &mmaps); /* Let's be extremely nitpicky about how devices and descriptors are set */ - if (emulated_devices == 1 && (model[0] == MODEL_SGB || model[0] == MODEL_SGB2)) - { + if (emulated_devices == 1 && (model[0] == MODEL_SGB || model[0] == MODEL_SGB2)) { static const struct retro_controller_info ports[] = { { controllers_sgb, 1 }, { controllers_sgb, 1 }, @@ -458,8 +454,7 @@ static void init_for_current_model(unsigned id) environ_cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void*)ports); environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, descriptors_4p); } - else if (emulated_devices == 1) - { + else if (emulated_devices == 1) { static const struct retro_controller_info ports[] = { { controllers, 1 }, { NULL, 0 }, @@ -467,8 +462,7 @@ static void init_for_current_model(unsigned id) environ_cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void*)ports); environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, descriptors_1p); } - else - { + else { static const struct retro_controller_info ports[] = { { controllers, 1 }, { controllers, 1 }, @@ -483,12 +477,10 @@ static void init_for_current_model(unsigned id) static void check_variables() { struct retro_variable var = {0}; - if (emulated_devices == 1) - { + if (emulated_devices == 1) { var.key = "sameboy_color_correction_mode"; var.value = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (strcmp(var.value, "off") == 0) GB_set_color_correction_mode(&gameboy[0], GB_COLOR_CORRECTION_DISABLED); else if (strcmp(var.value, "correct curves") == 0) @@ -503,8 +495,7 @@ static void check_variables() var.key = "sameboy_high_pass_filter_mode"; var.value = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (strcmp(var.value, "off") == 0) GB_set_highpass_filter_mode(&gameboy[0], GB_HIGHPASS_OFF); else if (strcmp(var.value, "accurate") == 0) @@ -515,8 +506,7 @@ static void check_variables() var.key = "sameboy_model"; var.value = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { enum model new_model = model[0]; if (strcmp(var.value, "Game Boy") == 0) new_model = MODEL_DMG; @@ -531,8 +521,7 @@ static void check_variables() else new_model = MODEL_AUTO; - if (new_model != model[0]) - { + if (new_model != model[0]) { geometry_updated = true; model[0] = new_model; init_for_current_model(0); @@ -541,20 +530,17 @@ static void check_variables() var.key = "sameboy_border"; var.value = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (strcmp(var.value, "enabled") == 0) sgb_border = 1; else if (strcmp(var.value, "disabled") == 0) sgb_border = 0; } } - else - { + else { var.key = "sameboy_color_correction_mode_1"; var.value = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (strcmp(var.value, "off") == 0) GB_set_color_correction_mode(&gameboy[0], GB_COLOR_CORRECTION_DISABLED); else if (strcmp(var.value, "correct curves") == 0) @@ -569,8 +555,7 @@ static void check_variables() var.key = "sameboy_color_correction_mode_2"; var.value = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (strcmp(var.value, "off") == 0) GB_set_color_correction_mode(&gameboy[1], GB_COLOR_CORRECTION_DISABLED); else if (strcmp(var.value, "correct curves") == 0) @@ -586,8 +571,7 @@ static void check_variables() var.key = "sameboy_high_pass_filter_mode_1"; var.value = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (strcmp(var.value, "off") == 0) GB_set_highpass_filter_mode(&gameboy[0], GB_HIGHPASS_OFF); else if (strcmp(var.value, "accurate") == 0) @@ -598,8 +582,7 @@ static void check_variables() var.key = "sameboy_high_pass_filter_mode_2"; var.value = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (strcmp(var.value, "off") == 0) GB_set_highpass_filter_mode(&gameboy[1], GB_HIGHPASS_OFF); else if (strcmp(var.value, "accurate") == 0) @@ -610,8 +593,7 @@ static void check_variables() var.key = "sameboy_model_1"; var.value = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { enum model new_model = model[0]; if (strcmp(var.value, "Game Boy") == 0) new_model = MODEL_DMG; @@ -626,8 +608,7 @@ static void check_variables() else new_model = MODEL_AUTO; - if (model[0] != new_model) - { + if (model[0] != new_model) { model[0] = new_model; init_for_current_model(0); } @@ -635,8 +616,7 @@ static void check_variables() var.key = "sameboy_model_2"; var.value = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { enum model new_model = model[1]; if (strcmp(var.value, "Game Boy") == 0) new_model = MODEL_DMG; @@ -651,8 +631,7 @@ static void check_variables() else new_model = MODEL_AUTO; - if (model[1] != new_model) - { + if (model[1] != new_model) { model[1] = new_model; init_for_current_model(1); } @@ -660,8 +639,7 @@ static void check_variables() var.key = "sameboy_screen_layout"; var.value = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (strcmp(var.value, "top-down") == 0) screen_layout = LAYOUT_TOP_DOWN; else @@ -672,8 +650,7 @@ static void check_variables() var.key = "sameboy_link"; var.value = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { bool tmp = link_cable_emulation; if (strcmp(var.value, "enabled") == 0) link_cable_emulation = true; @@ -687,8 +664,7 @@ static void check_variables() var.key = "sameboy_audio_output"; var.value = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (strcmp(var.value, "Game Boy #1") == 0) audio_out = GB_1; else @@ -753,28 +729,25 @@ void retro_get_system_av_info(struct retro_system_av_info *info) struct retro_game_geometry geom; struct retro_system_timing timing = { GB_get_usual_frame_rate(&gameboy[0]), AUDIO_FREQUENCY }; - if (emulated_devices == 2) - { + if (emulated_devices == 2) { if (screen_layout == LAYOUT_TOP_DOWN) { geom.base_width = VIDEO_WIDTH; geom.base_height = VIDEO_HEIGHT * emulated_devices; geom.aspect_ratio = (double)VIDEO_WIDTH / (emulated_devices * VIDEO_HEIGHT); - }else if (screen_layout == LAYOUT_LEFT_RIGHT) { + } + else if (screen_layout == LAYOUT_LEFT_RIGHT) { geom.base_width = VIDEO_WIDTH * emulated_devices; geom.base_height = VIDEO_HEIGHT; geom.aspect_ratio = ((double)VIDEO_WIDTH * emulated_devices) / VIDEO_HEIGHT; } } - else - { - if (model[0] == MODEL_SGB || model[0] == MODEL_SGB2) - { + else { + if (model[0] == MODEL_SGB || model[0] == MODEL_SGB2) { geom.base_width = SGB_VIDEO_WIDTH; geom.base_height = SGB_VIDEO_HEIGHT; geom.aspect_ratio = (double)SGB_VIDEO_WIDTH / SGB_VIDEO_HEIGHT; } - else - { + else { geom.base_width = VIDEO_WIDTH; geom.base_height = VIDEO_HEIGHT; geom.aspect_ratio = (double)VIDEO_WIDTH / VIDEO_HEIGHT; @@ -848,13 +821,11 @@ void retro_run(void) if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated) check_variables(); - if (emulated_devices == 2) - { + if (emulated_devices == 2) { GB_update_keys_status(&gameboy[0], 0); GB_update_keys_status(&gameboy[1], 1); } - else if (emulated_devices == 1 && (model[0] == MODEL_SGB || model[0] == MODEL_SGB2)) - { + else if (emulated_devices == 1 && (model[0] == MODEL_SGB || model[0] == MODEL_SGB2)) { for (unsigned i = 0; i < 4; i++) GB_update_keys_status(&gameboy[0], i); } @@ -863,8 +834,7 @@ void retro_run(void) vblank1_occurred = vblank2_occurred = false; signed delta = 0; - if (emulated_devices == 2) - { + if (emulated_devices == 2) { while (!vblank1_occurred || !vblank2_occurred) { if (delta >= 0) { delta -= GB_run(&gameboy[0]); @@ -874,16 +844,15 @@ void retro_run(void) } } } - else - { + else { GB_run_frame(&gameboy[0]); } - if (emulated_devices == 2) - { + if (emulated_devices == 2) { if (screen_layout == LAYOUT_TOP_DOWN) { video_cb(frame_buf, VIDEO_WIDTH, VIDEO_HEIGHT * emulated_devices, VIDEO_WIDTH * sizeof(uint32_t)); - }else if (screen_layout == LAYOUT_LEFT_RIGHT) { + } + else if (screen_layout == LAYOUT_LEFT_RIGHT) { /* use slow memcpy method for now */ for (int index = 0; index < emulated_devices; index++) { for (int y = 0; y < VIDEO_HEIGHT; y++) { @@ -896,8 +865,7 @@ void retro_run(void) video_cb(frame_buf_copy, VIDEO_WIDTH * emulated_devices, VIDEO_HEIGHT, VIDEO_WIDTH * emulated_devices * sizeof(uint32_t)); } } - else - { + else { if (model[0] == MODEL_SGB || model[0] == MODEL_SGB2) { if (sgb_border == 1) video_cb(frame_buf, SGB_VIDEO_WIDTH, SGB_VIDEO_HEIGHT, SGB_VIDEO_WIDTH * sizeof(uint32_t)); @@ -920,12 +888,11 @@ bool retro_load_game(const struct retro_game_info *info) environ_cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void *)vars_single); check_variables(); - frame_buf = (uint32_t*)malloc(SGB_VIDEO_PIXELS* emulated_devices * sizeof(uint32_t)); + frame_buf = (uint32_t*)malloc(SGB_VIDEO_PIXELS *emulated_devices * sizeof(uint32_t)); memset(frame_buf, 0, SGB_VIDEO_PIXELS * emulated_devices * sizeof(uint32_t)); enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_XRGB8888; - if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) - { + if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) { log_cb(RETRO_LOG_INFO, "XRGB8888 is not supported\n"); return false; } @@ -933,11 +900,9 @@ bool retro_load_game(const struct retro_game_info *info) auto_model = (info->path[strlen(info->path) - 1] & ~0x20) == 'C' ? MODEL_CGB : MODEL_DMG; snprintf(retro_game_path, sizeof(retro_game_path), "%s", info->path); - for (int i = 0; i < emulated_devices; i++) - { + for (int i = 0; i < emulated_devices; i++) { init_for_current_model(i); - if (GB_load_rom(&gameboy[i],info->path)) - { + if (GB_load_rom(&gameboy[i], info->path)) { log_cb(RETRO_LOG_INFO, "Failed to load ROM at %s\n", info->path); return false; } @@ -984,8 +949,7 @@ bool retro_load_game_special(unsigned type, const struct retro_game_info *info, memset(frame_buf_copy, 0, emulated_devices * SGB_VIDEO_PIXELS * sizeof(uint32_t)); enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_XRGB8888; - if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) - { + if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) { log_cb(RETRO_LOG_INFO, "XRGB8888 is not supported\n"); return false; } @@ -993,11 +957,9 @@ bool retro_load_game_special(unsigned type, const struct retro_game_info *info, auto_model = (info->path[strlen(info->path) - 1] & ~0x20) == 'C' ? MODEL_CGB : MODEL_DMG; snprintf(retro_game_path, sizeof(retro_game_path), "%s", info->path); - for (int i = 0; i < emulated_devices; i++) - { + for (int i = 0; i < emulated_devices; i++) { init_for_current_model(i); - if (GB_load_rom(&gameboy[i], info[i].path)) - { + if (GB_load_rom(&gameboy[i], info[i].path)) { log_cb(RETRO_LOG_INFO, "Failed to load ROM\n"); return false; } @@ -1063,8 +1025,7 @@ bool retro_serialize(void *data, size_t size) bool retro_unserialize(const void *data, size_t size) { - for (int i = 0; i < emulated_devices; i++) - { + for (int i = 0; i < emulated_devices; i++) { size_t state_size = GB_get_save_state_size(&gameboy[i]); if (state_size > size) { return false; @@ -1085,10 +1046,8 @@ bool retro_unserialize(const void *data, size_t size) void *retro_get_memory_data(unsigned type) { void *data = NULL; - if (emulated_devices == 1) - { - switch(type) - { + if (emulated_devices == 1) { + switch (type) { case RETRO_MEMORY_SYSTEM_RAM: data = gameboy[0].ram; break; @@ -1102,7 +1061,7 @@ void *retro_get_memory_data(unsigned type) data = gameboy[0].vram; break; case RETRO_MEMORY_RTC: - if(gameboy[0].cartridge_type->has_battery) + if (gameboy[0].cartridge_type->has_battery) data = GB_GET_SECTION(&gameboy[0], rtc); else data = NULL; @@ -1111,10 +1070,8 @@ void *retro_get_memory_data(unsigned type) break; } } - else - { - switch (type) - { + else { + switch (type) { case RETRO_MEMORY_GAMEBOY_1_SRAM: if (gameboy[0].cartridge_type->has_battery && gameboy[0].mbc_ram_size != 0) data = gameboy[0].mbc_ram; @@ -1128,13 +1085,13 @@ void *retro_get_memory_data(unsigned type) data = NULL; break; case RETRO_MEMORY_GAMEBOY_1_RTC: - if(gameboy[0].cartridge_type->has_battery) + if (gameboy[0].cartridge_type->has_battery) data = GB_GET_SECTION(&gameboy[0], rtc); else data = NULL; break; case RETRO_MEMORY_GAMEBOY_2_RTC: - if(gameboy[1].cartridge_type->has_battery) + if (gameboy[1].cartridge_type->has_battery) data = GB_GET_SECTION(&gameboy[1], rtc); else data = NULL; @@ -1150,10 +1107,8 @@ void *retro_get_memory_data(unsigned type) size_t retro_get_memory_size(unsigned type) { size_t size = 0; - if (emulated_devices == 1) - { - switch(type) - { + if (emulated_devices == 1) { + switch (type) { case RETRO_MEMORY_SYSTEM_RAM: size = gameboy[0].ram_size; break; @@ -1167,7 +1122,7 @@ size_t retro_get_memory_size(unsigned type) size = gameboy[0].vram_size; break; case RETRO_MEMORY_RTC: - if(gameboy[0].cartridge_type->has_battery) + if (gameboy[0].cartridge_type->has_battery) size = GB_SECTION_SIZE(rtc); else size = 0; @@ -1176,10 +1131,8 @@ size_t retro_get_memory_size(unsigned type) break; } } - else - { - switch (type) - { + else { + switch (type) { case RETRO_MEMORY_GAMEBOY_1_SRAM: if (gameboy[0].cartridge_type->has_battery && gameboy[0].mbc_ram_size != 0) size = gameboy[0].mbc_ram_size; @@ -1193,11 +1146,11 @@ size_t retro_get_memory_size(unsigned type) size = 0; break; case RETRO_MEMORY_GAMEBOY_1_RTC: - if(gameboy[0].cartridge_type->has_battery) + if (gameboy[0].cartridge_type->has_battery) size = GB_SECTION_SIZE(rtc); break; case RETRO_MEMORY_GAMEBOY_2_RTC: - if(gameboy[1].cartridge_type->has_battery) + if (gameboy[1].cartridge_type->has_battery) size = GB_SECTION_SIZE(rtc); break; default: