SameBoy | Accurate GB/GBC emulator |
| download: https://git.y1.nz/archives/sameboy.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit 2dfde867a9c614fd274f7b1c1d573295599f57c1 parent 6efefab52605da97d5af751a328d4519772f82a4 Author: Lior Halphon <LIJI32@gmail.com> Date: Fri, 8 Nov 2024 14:53:16 +0200 Syncing with the App Store branch Diffstat:
| M | AppleCommon/GBAudioClient.h | 6 | +++--- |
| M | AppleCommon/GBAudioClient.m | 2 | +- |
| M | Cocoa/Document.xib | 2 | +- |
| M | Core/debugger.c | 2 | +- |
| M | Core/gb.c | 10 | +++++----- |
| M | Core/gb.h | 2 | +- |
| M | JoyKit/JOYController.m | 2 | +- |
| M | Makefile | 4 | ++-- |
| M | SDL/configuration.h | 2 | +- |
| M | SDL/gui.c | 6 | +++--- |
| M | SDL/main.c | 2 | +- |
| M | iOS/GBBackgroundView.m | 12 | +++++++++--- |
| M | iOS/GBHub.m | 2 | +- |
| M | iOS/GBROMManager.m | 1 | + |
| M | iOS/GBROMViewController.m | 14 | +++++++++----- |
| M | iOS/GBSettingsViewController.m | 16 | +++++++++++----- |
| M | iOS/GBViewController.m | 5 | ++++- |
| M | iOS/main.m | 2 | +- |
18 files changed, 56 insertions(+), 36 deletions(-)
diff --git a/AppleCommon/GBAudioClient.h b/AppleCommon/GBAudioClient.h @@ -5,8 +5,8 @@ @property (nonatomic, strong) void (^renderBlock)(UInt32 sampleRate, UInt32 nFrames, GB_sample_t *buffer); @property (nonatomic, readonly) UInt32 rate; @property (nonatomic, readonly, getter=isPlaying) bool playing; --(void) start; --(void) stop; --(id) initWithRendererBlock:(void (^)(UInt32 sampleRate, UInt32 nFrames, GB_sample_t *buffer)) block +- (void)start; +- (void)stop; +- (id)initWithRendererBlock:(void (^)(UInt32 sampleRate, UInt32 nFrames, GB_sample_t *buffer)) block andSampleRate:(UInt32) rate; @end diff --git a/AppleCommon/GBAudioClient.m b/AppleCommon/GBAudioClient.m @@ -23,7 +23,7 @@ static OSStatus render( AudioComponentInstance audioUnit; } --(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 { if (!(self = [super init])) { diff --git a/Cocoa/Document.xib b/Cocoa/Document.xib @@ -225,7 +225,7 @@ <button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="onn-R8-3vg" customClass="GBDebuggerButton"> <rect key="frame" x="102" y="26" width="26" height="26"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> - <buttonCell key="cell" type="bevel" title="Step Backwards" alternateTitle="backstep" bezelStyle="rounded" image="BackstepTemplate" imagePosition="only" alignment="center" enabled="NO" imageScaling="proportionallyDown" inset="2" id="WtK-kD-bf6"> + <buttonCell key="cell" type="bevel" title="Step Backward" alternateTitle="backstep" bezelStyle="rounded" image="BackstepTemplate" imagePosition="only" alignment="center" enabled="NO" imageScaling="proportionallyDown" inset="2" id="WtK-kD-bf6"> <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/> <font key="font" metaFont="system"/> </buttonCell> diff --git a/Core/debugger.c b/Core/debugger.c @@ -2144,7 +2144,7 @@ static const debugger_command_t commands[] = { {"step", 1, step, "Run the next instruction, stepping into function calls"}, {"finish", 1, finish, "Run until the current function returns"}, #ifndef DISABLE_REWIND - {"backstep", 5, backstep, "Step one instruction backwards, assuming constant inputs"}, + {"backstep", 5, backstep, "Step one instruction backward, assuming constant inputs"}, {"bs", 2, }, /* Alias */ #endif {"undo", 1, undo, "Revert the last command"}, diff --git a/Core/gb.c b/Core/gb.c @@ -1065,13 +1065,13 @@ exit: } /* Loading will silently stop if the format is incomplete */ -void GB_load_battery(GB_gameboy_t *gb, const char *path) +int GB_load_battery(GB_gameboy_t *gb, const char *path) { GB_ASSERT_NOT_RUNNING_OTHER_THREAD(gb) FILE *f = fopen(path, "rb"); if (!f) { - return; + return errno; } if (fread(gb->mbc_ram, 1, gb->mbc_ram_size, f) != gb->mbc_ram_size) { @@ -1090,7 +1090,7 @@ void GB_load_battery(GB_gameboy_t *gb, const char *path) /* We must reset RTC here, or it will not advance. */ goto reset_rtc; } - return; + return 0; } if (gb->cartridge_type->mbc_type == GB_HUC3) { @@ -1109,7 +1109,7 @@ void GB_load_battery(GB_gameboy_t *gb, const char *path) /* We must reset RTC here, or it will not advance. */ goto reset_rtc; } - return; + return 0; } rtc_save_t rtc_save; @@ -1174,7 +1174,7 @@ reset_rtc: } exit: fclose(f); - return; + return 0; } unsigned GB_run(GB_gameboy_t *gb) diff --git a/Core/gb.h b/Core/gb.h @@ -956,7 +956,7 @@ int GB_save_battery_to_buffer(GB_gameboy_t *gb, uint8_t *buffer, size_t size); int GB_save_battery(GB_gameboy_t *gb, const char *path); void GB_load_battery_from_buffer(GB_gameboy_t *gb, const uint8_t *buffer, size_t size); -void GB_load_battery(GB_gameboy_t *gb, const char *path); +int GB_load_battery(GB_gameboy_t *gb, const char *path); void GB_set_turbo_mode(GB_gameboy_t *gb, bool on, bool no_frame_skip); void GB_set_rendering_disabled(GB_gameboy_t *gb, bool disabled); diff --git a/JoyKit/JOYController.m b/JoyKit/JOYController.m @@ -1450,7 +1450,7 @@ typedef union { } } -- (uint8_t)LEDMaskForPlayer:(unsigned int)player +- (uint8_t)LEDMaskForPlayer:(unsigned)player { return player; } diff --git a/Makefile b/Makefile @@ -181,7 +181,7 @@ endif # These must come before the -Wno- flags WARNINGS += -Werror -Wall -Wno-unknown-warning -Wno-unknown-warning-option -Wno-missing-braces -WARNINGS += -Wno-nonnull -Wno-unused-result -Wno-multichar -Wno-int-in-bool-context -Wno-format-truncation +WARNINGS += -Wno-nonnull -Wno-unused-result -Wno-multichar -Wno-int-in-bool-context -Wno-format-truncation -Wno-nullability-completeness # Only add this flag if the compiler supports it ifeq ($(shell $(CC) -x c -c $(NULL) -o $(NULL) -Werror -Wpartial-availability 2> $(NULL); echo $$?),0) @@ -787,7 +787,7 @@ $(OBJ)/debian-binary: $(LIBDIR)/libsameboy.o: $(CORE_OBJECTS) -@$(MKDIR) -p $(dir $@) @# This is a somewhat simple hack to force Clang and GCC to build a native object file out of one or many LTO objects - echo "static const char __attribute__((used)) x=0;"| $(CC) $(filter-out -flto,$(CFLAGS)) -c -x c - -o $(OBJ)/lto_hack.o + echo "static const char __attribute__((used)) x=0;"| $(CC) $(filter-out -flto,$(CFLAGS)) $(FAT_FLAGS) -c -x c - -o $(OBJ)/lto_hack.o @# And this is a somewhat complicated hack to invoke the correct LTO-enabled LD command in a mostly cross-platform nature $(CC) $(FAT_FLAGS) $(CFLAGS) $(LIBFLAGS) $^ $(OBJ)/lto_hack.o -o $@ -@rm $(OBJ)/lto_hack.o diff --git a/SDL/configuration.h b/SDL/configuration.h @@ -151,7 +151,7 @@ typedef struct { char audio_driver[16]; /* v0.15.2 */ bool allow_background_controllers; - bool gui_pallete_enabled; // Change the GUI palette only once the user changed the DMG palette + bool gui_palette_enabled; // Change the GUI palette only once the user changed the DMG palette char dmg_palette_name[25]; hotkey_action_t hotkey_actions[2]; uint16_t agb_revision; diff --git a/SDL/gui.c b/SDL/gui.c @@ -1383,7 +1383,7 @@ static void cycle_palette(unsigned index) else { configuration.dmg_palette++; } - configuration.gui_pallete_enabled = true; + configuration.gui_palette_enabled = true; update_gui_palette(); } @@ -1414,7 +1414,7 @@ static void cycle_palette_backwards(unsigned index) else { configuration.dmg_palette--; } - configuration.gui_pallete_enabled = true; + configuration.gui_palette_enabled = true; update_gui_palette(); } @@ -2164,7 +2164,7 @@ void run_gui(bool is_running) /* Draw the background screen */ if (!converted_background) { - if (configuration.gui_pallete_enabled) { + if (configuration.gui_palette_enabled) { update_gui_palette(); } else { diff --git a/SDL/main.c b/SDL/main.c @@ -1169,7 +1169,7 @@ int main(int argc, char **argv) configuration.sgb_revision %= SGB_MAX; configuration.dmg_palette %= 5; if (configuration.dmg_palette) { - configuration.gui_pallete_enabled = true; + configuration.gui_palette_enabled = true; } configuration.border_mode %= GB_BORDER_ALWAYS + 1; configuration.rumble_mode %= GB_RUMBLE_ALL_GAMES + 1; diff --git a/iOS/GBBackgroundView.m b/iOS/GBBackgroundView.m @@ -5,14 +5,14 @@ #import "GBViewController.h" #import "GBROMManager.h" -double CGPointSquaredDistance(CGPoint a, CGPoint b) +static double CGPointSquaredDistance(CGPoint a, CGPoint b) { double deltaX = a.x - b.x; double deltaY = a.y - b.y; return deltaX * deltaX + deltaY * deltaY; } -double CGPointAngle(CGPoint a, CGPoint b) +static double CGPointAngle(CGPoint a, CGPoint b) { double deltaX = a.x - b.x; double deltaY = a.y - b.y; @@ -117,6 +117,12 @@ static GB_key_mask_t angleToKeyMask(double angle) self.usesSwipePad = self.usesSwipePad; } +- (void)setDefaultScreenLabel +{ + _screenLabel.text = @"Tap the Game Boy screen to open the menu and load a ROM from the library."; +} + + - (instancetype)initWithLayout:(GBLayout *)layout; { self = [super initWithImage:nil]; @@ -126,12 +132,12 @@ static GB_key_mask_t angleToKeyMask(double angle) _touches = [NSMutableSet set]; _screenLabel = [[UILabel alloc] initWithFrame:CGRectZero]; - _screenLabel.text = @"Tap the Game Boy screen to open the menu and load a ROM from the library."; _screenLabel.font = [UIFont systemFontOfSize:20 weight:UIFontWeightMedium]; _screenLabel.textAlignment = NSTextAlignmentCenter; _screenLabel.textColor = [UIColor whiteColor]; _screenLabel.lineBreakMode = NSLineBreakByWordWrapping; _screenLabel.numberOfLines = 0; + [self setDefaultScreenLabel]; [self addSubview:_screenLabel]; _dpadView = [[UIImageView alloc] initWithImage:[_layout.theme imageNamed:@"dpad"]]; diff --git a/iOS/GBHub.m b/iOS/GBHub.m @@ -291,7 +291,7 @@ static NSURL *StringToWebURL(NSString *string) }] resume]; } -- (unsigned int)countForTag:(NSString *)tag +- (unsigned)countForTag:(NSString *)tag { return _tags[tag].unsignedIntValue; } diff --git a/iOS/GBROMManager.m b/iOS/GBROMManager.m @@ -1,5 +1,6 @@ #import "GBROMManager.h" #import <copyfile.h> +#import <sys/stat.h> @implementation GBROMManager { diff --git a/iOS/GBROMViewController.m b/iOS/GBROMViewController.m @@ -38,7 +38,9 @@ { UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]; cell.textLabel.text = rom.lastPathComponent; - cell.accessoryType = [rom isEqualToString:[GBROMManager sharedManager].currentROM]? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone; + bool isCurrentROM = [rom isEqualToString:[GBROMManager sharedManager].currentROM]; + bool checkmark = isCurrentROM; + cell.accessoryType = checkmark? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone; NSString *pngPath = [[[GBROMManager sharedManager] autosaveStateFileForROM:rom] stringByAppendingPathExtension:@"png"]; UIGraphicsBeginImageContextWithOptions((CGSize){60, 60}, false, self.view.window.screen.scale); @@ -94,7 +96,8 @@ - (void)romSelectedAtIndex:(unsigned)index { - [GBROMManager sharedManager].currentROM = [GBROMManager sharedManager].allROMs[index]; + NSString *rom = [GBROMManager sharedManager].allROMs[index]; + [GBROMManager sharedManager].currentROM = rom; [self.presentingViewController dismissViewControllerAnimated:true completion:nil]; } @@ -286,7 +289,7 @@ contextMenuConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath forRowAtIndexPath:indexPath]; }]; deleteAction.attributes = UIMenuElementAttributesDestructive; - return [UIMenu menuWithTitle:nil children:@[ + NSMutableArray *items = @[ [UIAction actionWithTitle:@"Rename" image:[UIImage systemImageNamed:@"pencil"] identifier:nil @@ -299,8 +302,9 @@ contextMenuConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath handler:^(__kindof UIAction *action) { [self duplicateROMAtIndex:indexPath.row]; }], - deleteAction, - ]]; + ].mutableCopy; + [items addObject:deleteAction]; + return [UIMenu menuWithTitle:nil children:items]; }]; } diff --git a/iOS/GBSettingsViewController.m b/iOS/GBSettingsViewController.m @@ -351,9 +351,8 @@ static NSString const *typeLightTemp = @"typeLightTemp"; }, ]; - return @[ - @{ - @"items": @[ + + NSArray *rootItems = @[ @{ @"title": @"Emulation", @"type": typeSubmenu, @@ -384,7 +383,12 @@ static NSString const *typeLightTemp = @"typeLightTemp"; @"class": [GBThemesViewController class], @"image": [UIImage imageNamed:@"themeSettings"], }, - ] + ]; + + + return @[ + @{ + @"items": rootItems, } ]; } @@ -716,7 +720,9 @@ static id ValueForItem(NSDictionary *item) } } else if (item[@"type"] == typeRadio) { - if ([ValueForItem(item) isEqual:item[@"value"]]) { + id settingValue = ValueForItem(item); + id itemValue = item[@"value"]; + if (settingValue == itemValue || [settingValue isEqual:itemValue]) { cell.accessoryType = UITableViewCellAccessoryCheckmark; } } diff --git a/iOS/GBViewController.m b/iOS/GBViewController.m @@ -640,7 +640,10 @@ static void rumbleCallback(GB_gameboy_t *gb, double amp) - (void)saveStateToFile:(NSString *)file { - GB_save_state(&_gb, file.fileSystemRepresentation); + NSString *tempPath = [file stringByAppendingPathExtension:@"tmp"]; + if (!GB_save_state(&_gb, tempPath.UTF8String)) { + rename(tempPath.UTF8String, file.UTF8String); + } NSData *data = [NSData dataWithBytes:_gbView.previousBuffer length:GB_get_screen_width(&_gb) * GB_get_screen_height(&_gb) * diff --git a/iOS/main.m b/iOS/main.m @@ -11,7 +11,7 @@ int main(int argc, char * argv[]) @"GBColorCorrection": @(GB_COLOR_CORRECTION_MODERN_BALANCED), @"GBAudioMode": @"switch", @"GBHighpassFilter": @(GB_HIGHPASS_ACCURATE), - @"GBRewindLength": @(120), + @"GBRewindLength": @120, @"GBFrameBlendingMode": @(GB_FRAME_BLENDING_MODE_ACCURATE), @"GBDMGModel": @(GB_MODEL_DMG_B),
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.