Fixing inconsistent style

This commit is contained in:
Lior Halphon 2020-04-24 20:37:57 +03:00
parent d38fd41b0e
commit 0cf168f32b
33 changed files with 197 additions and 223 deletions

View File

@ -97,7 +97,8 @@ LoadTileset:
* @param blocklength size of an independent input block in bytes * @param blocklength size of an independent input block in bytes
* @return 0 for reaching infp end of file, or EOF for error * @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 blocklength >>= 3; // convert bytes to blocks
assert(blocklength > 0); assert(blocklength > 0);
while (1) { while (1) {
@ -113,7 +114,8 @@ int pb8(FILE *infp, FILE *outfp, size_t blocklength) {
control_byte <<= 1; control_byte <<= 1;
if (c == last_byte) { if (c == last_byte) {
control_byte |= 0x01; control_byte |= 0x01;
} else { }
else {
literals[nliterals++] = last_byte = c; literals[nliterals++] = last_byte = c;
} }
} }
@ -143,7 +145,8 @@ int pb8(FILE *infp, FILE *outfp, size_t blocklength) {
* @param outfp output stream * @param outfp output stream
* @return 0 for reaching infp end of file, or EOF for error * @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; int last_byte = 0;
while (1) { while (1) {
int control_byte = fgetc(infp); int control_byte = fgetc(infp);
@ -165,7 +168,8 @@ int unpb8(FILE *infp, FILE *outfp) {
/* CLI frontend ****************************************************/ /* CLI frontend ****************************************************/
static inline void set_fd_binary(unsigned int fd) { static inline void set_fd_binary(unsigned int fd)
{
#ifdef _WIN32 #ifdef _WIN32
_setmode(fd, _O_BINARY); _setmode(fd, _O_BINARY);
#else #else
@ -197,7 +201,8 @@ static const char *version_msg =
static const char *toomanyfilenames_msg = static const char *toomanyfilenames_msg =
"pb8: too many filenames; try pb8 --help\n"; "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 *infilename = NULL;
const char *outfilename = NULL; const char *outfilename = NULL;
bool decompress = false; bool decompress = false;
@ -248,11 +253,14 @@ int main(int argc, char **argv) {
fprintf(stderr, "pb8: unknown option -%c\n", argtype); fprintf(stderr, "pb8: unknown option -%c\n", argtype);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
} else if (!infilename) { }
else if (!infilename) {
infilename = argv[i]; infilename = argv[i];
} else if (!outfilename) { }
else if (!outfilename) {
outfilename = argv[i]; outfilename = argv[i];
} else { }
else {
fputs(toomanyfilenames_msg, stderr); fputs(toomanyfilenames_msg, stderr);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -282,7 +290,8 @@ int main(int argc, char **argv) {
perror("for reading"); perror("for reading");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
} else { }
else {
infp = stdin; infp = stdin;
set_fd_binary(0); set_fd_binary(0);
} }
@ -296,7 +305,8 @@ int main(int argc, char **argv) {
fclose(infp); fclose(infp);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
} else { }
else {
outfp = stdout; outfp = stdout;
set_fd_binary(1); set_fd_binary(1);
} }
@ -305,7 +315,8 @@ int main(int argc, char **argv) {
int has_ferror = 0; int has_ferror = 0;
if (decompress) { if (decompress) {
compfailed = unpb8(infp, outfp); compfailed = unpb8(infp, outfp);
} else { }
else {
compfailed = pb8(infp, outfp, blocklength); compfailed = pb8(infp, outfp, blocklength);
} }
fflush(outfp); fflush(outfp);

View File

@ -150,7 +150,8 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample)
NSMutableArray *debugger_input_queue; NSMutableArray *debugger_input_queue;
} }
- (instancetype)init { - (instancetype)init
{
self = [super init]; self = [super init];
if (self) { if (self) {
has_debugger_input = [[NSConditionLock alloc] initWithCondition:0]; 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]; [super windowControllerDidLoadNib:aController];
// Interface Builder bug? // Interface Builder bug?
[self.consoleWindow setContentSize:self.consoleWindow.minSize]; [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; self.memoryBankItem.enabled = false;
} }
+ (BOOL)autosavesInPlace { + (BOOL)autosavesInPlace
{
return YES; return YES;
} }
- (NSString *)windowNibName { - (NSString *)windowNibName
{
// Override returning the nib file name of the document // 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. // 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"; return @"Document";
@ -690,7 +694,7 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample)
- (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)anItem - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)anItem
{ {
if([anItem action] == @selector(mute:)) { if ([anItem action] == @selector(mute:)) {
[(NSMenuItem*)anItem setState:!self.audioClient.isPlaying]; [(NSMenuItem*)anItem setState:!self.audioClient.isPlaying];
} }
else if ([anItem action] == @selector(togglePause:)) { 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]; [self.consoleWindow orderBack:nil];
} }
- (IBAction)consoleInput:(NSTextField *)sender { - (IBAction)consoleInput:(NSTextField *)sender
{
NSString *line = [sender stringValue]; NSString *line = [sender stringValue];
if ([line isEqualToString:@""] && lastConsoleInput) { if ([line isEqualToString:@""] && lastConsoleInput) {
line = lastConsoleInput; line = lastConsoleInput;
@ -1475,7 +1480,7 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample)
NSUInteger columnIndex = [[tableView tableColumns] indexOfObject:tableColumn]; NSUInteger columnIndex = [[tableView tableColumns] indexOfObject:tableColumn];
if (tableView == self.paletteTableView) { if (tableView == self.paletteTableView) {
if (columnIndex == 0) { 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); 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]; [self stop];
NSSavePanel * savePanel = [NSSavePanel savePanel]; NSSavePanel * savePanel = [NSSavePanel savePanel];
[savePanel setAllowedFileTypes:@[@"png"]]; [savePanel setAllowedFileTypes:@[@"png"]];
[savePanel beginSheetModalForWindow:self.printerFeedWindow completionHandler:^(NSInteger result){ [savePanel beginSheetModalForWindow:self.printerFeedWindow completionHandler:^(NSInteger result) {
if (result == NSFileHandlingPanelOKButton) { if (result == NSFileHandlingPanelOKButton) {
[savePanel orderOut:self]; [savePanel orderOut:self];
CGImageRef cgRef = [self.feedImageView.image CGImageForProposedRect:NULL CGImageRef cgRef = [self.feedImageView.image CGImageForProposedRect:NULL
@ -1681,11 +1686,13 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample)
return 600; 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; 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) { if ([[splitView arrangedSubviews] lastObject] == view) {
return NO; return NO;
} }

View File

@ -26,8 +26,7 @@ static OSStatus render(
-(id) initWithRendererBlock:(void (^)(UInt32 sampleRate, UInt32 nFrames, GB_sample_t *buffer)) block -(id) initWithRendererBlock:(void (^)(UInt32 sampleRate, UInt32 nFrames, GB_sample_t *buffer)) block
andSampleRate:(UInt32) rate andSampleRate:(UInt32) rate
{ {
if(!(self = [super init])) if (!(self = [super init])) {
{
return nil; return nil;
} }
@ -102,7 +101,8 @@ static OSStatus render(
_playing = NO; _playing = NO;
} }
-(void) dealloc { -(void) dealloc
{
[self stop]; [self stop];
AudioUnitUninitialize(audioUnit); AudioUnitUninitialize(audioUnit);
AudioComponentInstanceDispose(audioUnit); AudioComponentInstanceDispose(audioUnit);

View File

@ -169,7 +169,7 @@ void main(void) {\n\
+ (GLuint)shaderWithContents:(NSString*)contents type:(GLenum)type + (GLuint)shaderWithContents:(NSString*)contents type:(GLenum)type
{ {
const GLchar* source = [contents UTF8String]; const GLchar *source = [contents UTF8String];
// Create the shader object // Create the shader object
GLuint shader = glCreateShader(type); GLuint shader = glCreateShader(type);
// Load the shader source // Load the shader source

View File

@ -93,7 +93,7 @@
- (void)updateTrackingAreas - (void)updateTrackingAreas
{ {
if(trackingArea != nil) { if (trackingArea != nil) {
[self removeTrackingArea:trackingArea]; [self removeTrackingArea:trackingArea];
} }

View File

@ -4,7 +4,8 @@
@implementation GBOpenGLView @implementation GBOpenGLView
- (void)drawRect:(NSRect)dirtyRect { - (void)drawRect:(NSRect)dirtyRect
{
if (!self.shader) { if (!self.shader) {
self.shader = [[GBGLShader alloc] initWithName:[[NSUserDefaults standardUserDefaults] objectForKey:@"GBFilter"]]; self.shader = [[GBGLShader alloc] initWithName:[[NSUserDefaults standardUserDefaults] objectForKey:@"GBFilter"]];
} }

View File

@ -5,12 +5,14 @@
NSColor *_dividerColor; NSColor *_dividerColor;
} }
- (void)setDividerColor:(NSColor *)color { - (void)setDividerColor:(NSColor *)color
{
_dividerColor = color; _dividerColor = color;
[self setNeedsDisplay:YES]; [self setNeedsDisplay:YES];
} }
- (NSColor *)dividerColor { - (NSColor *)dividerColor
{
if (_dividerColor) { if (_dividerColor) {
return _dividerColor; return _dividerColor;
} }
@ -22,7 +24,8 @@
{ {
if (@available(macOS 10.11, *)) { if (@available(macOS 10.11, *)) {
return [super arrangedSubviews]; return [super arrangedSubviews];
} else { }
else {
return [self subviews]; return [self subviews];
} }
} }

View File

@ -173,7 +173,8 @@
[super setSelectedRanges:ranges affinity:affinity stillSelecting:stillSelectingFlag]; [super setSelectedRanges:ranges affinity:affinity stillSelecting:stillSelectingFlag];
} }
- (BOOL)resignFirstResponder { - (BOOL)resignFirstResponder
{
reverse_search_mode = false; reverse_search_mode = false;
return [super resignFirstResponder]; return [super resignFirstResponder];
} }

View File

@ -114,8 +114,7 @@
} }
- (instancetype)initWithCoder:(NSCoder *)coder - (instancetype)initWithCoder:(NSCoder *)coder
{ {
if (!(self = [super initWithCoder:coder])) if (!(self = [super initWithCoder:coder])) {
{
return self; return self;
} }
[self _init]; [self _init];
@ -124,8 +123,7 @@
- (instancetype)initWithFrame:(NSRect)frameRect - (instancetype)initWithFrame:(NSRect)frameRect
{ {
if (!(self = [super initWithFrame:frameRect])) if (!(self = [super initWithFrame:frameRect])) {
{
return self; return self;
} }
[self _init]; [self _init];

View File

@ -159,8 +159,7 @@ static const vector_float2 rect[] =
MTLRenderPassDescriptor *render_pass_descriptor = view.currentRenderPassDescriptor; MTLRenderPassDescriptor *render_pass_descriptor = view.currentRenderPassDescriptor;
id<MTLCommandBuffer> command_buffer = [command_queue commandBuffer]; id<MTLCommandBuffer> 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]; *(GB_frame_blending_mode_t *)[frame_blending_mode_buffer contents] = [self frameBlendingMode];
*(vector_float2 *)[output_resolution_buffer contents] = output_resolution; *(vector_float2 *)[output_resolution_buffer contents] = output_resolution;

View File

@ -295,7 +295,8 @@ AddHIDElements(CFArrayRef array, recDevice *pDevice)
} }
static bool static bool
ElementAlreadyAdded(const IOHIDElementCookie cookie, const recElement *listitem) { ElementAlreadyAdded(const IOHIDElementCookie cookie, const recElement *listitem)
{
while (listitem) { while (listitem) {
if (listitem->cookie == cookie) { if (listitem->cookie == cookie) {
return true; return true;
@ -431,7 +432,8 @@ AddHIDElement(const void *value, void *parameter)
} }
if (elementPrevious) { if (elementPrevious) {
elementPrevious->pNext = element; elementPrevious->pNext = element;
} else { }
else {
*headElement = element; *headElement = element;
} }
@ -519,7 +521,8 @@ GetDeviceInfo(IOHIDDeviceRef hidDevice, recDevice *pDevice)
*guid16++ = 0; *guid16++ = 0;
*guid16++ = version; *guid16++ = version;
*guid16++ = 0; *guid16++ = 0;
} else { }
else {
*guid16++ = BUS_BLUETOOTH; *guid16++ = BUS_BLUETOOTH;
*guid16++ = 0; *guid16++ = 0;
strlcpy((char*)guid16, pDevice->product, sizeof(pDevice->guid.data) - 4); 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; value = GetHIDElementState(device, element) - element->min;
if (range == 4) { /* 4 position hatswitch - scale up value */ if (range == 4) { /* 4 position hatswitch - scale up value */
value *= 2; 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; value = -1;
} }
if ((unsigned)value >= 8) { if ((unsigned)value >= 8) {

View File

@ -1,5 +1,6 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
int main(int argc, const char * argv[]) { int main(int argc, const char * argv[])
{
return NSApplicationMain(argc, argv); return NSApplicationMain(argc, argv);
} }

View File

@ -139,7 +139,7 @@ static double smooth(double x)
static void render(GB_gameboy_t *gb) static void render(GB_gameboy_t *gb)
{ {
GB_sample_t output = {0,0}; GB_sample_t output = {0, 0};
UNROLL UNROLL
for (unsigned i = 0; i < GB_N_CHANNELS; i++) { 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; gb->apu.is_active[GB_NOISE] = false;
update_sample(gb, GB_NOISE, 0, 0); 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]); nrx2_glitch(&gb->apu.noise_channel.current_volume, value, gb->io_registers[reg]);
update_sample(gb, GB_NOISE, update_sample(gb, GB_NOISE,
gb->apu.current_lfsr_sample ? gb->apu.current_lfsr_sample ?

View File

@ -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 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 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 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) { if (b.value == 0) {
return FIX_BANK(0); return FIX_BANK(0);
} }
return FIX_BANK(a.value / b.value); 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) { if (b.value == 0) {
return FIX_BANK(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')) { while (length && (string[length-1] == ' ' || string[length-1] == '\n' || string[length-1] == '\r' || string[length-1] == '\t')) {
length--; length--;
} }
if (length == 0) if (length == 0) {
{
GB_log(gb, "Expected expression.\n"); GB_log(gb, "Expected expression.\n");
*error = true; *error = true;
return (lvalue_t){0,}; 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')) { while (length && (string[length-1] == ' ' || string[length-1] == '\n' || string[length-1] == '\r' || string[length-1] == '\t')) {
length--; length--;
} }
if (length == 0) if (length == 0) {
{
GB_log(gb, "Expected expression.\n"); GB_log(gb, "Expected expression.\n");
*error = true; *error = true;
goto exit; 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])); memmove(&gb->watchpoints[index], &gb->watchpoints[index + 1], (gb->n_watchpoints - index - 1) * sizeof(gb->watchpoints[0]));
gb->n_watchpoints--; 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)); GB_log(gb, "Watchpoint removed from %s\n", debugger_value_to_string(gb, result, true));
return true; return true;
@ -1216,7 +1216,7 @@ static bool list(GB_gameboy_t *gb, char *arguments, char *modifiers, const debug
gb->watchpoints[i].condition); gb->watchpoints[i].condition);
} }
else { 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_R)? 'r' : '-',
(gb->watchpoints[i].flags & GB_WATCHPOINT_W)? 'w' : '-'); (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, "LY: %d\n", gb->io_registers[GB_IO_LY]);
GB_log(gb, "LYC: %d\n", gb->io_registers[GB_IO_LYC]); 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"); GB_log(gb, "Interrupt line: %s\n", gb->stat_interrupt_line? "On" : "Off");
return true; 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; uint8_t shift_amount = 1, mask;
if (modifiers) { if (modifiers) {
switch(modifiers[0]) { switch (modifiers[0]) {
case 'c': case 'c':
shift_amount = 2; shift_amount = 2;
break; 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) 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 | 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) static void print_command_description(GB_gameboy_t *gb, const debugger_command_t *command)

View File

@ -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]; *dest = gb->sprite_palettes_rgb[oam_fifo_item->palette * 4 + pixel];
} }
} }
if (gb->model & GB_MODEL_NO_SFC_BIT) { if (gb->model & GB_MODEL_NO_SFC_BIT) {
if (gb->icd_pixel_callback) { if (gb->icd_pixel_callback) {
gb->icd_pixel_callback(gb, icd_pixel); gb->icd_pixel_callback(gb, icd_pixel);

View File

@ -119,7 +119,7 @@ static void load_default_border(GB_gameboy_t *gb)
}\ }\
}\ }\
}\ }\
} while(false); } while (false);
if (gb->model == GB_MODEL_AGB) { if (gb->model == GB_MODEL_AGB) {
#include "graphics/agb_border.inc" #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 #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_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_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_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}}}; const GB_palette_t GB_PALETTE_GBL = {{{0x0a, 0x1c, 0x15}, {0x35, 0x78, 0x62}, {0x56, 0xb4, 0x95}, {0x7f, 0xe2, 0xc3}, {0x91, 0xea, 0xd0}}};

View File

@ -53,7 +53,7 @@
typedef struct { typedef struct {
struct { struct {
uint8_t r,g,b; uint8_t r, g, b;
} colors[5]; } colors[5];
} GB_palette_t; } GB_palette_t;
@ -254,11 +254,11 @@ typedef enum {
#define INTERNAL_DIV_CYCLES (0x40000) #define INTERNAL_DIV_CYCLES (0x40000)
#if !defined(MIN) #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 #endif
#if !defined(MAX) #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
#endif #endif

View File

@ -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_SGB_PAL_NO_SFC:
case GB_MODEL_SGB2: case GB_MODEL_SGB2:
case GB_MODEL_SGB2_NO_SFC: case GB_MODEL_SGB2_NO_SFC:
; break;
} }
} }

View File

@ -361,7 +361,7 @@ int GB_load_state_from_buffer(GB_gameboy_t *gb, const uint8_t *buffer, size_t le
return -1; 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; return -1;
} }

View File

@ -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. */ 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->sgb->command[0] & 0xF1) == 0xF1) {
if(gb->boot_rom_finished) return; if (gb->boot_rom_finished) return;
uint8_t checksum = 0; uint8_t checksum = 0;
for (unsigned i = 2; i < 0x10; i++) { 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; gb->sgb->attribute_map[x + 20 * y] = inside_palette;
} }
} }
else if(middle) { else if (middle) {
gb->sgb->attribute_map[x + 20 * y] = middle_palette; gb->sgb->attribute_map[x + 20 * y] = middle_palette;
} }
} }

View File

@ -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++);
addr |= cycle_read_inc_oam_bug(gb, gb->pc++) << 8; addr |= cycle_read_inc_oam_bug(gb, gb->pc++) << 8;
cycle_write(gb, addr, gb->registers[GB_REGISTER_SP] & 0xFF); 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) 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; uint16_t addr;
gb->registers[GB_REGISTER_AF] &= 0xFF; gb->registers[GB_REGISTER_AF] &= 0xFF;
addr = cycle_read_inc_oam_bug(gb, gb->pc++); 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; 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 */ 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 */ 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); GB_debugger_call_hook(gb, call_addr);
} }
/* Run mode */ /* Run mode */
else if(!gb->halted) { else if (!gb->halted) {
gb->last_opcode_read = cycle_read_inc_oam_bug(gb, gb->pc++); gb->last_opcode_read = cycle_read_inc_oam_bug(gb, gb->pc++);
if (gb->halt_bug) { if (gb->halt_bug) {
gb->pc--; gb->pc--;

View File

@ -97,7 +97,8 @@ static void rla(GB_gameboy_t *gb, uint8_t opcode, uint16_t *pc)
GB_log(gb, "RLA\n"); 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; uint16_t addr;
(*pc)++; (*pc)++;
addr = GB_read_memory(gb, (*pc)++); addr = GB_read_memory(gb, (*pc)++);

View File

@ -274,19 +274,14 @@ void GB_rtc_run(GB_gameboy_t *gb)
time_t current_time = time(NULL); time_t current_time = time(NULL);
while (gb->last_rtc_second < current_time) { while (gb->last_rtc_second < current_time) {
gb->last_rtc_second++; gb->last_rtc_second++;
if (++gb->rtc_real.seconds == 60) if (++gb->rtc_real.seconds == 60) {
{
gb->rtc_real.seconds = 0; gb->rtc_real.seconds = 0;
if (++gb->rtc_real.minutes == 60) if (++gb->rtc_real.minutes == 60) {
{
gb->rtc_real.minutes = 0; gb->rtc_real.minutes = 0;
if (++gb->rtc_real.hours == 24) if (++gb->rtc_real.hours == 24) {
{
gb->rtc_real.hours = 0; gb->rtc_real.hours = 0;
if (++gb->rtc_real.days == 0) if (++gb->rtc_real.days == 0) {
{ if (gb->rtc_real.high & 1) { /* Bit 8 of days*/
if (gb->rtc_real.high & 1) /* Bit 8 of days*/
{
gb->rtc_real.high |= 0x80; /* Overflow bit */ gb->rtc_real.high |= 0x80; /* Overflow bit */
} }
gb->rtc_real.high ^= 1; gb->rtc_real.high ^= 1;

View File

@ -88,8 +88,7 @@ char *do_open_rom_dialog(void)
int res = gtk_dialog_run (dialog); int res = gtk_dialog_run (dialog);
char *ret = NULL; char *ret = NULL;
if (res == GTK_RESPONSE_ACCEPT) if (res == GTK_RESPONSE_ACCEPT) {
{
char *filename; char *filename;
filename = gtk_file_chooser_get_filename(dialog); filename = gtk_file_chooser_get_filename(dialog);
ret = strdup(filename); ret = strdup(filename);

View File

@ -17,8 +17,7 @@ char *do_open_rom_dialog(void)
dialog.lpstrInitialDir = NULL; dialog.lpstrInitialDir = NULL;
dialog.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; dialog.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if (GetOpenFileNameW(&dialog) == TRUE) if (GetOpenFileNameW(&dialog) == TRUE) {
{
char *ret = malloc(MAX_PATH * 4); char *ret = malloc(MAX_PATH * 4);
WideCharToMultiByte(CP_UTF8, 0, filename, sizeof(filename), ret, MAX_PATH * 4, NULL, NULL); WideCharToMultiByte(CP_UTF8, 0, filename, sizeof(filename), ret, MAX_PATH * 4, NULL, NULL);
return ret; return ret;

View File

@ -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) */ /* 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); CGColorSpaceRelease(colorSpaceRef);

View File

@ -43,8 +43,8 @@ typedef struct __QuickLookGeneratorPluginType
QuickLookGeneratorPluginType *AllocQuickLookGeneratorPluginType(CFUUIDRef inFactoryID); QuickLookGeneratorPluginType *AllocQuickLookGeneratorPluginType(CFUUIDRef inFactoryID);
void DeallocQuickLookGeneratorPluginType(QuickLookGeneratorPluginType *thisInstance); void DeallocQuickLookGeneratorPluginType(QuickLookGeneratorPluginType *thisInstance);
HRESULT QuickLookGeneratorQueryInterface(void *thisInstance,REFIID iid,LPVOID *ppv); HRESULT QuickLookGeneratorQueryInterface(void *thisInstance, REFIID iid, LPVOID *ppv);
void *QuickLookGeneratorPluginFactory(CFAllocatorRef allocator,CFUUIDRef typeID); void *QuickLookGeneratorPluginFactory(CFAllocatorRef allocator, CFUUIDRef typeID);
ULONG QuickLookGeneratorPluginAddRef(void *thisInstance); ULONG QuickLookGeneratorPluginAddRef(void *thisInstance);
ULONG QuickLookGeneratorPluginRelease(void *thisInstance); ULONG QuickLookGeneratorPluginRelease(void *thisInstance);
@ -77,11 +77,11 @@ QuickLookGeneratorPluginType *AllocQuickLookGeneratorPluginType(CFUUIDRef inFact
QuickLookGeneratorPluginType *theNewInstance; QuickLookGeneratorPluginType *theNewInstance;
theNewInstance = (QuickLookGeneratorPluginType *)malloc(sizeof(QuickLookGeneratorPluginType)); 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 */ /* Point to the function table Malloc enough to store the stuff and copy the filler from myInterfaceFtbl over */
theNewInstance->conduitInterface = malloc(sizeof(QLGeneratorInterfaceStruct)); 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. */ /* Retain and keep an open instance refcount for each factory. */
theNewInstance->factoryID = CFRetain(inFactoryID); theNewInstance->factoryID = CFRetain(inFactoryID);
@ -110,7 +110,7 @@ void DeallocQuickLookGeneratorPluginType(QuickLookGeneratorPluginType *thisInsta
/* Free the instance structure */ /* Free the instance structure */
free(thisInstance); free(thisInstance);
if (theFactoryID){ if (theFactoryID) {
CFPlugInRemoveInstanceForFactory(theFactoryID); CFPlugInRemoveInstanceForFactory(theFactoryID);
CFRelease(theFactoryID); CFRelease(theFactoryID);
} }
@ -121,13 +121,13 @@ void DeallocQuickLookGeneratorPluginType(QuickLookGeneratorPluginType *thisInsta
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Implementation of the IUnknown QueryInterface function. // Implementation of the IUnknown QueryInterface function.
// //
HRESULT QuickLookGeneratorQueryInterface(void *thisInstance,REFIID iid,LPVOID *ppv) HRESULT QuickLookGeneratorQueryInterface(void *thisInstance, REFIID iid, LPVOID *ppv)
{ {
CFUUIDRef interfaceID; 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, /* If the Right interface was requested, bump the ref count,
* set the ppv parameter equal to the instance, and * set the ppv parameter equal to the instance, and
* return good status. * return good status.
@ -138,7 +138,8 @@ HRESULT QuickLookGeneratorQueryInterface(void *thisInstance,REFIID iid,LPVOID *p
*ppv = thisInstance; *ppv = thisInstance;
CFRelease(interfaceID); CFRelease(interfaceID);
return S_OK; return S_OK;
}else{ }
else {
/* Requested interface unknown, bail with error. */ /* Requested interface unknown, bail with error. */
*ppv = NULL; *ppv = NULL;
CFRelease(interfaceID); CFRelease(interfaceID);
@ -168,10 +169,11 @@ ULONG QuickLookGeneratorPluginAddRef(void *thisInstance)
ULONG QuickLookGeneratorPluginRelease(void *thisInstance) ULONG QuickLookGeneratorPluginRelease(void *thisInstance)
{ {
((QuickLookGeneratorPluginType*)thisInstance)->refCount -= 1; ((QuickLookGeneratorPluginType*)thisInstance)->refCount -= 1;
if (((QuickLookGeneratorPluginType*)thisInstance)->refCount == 0){ if (((QuickLookGeneratorPluginType*)thisInstance)->refCount == 0) {
DeallocQuickLookGeneratorPluginType((QuickLookGeneratorPluginType*)thisInstance ); DeallocQuickLookGeneratorPluginType((QuickLookGeneratorPluginType*)thisInstance );
return 0; return 0;
}else{ }
else {
return ((QuickLookGeneratorPluginType*) thisInstance )->refCount; return ((QuickLookGeneratorPluginType*) thisInstance )->refCount;
} }
} }
@ -179,7 +181,7 @@ ULONG QuickLookGeneratorPluginRelease(void *thisInstance)
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// QuickLookGeneratorPluginFactory // QuickLookGeneratorPluginFactory
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void *QuickLookGeneratorPluginFactory(CFAllocatorRef allocator,CFUUIDRef typeID) void *QuickLookGeneratorPluginFactory(CFAllocatorRef allocator, CFUUIDRef typeID)
{ {
QuickLookGeneratorPluginType *result; QuickLookGeneratorPluginType *result;
CFUUIDRef uuid; CFUUIDRef uuid;
@ -187,8 +189,8 @@ void *QuickLookGeneratorPluginFactory(CFAllocatorRef allocator,CFUUIDRef typeID)
/* If correct type is being requested, allocate an /* If correct type is being requested, allocate an
* instance of kQLGeneratorTypeID and return the IUnknown interface. * instance of kQLGeneratorTypeID and return the IUnknown interface.
*/ */
if (CFEqual(typeID,kQLGeneratorTypeID)){ if (CFEqual(typeID, kQLGeneratorTypeID)) {
uuid = CFUUIDCreateFromString(kCFAllocatorDefault,CFSTR(PLUGIN_ID)); uuid = CFUUIDCreateFromString(kCFAllocatorDefault, CFSTR(PLUGIN_ID));
result = AllocQuickLookGeneratorPluginType(uuid); result = AllocQuickLookGeneratorPluginType(uuid);
CFRelease(uuid); CFRelease(uuid);
return result; return result;

View File

@ -338,7 +338,7 @@ static void cycle_model_backwards(unsigned index)
const char *current_model_string(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]; [configuration.model];
} }
@ -800,7 +800,7 @@ static void cycle_joypads(unsigned index)
SDL_JoystickClose(joystick); SDL_JoystickClose(joystick);
joystick = NULL; joystick = NULL;
} }
if ((controller = SDL_GameControllerOpen(joypad_index))){ if ((controller = SDL_GameControllerOpen(joypad_index))) {
joystick = SDL_GameControllerGetJoystick(controller); joystick = SDL_GameControllerGetJoystick(controller);
} }
else { else {
@ -822,7 +822,7 @@ static void cycle_joypads_backwards(unsigned index)
SDL_JoystickClose(joystick); SDL_JoystickClose(joystick);
joystick = NULL; joystick = NULL;
} }
if ((controller = SDL_GameControllerOpen(joypad_index))){ if ((controller = SDL_GameControllerOpen(joypad_index))) {
joystick = SDL_GameControllerGetJoystick(controller); joystick = SDL_GameControllerGetJoystick(controller);
} }
else { else {
@ -886,7 +886,7 @@ void connect_joypad(void)
} }
} }
else if (!joystick && SDL_NumJoysticks()) { else if (!joystick && SDL_NumJoysticks()) {
if ((controller = SDL_GameControllerOpen(0))){ if ((controller = SDL_GameControllerOpen(0))) {
joystick = SDL_GameControllerGetJoystick(controller); joystick = SDL_GameControllerGetJoystick(controller);
} }
else { else {

View File

@ -149,8 +149,7 @@ static void open_menu(void)
static void handle_events(GB_gameboy_t *gb) static void handle_events(GB_gameboy_t *gb)
{ {
SDL_Event event; SDL_Event event;
while (SDL_PollEvent(&event)) while (SDL_PollEvent(&event)) {
{
switch (event.type) { switch (event.type) {
case SDL_QUIT: case SDL_QUIT:
pending_command = GB_SDL_QUIT_COMMAND; 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) int main(int argc, char **argv)
{ {
#ifdef _WIN32 #ifdef _WIN32
SetProcessDPIAware(); SetProcessDPIAware();
#endif #endif
#define str(x) #x #define str(x) #x
#define xstr(x) str(x) #define xstr(x) str(x)

View File

@ -10,7 +10,7 @@
#define GL_COMPAT_WRAPPER(func) \ #define GL_COMPAT_WRAPPER(func) \
({ extern typeof(func) *GL_COMPAT_NAME(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); \ GL_COMPAT_NAME(func); \
}) })

View File

@ -300,7 +300,7 @@ int main(int argc, char **argv)
if (max_forks > 1) { if (max_forks > 1) {
while (current_forks >= max_forks) { while (current_forks >= max_forks) {
int wait_out; int wait_out;
while(wait(&wait_out) == -1); while (wait(&wait_out) == -1);
current_forks--; current_forks--;
} }
@ -433,7 +433,7 @@ int main(int argc, char **argv)
} }
#ifndef _WIN32 #ifndef _WIN32
int wait_out; int wait_out;
while(wait(&wait_out) != -1); while (wait(&wait_out) != -1);
#endif #endif
return 0; return 0;
} }

View File

@ -24,7 +24,8 @@ static inline int vasprintf(char **str, const char *fmt, va_list args)
#endif #endif
/* This code is public domain -- Will Hartung 4/9/09 */ /* 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 *bufptr = NULL;
char *p = bufptr; char *p = bufptr;
size_t size; size_t size;

View File

@ -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) 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; 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) 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_start_callback(&gameboy[0], serial_start1);
GB_set_serial_transfer_bit_end_callback(&gameboy[0], serial_end1); 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_start_callback(&gameboy[1], serial_start2);
GB_set_serial_transfer_bit_end_callback(&gameboy[1], serial_end2); 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_start_callback(&gameboy[0], NULL);
GB_set_serial_transfer_bit_end_callback(&gameboy[0], NULL); GB_set_serial_transfer_bit_end_callback(&gameboy[0], NULL);
GB_set_serial_transfer_bit_start_callback(&gameboy[1], 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 */ /* todo: attempt to make these more generic */
GB_set_vblank_callback(&gameboy[0], (GB_vblank_callback_t) vblank1); 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); GB_set_vblank_callback(&gameboy[1], (GB_vblank_callback_t) vblank2);
if (link_cable_emulation) if (link_cable_emulation)
set_link_cable_state(true); 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].ptr = GB_get_direct_access(&gameboy[i], GB_DIRECT_ACCESS_OAM, &size, &bank);
descs[8].start = 0xFE00; descs[8].start = 0xFE00;
descs[8].len = 0x00A0; 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].ptr = descs[2].ptr + 0x2000; /* GBC RAM bank 2 */
descs[9].start = 0x10000; descs[9].start = 0x10000;
descs[9].len = GB_is_cgb(&gameboy[i]) ? 0x6000 : 0; /* 0x1000 per bank (2-7), unmapped on GB */ 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].ptr = GB_get_direct_access(&gameboy[i], GB_DIRECT_ACCESS_IO, &size, &bank);
descs[10].start = 0xFF00; descs[10].start = 0xFF00;
descs[10].len = 0x0080; descs[10].len = 0x0080;
descs[10].select= 0xFFFFFF00; descs[10].select = 0xFFFFFF00;
struct retro_memory_map mmaps; struct retro_memory_map mmaps;
mmaps.descriptors = descs; mmaps.descriptors = descs;
@ -446,8 +443,7 @@ static void init_for_current_model(unsigned id)
environ_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &mmaps); environ_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &mmaps);
/* Let's be extremely nitpicky about how devices and descriptors are set */ /* 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[] = { static const struct retro_controller_info ports[] = {
{ controllers_sgb, 1 }, { controllers_sgb, 1 },
{ 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_CONTROLLER_INFO, (void*)ports);
environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, descriptors_4p); 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[] = { static const struct retro_controller_info ports[] = {
{ controllers, 1 }, { controllers, 1 },
{ NULL, 0 }, { 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_CONTROLLER_INFO, (void*)ports);
environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, descriptors_1p); environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, descriptors_1p);
} }
else else {
{
static const struct retro_controller_info ports[] = { static const struct retro_controller_info ports[] = {
{ controllers, 1 }, { controllers, 1 },
{ controllers, 1 }, { controllers, 1 },
@ -483,12 +477,10 @@ static void init_for_current_model(unsigned id)
static void check_variables() static void check_variables()
{ {
struct retro_variable var = {0}; struct retro_variable var = {0};
if (emulated_devices == 1) if (emulated_devices == 1) {
{
var.key = "sameboy_color_correction_mode"; var.key = "sameboy_color_correction_mode";
var.value = NULL; 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) if (strcmp(var.value, "off") == 0)
GB_set_color_correction_mode(&gameboy[0], GB_COLOR_CORRECTION_DISABLED); GB_set_color_correction_mode(&gameboy[0], GB_COLOR_CORRECTION_DISABLED);
else if (strcmp(var.value, "correct curves") == 0) else if (strcmp(var.value, "correct curves") == 0)
@ -503,8 +495,7 @@ static void check_variables()
var.key = "sameboy_high_pass_filter_mode"; var.key = "sameboy_high_pass_filter_mode";
var.value = NULL; 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) if (strcmp(var.value, "off") == 0)
GB_set_highpass_filter_mode(&gameboy[0], GB_HIGHPASS_OFF); GB_set_highpass_filter_mode(&gameboy[0], GB_HIGHPASS_OFF);
else if (strcmp(var.value, "accurate") == 0) else if (strcmp(var.value, "accurate") == 0)
@ -515,8 +506,7 @@ static void check_variables()
var.key = "sameboy_model"; var.key = "sameboy_model";
var.value = NULL; 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]; enum model new_model = model[0];
if (strcmp(var.value, "Game Boy") == 0) if (strcmp(var.value, "Game Boy") == 0)
new_model = MODEL_DMG; new_model = MODEL_DMG;
@ -531,8 +521,7 @@ static void check_variables()
else else
new_model = MODEL_AUTO; new_model = MODEL_AUTO;
if (new_model != model[0]) if (new_model != model[0]) {
{
geometry_updated = true; geometry_updated = true;
model[0] = new_model; model[0] = new_model;
init_for_current_model(0); init_for_current_model(0);
@ -541,20 +530,17 @@ static void check_variables()
var.key = "sameboy_border"; var.key = "sameboy_border";
var.value = NULL; 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) if (strcmp(var.value, "enabled") == 0)
sgb_border = 1; sgb_border = 1;
else if (strcmp(var.value, "disabled") == 0) else if (strcmp(var.value, "disabled") == 0)
sgb_border = 0; sgb_border = 0;
} }
} }
else else {
{
var.key = "sameboy_color_correction_mode_1"; var.key = "sameboy_color_correction_mode_1";
var.value = NULL; 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) if (strcmp(var.value, "off") == 0)
GB_set_color_correction_mode(&gameboy[0], GB_COLOR_CORRECTION_DISABLED); GB_set_color_correction_mode(&gameboy[0], GB_COLOR_CORRECTION_DISABLED);
else if (strcmp(var.value, "correct curves") == 0) else if (strcmp(var.value, "correct curves") == 0)
@ -569,8 +555,7 @@ static void check_variables()
var.key = "sameboy_color_correction_mode_2"; var.key = "sameboy_color_correction_mode_2";
var.value = NULL; 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) if (strcmp(var.value, "off") == 0)
GB_set_color_correction_mode(&gameboy[1], GB_COLOR_CORRECTION_DISABLED); GB_set_color_correction_mode(&gameboy[1], GB_COLOR_CORRECTION_DISABLED);
else if (strcmp(var.value, "correct curves") == 0) 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.key = "sameboy_high_pass_filter_mode_1";
var.value = NULL; 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) if (strcmp(var.value, "off") == 0)
GB_set_highpass_filter_mode(&gameboy[0], GB_HIGHPASS_OFF); GB_set_highpass_filter_mode(&gameboy[0], GB_HIGHPASS_OFF);
else if (strcmp(var.value, "accurate") == 0) else if (strcmp(var.value, "accurate") == 0)
@ -598,8 +582,7 @@ static void check_variables()
var.key = "sameboy_high_pass_filter_mode_2"; var.key = "sameboy_high_pass_filter_mode_2";
var.value = NULL; 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) if (strcmp(var.value, "off") == 0)
GB_set_highpass_filter_mode(&gameboy[1], GB_HIGHPASS_OFF); GB_set_highpass_filter_mode(&gameboy[1], GB_HIGHPASS_OFF);
else if (strcmp(var.value, "accurate") == 0) else if (strcmp(var.value, "accurate") == 0)
@ -610,8 +593,7 @@ static void check_variables()
var.key = "sameboy_model_1"; var.key = "sameboy_model_1";
var.value = NULL; 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]; enum model new_model = model[0];
if (strcmp(var.value, "Game Boy") == 0) if (strcmp(var.value, "Game Boy") == 0)
new_model = MODEL_DMG; new_model = MODEL_DMG;
@ -626,8 +608,7 @@ static void check_variables()
else else
new_model = MODEL_AUTO; new_model = MODEL_AUTO;
if (model[0] != new_model) if (model[0] != new_model) {
{
model[0] = new_model; model[0] = new_model;
init_for_current_model(0); init_for_current_model(0);
} }
@ -635,8 +616,7 @@ static void check_variables()
var.key = "sameboy_model_2"; var.key = "sameboy_model_2";
var.value = NULL; 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]; enum model new_model = model[1];
if (strcmp(var.value, "Game Boy") == 0) if (strcmp(var.value, "Game Boy") == 0)
new_model = MODEL_DMG; new_model = MODEL_DMG;
@ -651,8 +631,7 @@ static void check_variables()
else else
new_model = MODEL_AUTO; new_model = MODEL_AUTO;
if (model[1] != new_model) if (model[1] != new_model) {
{
model[1] = new_model; model[1] = new_model;
init_for_current_model(1); init_for_current_model(1);
} }
@ -660,8 +639,7 @@ static void check_variables()
var.key = "sameboy_screen_layout"; var.key = "sameboy_screen_layout";
var.value = NULL; 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) if (strcmp(var.value, "top-down") == 0)
screen_layout = LAYOUT_TOP_DOWN; screen_layout = LAYOUT_TOP_DOWN;
else else
@ -672,8 +650,7 @@ static void check_variables()
var.key = "sameboy_link"; var.key = "sameboy_link";
var.value = NULL; 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; bool tmp = link_cable_emulation;
if (strcmp(var.value, "enabled") == 0) if (strcmp(var.value, "enabled") == 0)
link_cable_emulation = true; link_cable_emulation = true;
@ -687,8 +664,7 @@ static void check_variables()
var.key = "sameboy_audio_output"; var.key = "sameboy_audio_output";
var.value = NULL; 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) if (strcmp(var.value, "Game Boy #1") == 0)
audio_out = GB_1; audio_out = GB_1;
else else
@ -753,28 +729,25 @@ void retro_get_system_av_info(struct retro_system_av_info *info)
struct retro_game_geometry geom; struct retro_game_geometry geom;
struct retro_system_timing timing = { GB_get_usual_frame_rate(&gameboy[0]), AUDIO_FREQUENCY }; 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) { if (screen_layout == LAYOUT_TOP_DOWN) {
geom.base_width = VIDEO_WIDTH; geom.base_width = VIDEO_WIDTH;
geom.base_height = VIDEO_HEIGHT * emulated_devices; geom.base_height = VIDEO_HEIGHT * emulated_devices;
geom.aspect_ratio = (double)VIDEO_WIDTH / (emulated_devices * VIDEO_HEIGHT); 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_width = VIDEO_WIDTH * emulated_devices;
geom.base_height = VIDEO_HEIGHT; geom.base_height = VIDEO_HEIGHT;
geom.aspect_ratio = ((double)VIDEO_WIDTH * emulated_devices) / VIDEO_HEIGHT; geom.aspect_ratio = ((double)VIDEO_WIDTH * emulated_devices) / VIDEO_HEIGHT;
} }
} }
else else {
{ if (model[0] == MODEL_SGB || model[0] == MODEL_SGB2) {
if (model[0] == MODEL_SGB || model[0] == MODEL_SGB2)
{
geom.base_width = SGB_VIDEO_WIDTH; geom.base_width = SGB_VIDEO_WIDTH;
geom.base_height = SGB_VIDEO_HEIGHT; geom.base_height = SGB_VIDEO_HEIGHT;
geom.aspect_ratio = (double)SGB_VIDEO_WIDTH / SGB_VIDEO_HEIGHT; geom.aspect_ratio = (double)SGB_VIDEO_WIDTH / SGB_VIDEO_HEIGHT;
} }
else else {
{
geom.base_width = VIDEO_WIDTH; geom.base_width = VIDEO_WIDTH;
geom.base_height = VIDEO_HEIGHT; geom.base_height = VIDEO_HEIGHT;
geom.aspect_ratio = (double)VIDEO_WIDTH / 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) if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
check_variables(); check_variables();
if (emulated_devices == 2) if (emulated_devices == 2) {
{
GB_update_keys_status(&gameboy[0], 0); GB_update_keys_status(&gameboy[0], 0);
GB_update_keys_status(&gameboy[1], 1); 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++) for (unsigned i = 0; i < 4; i++)
GB_update_keys_status(&gameboy[0], i); GB_update_keys_status(&gameboy[0], i);
} }
@ -863,8 +834,7 @@ void retro_run(void)
vblank1_occurred = vblank2_occurred = false; vblank1_occurred = vblank2_occurred = false;
signed delta = 0; signed delta = 0;
if (emulated_devices == 2) if (emulated_devices == 2) {
{
while (!vblank1_occurred || !vblank2_occurred) { while (!vblank1_occurred || !vblank2_occurred) {
if (delta >= 0) { if (delta >= 0) {
delta -= GB_run(&gameboy[0]); delta -= GB_run(&gameboy[0]);
@ -874,16 +844,15 @@ void retro_run(void)
} }
} }
} }
else else {
{
GB_run_frame(&gameboy[0]); GB_run_frame(&gameboy[0]);
} }
if (emulated_devices == 2) if (emulated_devices == 2) {
{
if (screen_layout == LAYOUT_TOP_DOWN) { if (screen_layout == LAYOUT_TOP_DOWN) {
video_cb(frame_buf, VIDEO_WIDTH, VIDEO_HEIGHT * emulated_devices, VIDEO_WIDTH * sizeof(uint32_t)); 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 */ /* use slow memcpy method for now */
for (int index = 0; index < emulated_devices; index++) { for (int index = 0; index < emulated_devices; index++) {
for (int y = 0; y < VIDEO_HEIGHT; y++) { 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)); 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 (model[0] == MODEL_SGB || model[0] == MODEL_SGB2) {
if (sgb_border == 1) if (sgb_border == 1)
video_cb(frame_buf, SGB_VIDEO_WIDTH, SGB_VIDEO_HEIGHT, SGB_VIDEO_WIDTH * sizeof(uint32_t)); 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); environ_cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void *)vars_single);
check_variables(); 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)); memset(frame_buf, 0, SGB_VIDEO_PIXELS * emulated_devices * sizeof(uint32_t));
enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_XRGB8888; 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"); log_cb(RETRO_LOG_INFO, "XRGB8888 is not supported\n");
return false; 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; 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); 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); 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); log_cb(RETRO_LOG_INFO, "Failed to load ROM at %s\n", info->path);
return false; 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)); memset(frame_buf_copy, 0, emulated_devices * SGB_VIDEO_PIXELS * sizeof(uint32_t));
enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_XRGB8888; 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"); log_cb(RETRO_LOG_INFO, "XRGB8888 is not supported\n");
return false; 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; 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); 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); 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"); log_cb(RETRO_LOG_INFO, "Failed to load ROM\n");
return false; return false;
} }
@ -1063,8 +1025,7 @@ bool retro_serialize(void *data, size_t size)
bool retro_unserialize(const 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]); size_t state_size = GB_get_save_state_size(&gameboy[i]);
if (state_size > size) { if (state_size > size) {
return false; return false;
@ -1085,10 +1046,8 @@ bool retro_unserialize(const void *data, size_t size)
void *retro_get_memory_data(unsigned type) void *retro_get_memory_data(unsigned type)
{ {
void *data = NULL; void *data = NULL;
if (emulated_devices == 1) if (emulated_devices == 1) {
{ switch (type) {
switch(type)
{
case RETRO_MEMORY_SYSTEM_RAM: case RETRO_MEMORY_SYSTEM_RAM:
data = gameboy[0].ram; data = gameboy[0].ram;
break; break;
@ -1102,7 +1061,7 @@ void *retro_get_memory_data(unsigned type)
data = gameboy[0].vram; data = gameboy[0].vram;
break; break;
case RETRO_MEMORY_RTC: 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); data = GB_GET_SECTION(&gameboy[0], rtc);
else else
data = NULL; data = NULL;
@ -1111,10 +1070,8 @@ void *retro_get_memory_data(unsigned type)
break; break;
} }
} }
else else {
{ switch (type) {
switch (type)
{
case RETRO_MEMORY_GAMEBOY_1_SRAM: case RETRO_MEMORY_GAMEBOY_1_SRAM:
if (gameboy[0].cartridge_type->has_battery && gameboy[0].mbc_ram_size != 0) if (gameboy[0].cartridge_type->has_battery && gameboy[0].mbc_ram_size != 0)
data = gameboy[0].mbc_ram; data = gameboy[0].mbc_ram;
@ -1128,13 +1085,13 @@ void *retro_get_memory_data(unsigned type)
data = NULL; data = NULL;
break; break;
case RETRO_MEMORY_GAMEBOY_1_RTC: 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); data = GB_GET_SECTION(&gameboy[0], rtc);
else else
data = NULL; data = NULL;
break; break;
case RETRO_MEMORY_GAMEBOY_2_RTC: 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); data = GB_GET_SECTION(&gameboy[1], rtc);
else else
data = NULL; data = NULL;
@ -1150,10 +1107,8 @@ void *retro_get_memory_data(unsigned type)
size_t retro_get_memory_size(unsigned type) size_t retro_get_memory_size(unsigned type)
{ {
size_t size = 0; size_t size = 0;
if (emulated_devices == 1) if (emulated_devices == 1) {
{ switch (type) {
switch(type)
{
case RETRO_MEMORY_SYSTEM_RAM: case RETRO_MEMORY_SYSTEM_RAM:
size = gameboy[0].ram_size; size = gameboy[0].ram_size;
break; break;
@ -1167,7 +1122,7 @@ size_t retro_get_memory_size(unsigned type)
size = gameboy[0].vram_size; size = gameboy[0].vram_size;
break; break;
case RETRO_MEMORY_RTC: case RETRO_MEMORY_RTC:
if(gameboy[0].cartridge_type->has_battery) if (gameboy[0].cartridge_type->has_battery)
size = GB_SECTION_SIZE(rtc); size = GB_SECTION_SIZE(rtc);
else else
size = 0; size = 0;
@ -1176,10 +1131,8 @@ size_t retro_get_memory_size(unsigned type)
break; break;
} }
} }
else else {
{ switch (type) {
switch (type)
{
case RETRO_MEMORY_GAMEBOY_1_SRAM: case RETRO_MEMORY_GAMEBOY_1_SRAM:
if (gameboy[0].cartridge_type->has_battery && gameboy[0].mbc_ram_size != 0) if (gameboy[0].cartridge_type->has_battery && gameboy[0].mbc_ram_size != 0)
size = gameboy[0].mbc_ram_size; size = gameboy[0].mbc_ram_size;
@ -1193,11 +1146,11 @@ size_t retro_get_memory_size(unsigned type)
size = 0; size = 0;
break; break;
case RETRO_MEMORY_GAMEBOY_1_RTC: 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); size = GB_SECTION_SIZE(rtc);
break; break;
case RETRO_MEMORY_GAMEBOY_2_RTC: 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); size = GB_SECTION_SIZE(rtc);
break; break;
default: default: