mirror of https://github.com/LIJI32/SameBoy.git
Allow user-provided boot ROMs in iOS
This commit is contained in:
parent
a3128d89c0
commit
60ff8577bb
|
@ -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[] = {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -163,6 +163,31 @@ static NSString const *typeLightTemp = @"typeLightTemp";
|
|||
return @"";
|
||||
}
|
||||
},
|
||||
@{
|
||||
@"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": @[
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue