git.y1.nz

SameBoy

Accurate GB/GBC emulator
download: https://git.y1.nz/archives/sameboy.tar.gz
README | Files | Log | Refs | LICENSE

commit 60ff8577bb43a638c97646efc6de836b0237d265
parent a3128d89c0ceb95b198d8ffdd4e6da94a99f2a99
Author: Lior Halphon <LIJI32@gmail.com>
Date:   Tue, 11 Jun 2024 17:43:26 +0300

Allow user-provided boot ROMs in iOS

Diffstat:
MCocoa/Document.m30+++++++++++++++---------------
MiOS/GBROMManager.m1+
MiOS/GBSettingsViewController.m25+++++++++++++++++++++++++
MiOS/GBViewController.m34+++++++++++++++++++++++++++++++++-
4 files changed, 74 insertions(+), 16 deletions(-)

diff --git a/Cocoa/Document.m b/Cocoa/Document.m @@ -255,21 +255,6 @@ static void debuggerReloadCallback(GB_gameboy_t *gb) return self; } -- (NSString *)bootROMPathForName:(NSString *)name -{ - NSURL *url = [[NSUserDefaults standardUserDefaults] URLForKey:@"GBBootROMsFolder"]; - if (url) { - NSString *path = [url path]; - path = [path stringByAppendingPathComponent:name]; - path = [path stringByAppendingPathExtension:@"bin"]; - if ([[NSFileManager defaultManager] fileExistsAtPath:path]) { - return path; - } - } - - return [[NSBundle mainBundle] pathForResource:name ofType:@"bin"]; -} - - (GB_model_t)internalModel { switch (_currentModel) { @@ -647,6 +632,21 @@ static unsigned *multiplication_table_for_frequency(unsigned frequency) GB_debugger_set_disabled(&_gb, false); } +- (NSString *)bootROMPathForName:(NSString *)name +{ + NSURL *url = [[NSUserDefaults standardUserDefaults] URLForKey:@"GBBootROMsFolder"]; + if (url) { + NSString *path = [url path]; + path = [path stringByAppendingPathComponent:name]; + path = [path stringByAppendingPathExtension:@"bin"]; + if ([[NSFileManager defaultManager] fileExistsAtPath:path]) { + return path; + } + } + + return [[NSBundle mainBundle] pathForResource:name ofType:@"bin"]; +} + - (void)loadBootROM: (GB_boot_rom_t)type { static NSString *const names[] = { diff --git a/iOS/GBROMManager.m b/iOS/GBROMManager.m @@ -59,6 +59,7 @@ - (NSString *)romFileForROM:(NSString *)rom { if ([rom isEqualToString:@"Inbox"]) return nil; + if ([rom isEqualToString:@"Boot ROMs"]) return nil; if (rom == _currentROM) { return self.romFile; } diff --git a/iOS/GBSettingsViewController.m b/iOS/GBSettingsViewController.m @@ -164,6 +164,31 @@ static NSString const *typeLightTemp = @"typeLightTemp"; } }, @{ + @"header": @"Boot ROMs", + @"items": @[ + @{@"type": typeRadio, @"pref": @"GBCustomBootROMs", @"title": @"Use Built-in Boot ROMs", @"value": @NO,}, + @{@"type": typeRadio, @"pref": @"GBCustomBootROMs", @"title": @"Use Boot ROMs from Files", @"value": @YES,}, + @{@"type": typeBlock, @"title": @"Open Boot ROMs Folder", @"block": ^bool(GBSettingsViewController *controller) { + + NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0]; + path = [path stringByAppendingPathComponent:@"Boot ROMs"]; + [[NSFileManager defaultManager] createDirectoryAtPath:path + withIntermediateDirectories:true + attributes:nil + error:nil]; + + + [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"shareddocuments://%@", [path stringByReplacingOccurrencesOfString:@" " + withString:@"%20"]]] + options:nil + completionHandler:nil]; + + return false; + }}, + ], + @"footer": @"Put your boot ROM files (dmg_boot.bin, cgb_boot.bin, etc.) in the Boot ROMs folder to use them" + }, + @{ @"header": @"Emulated Revisions", @"items": @[ QUICK_SUBMENU(@"Game Boy", @[ diff --git a/iOS/GBViewController.m b/iOS/GBViewController.m @@ -965,6 +965,23 @@ didReceiveNotificationResponse:(UNNotificationResponse *)response [_audioLock unlock]; } } + + +- (NSString *)bootROMPathForName:(NSString *)name +{ + if ([[NSUserDefaults standardUserDefaults] boolForKey:@"GBCustomBootROMs"]) { + NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0]; + path = [path stringByAppendingPathComponent:@"Boot ROMs"]; + path = [path stringByAppendingPathComponent:name]; + path = [path stringByAppendingPathExtension:@"bin"]; + if ([[NSFileManager defaultManager] fileExistsAtPath:path]) { + return path; + } + } + + return [[NSBundle mainBundle] pathForResource:name ofType:@"bin"]; +} + - (void)loadBootROM: (GB_boot_rom_t)type { static NSString *const names[] = { @@ -975,9 +992,24 @@ didReceiveNotificationResponse:(UNNotificationResponse *)response [GB_BOOT_ROM_SGB2] = @"sgb2_boot", [GB_BOOT_ROM_CGB_0] = @"cgb0_boot", [GB_BOOT_ROM_CGB] = @"cgb_boot", + [GB_BOOT_ROM_CGB_E] = @"cgbE_boot", + [GB_BOOT_ROM_AGB_0] = @"agb0_boot", [GB_BOOT_ROM_AGB] = @"agb_boot", }; - GB_load_boot_rom(&_gb, [[[NSBundle mainBundle] pathForResource:names[type] ofType:@"bin"] UTF8String]); + NSString *name = names[type]; + NSString *path = [self bootROMPathForName:name]; + /* These boot types are not commonly available, and they are indentical + from an emulator perspective, so fall back to the more common variants + if they can't be found. */ + if (!path && type == GB_BOOT_ROM_CGB_E) { + [self loadBootROM:GB_BOOT_ROM_CGB]; + return; + } + if (!path && type == GB_BOOT_ROM_AGB_0) { + [self loadBootROM:GB_BOOT_ROM_AGB]; + return; + } + GB_load_boot_rom(&_gb, [path UTF8String]); } - (void)vblankWithType:(GB_vblank_type_t)type

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.