2013-08-14 14:07:36 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2013 - Jason Fetters
|
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#import "RetroArch_Apple.h"
|
|
|
|
#include "rarch_wrapper.h"
|
|
|
|
|
2013-09-05 05:20:56 +00:00
|
|
|
#include "apple/common/apple_input.h"
|
2013-11-22 14:30:02 +00:00
|
|
|
#include "apple/common/setting_data.h"
|
|
|
|
#include "menu.h"
|
2013-08-14 14:07:36 +00:00
|
|
|
|
|
|
|
#import "views.h"
|
2013-09-05 05:20:56 +00:00
|
|
|
#include "bluetooth/btpad.h"
|
|
|
|
#include "bluetooth/btdynamic.h"
|
|
|
|
#include "bluetooth/btpad.h"
|
2013-08-14 14:07:36 +00:00
|
|
|
|
|
|
|
#include "file.h"
|
|
|
|
|
2013-12-04 00:24:01 +00:00
|
|
|
apple_frontend_settings_t apple_frontend_settings;
|
|
|
|
|
2013-08-14 14:07:36 +00:00
|
|
|
//#define HAVE_DEBUG_FILELOG
|
2013-10-03 21:43:41 +00:00
|
|
|
bool is_ios_7()
|
2013-08-15 16:47:13 +00:00
|
|
|
{
|
2013-10-03 21:43:41 +00:00
|
|
|
return [[UIDevice currentDevice].systemVersion compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending;
|
2013-09-20 21:49:18 +00:00
|
|
|
}
|
|
|
|
|
2013-10-03 21:43:41 +00:00
|
|
|
void ios_set_bluetooth_mode(NSString* mode)
|
2013-09-20 21:49:18 +00:00
|
|
|
{
|
2013-10-03 21:43:41 +00:00
|
|
|
if (!is_ios_7())
|
|
|
|
{
|
|
|
|
apple_input_enable_icade([mode isEqualToString:@"icade"]);
|
|
|
|
btstack_set_poweron([mode isEqualToString:@"btstack"]);
|
|
|
|
}
|
|
|
|
#ifdef __IPHONE_7_0 // iOS7 iCade Support
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool enabled = [mode isEqualToString:@"icade"];
|
|
|
|
apple_input_enable_icade(enabled);
|
|
|
|
[[RAGameView get] iOS7SetiCadeMode:enabled];
|
|
|
|
}
|
|
|
|
#endif
|
2013-08-15 16:47:13 +00:00
|
|
|
}
|
2013-08-14 14:07:36 +00:00
|
|
|
|
2013-12-04 00:24:01 +00:00
|
|
|
const void* apple_get_frontend_settings(void)
|
|
|
|
{
|
2013-12-04 00:46:30 +00:00
|
|
|
static rarch_setting_t settings[8];
|
2013-12-04 00:24:01 +00:00
|
|
|
|
|
|
|
if (settings[0].type == ST_NONE)
|
|
|
|
{
|
2013-12-04 00:46:30 +00:00
|
|
|
settings[0] = setting_data_group_setting(ST_GROUP, "Frontend Settings");
|
|
|
|
settings[1] = setting_data_group_setting(ST_SUB_GROUP, "Frontend");
|
|
|
|
settings[2] = setting_data_bool_setting("ios_use_file_log", "Enable File Logging",
|
2013-12-04 00:24:01 +00:00
|
|
|
&apple_frontend_settings.logging_enabled, false);
|
2013-12-04 00:46:30 +00:00
|
|
|
settings[3] = setting_data_bool_setting("ios_tv_mode", "TV Mode", &apple_use_tv_mode, false);
|
|
|
|
settings[4] = setting_data_string_setting(ST_STRING, "ios_btmode", "Bluetooth Input Type", apple_frontend_settings.bluetooth_mode,
|
2013-12-04 00:24:01 +00:00
|
|
|
sizeof(apple_frontend_settings.bluetooth_mode), "keyboard");
|
2013-12-04 00:46:30 +00:00
|
|
|
settings[4].values = "icade|keyboard|btstack";
|
|
|
|
settings[5] = setting_data_string_setting(ST_STRING, "ios_orientations", "Screen Orientations", apple_frontend_settings.orientations,
|
|
|
|
sizeof(apple_frontend_settings.orientations), "both");
|
|
|
|
settings[5].values = "both|landscape|portrait";
|
|
|
|
settings[6] = setting_data_group_setting(ST_END_SUB_GROUP, 0);
|
2013-12-04 00:24:01 +00:00
|
|
|
|
2013-12-04 00:46:30 +00:00
|
|
|
settings[7] = setting_data_group_setting(ST_END_GROUP, 0);
|
2013-12-04 00:24:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return settings;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ios_set_logging_state(const char *log_path, bool on)
|
|
|
|
{
|
|
|
|
fflush(stdout);
|
|
|
|
fflush(stderr);
|
|
|
|
|
|
|
|
if (on && !apple_frontend_settings.logging.file)
|
|
|
|
{
|
|
|
|
apple_frontend_settings.logging.file = fopen(log_path, "a");
|
|
|
|
apple_frontend_settings.logging.stdout = dup(1);
|
|
|
|
apple_frontend_settings.logging.stderr = dup(2);
|
|
|
|
dup2(fileno(apple_frontend_settings.logging.file), 1);
|
|
|
|
dup2(fileno(apple_frontend_settings.logging.file), 2);
|
|
|
|
}
|
|
|
|
else if (!on && apple_frontend_settings.logging.file)
|
|
|
|
{
|
|
|
|
dup2(apple_frontend_settings.logging.stdout, 1);
|
|
|
|
dup2(apple_frontend_settings.logging.stderr, 2);
|
|
|
|
|
|
|
|
fclose(apple_frontend_settings.logging.file);
|
|
|
|
apple_frontend_settings.logging.file = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-14 14:07:36 +00:00
|
|
|
// Input helpers: This is kept here because it needs objective-c
|
|
|
|
static void handle_touch_event(NSArray* touches)
|
|
|
|
{
|
|
|
|
const int numTouches = [touches count];
|
|
|
|
const float scale = [[UIScreen mainScreen] scale];
|
|
|
|
|
|
|
|
g_current_input_data.touch_count = 0;
|
|
|
|
|
|
|
|
for(int i = 0; i != numTouches && g_current_input_data.touch_count < MAX_TOUCHES; i ++)
|
|
|
|
{
|
|
|
|
UITouch* touch = [touches objectAtIndex:i];
|
|
|
|
const CGPoint coord = [touch locationInView:touch.view];
|
|
|
|
|
|
|
|
if (touch.phase != UITouchPhaseEnded && touch.phase != UITouchPhaseCancelled)
|
|
|
|
{
|
|
|
|
g_current_input_data.touches[g_current_input_data.touch_count ].screen_x = coord.x * scale;
|
|
|
|
g_current_input_data.touches[g_current_input_data.touch_count ++].screen_y = coord.y * scale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@interface RApplication : UIApplication
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RApplication
|
|
|
|
|
|
|
|
- (void)sendEvent:(UIEvent *)event
|
|
|
|
{
|
|
|
|
[super sendEvent:event];
|
|
|
|
|
|
|
|
if ([[event allTouches] count])
|
|
|
|
handle_touch_event(event.allTouches.allObjects);
|
|
|
|
else if ([event respondsToSelector:@selector(_gsEvent)])
|
2013-09-20 23:04:04 +00:00
|
|
|
{
|
2013-08-14 14:07:36 +00:00
|
|
|
// Stolen from: http://nacho4d-nacho4d.blogspot.com/2012/01/catching-keyboard-events-in-ios.html
|
|
|
|
uint8_t* eventMem = (uint8_t*)(void*)CFBridgingRetain([event performSelector:@selector(_gsEvent)]);
|
|
|
|
int eventType = eventMem ? *(int*)&eventMem[8] : 0;
|
|
|
|
|
|
|
|
if (eventType == GSEVENT_TYPE_KEYDOWN || eventType == GSEVENT_TYPE_KEYUP)
|
|
|
|
apple_input_handle_key_event(*(uint16_t*)&eventMem[0x3C], eventType == GSEVENT_TYPE_KEYDOWN);
|
|
|
|
|
|
|
|
CFBridgingRelease(eventMem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-20 21:49:18 +00:00
|
|
|
#ifdef __IPHONE_7_0 // iOS7 iCade Support
|
|
|
|
|
|
|
|
- (NSArray*)keyCommands
|
|
|
|
{
|
|
|
|
static NSMutableArray* key_commands;
|
|
|
|
|
|
|
|
if (!key_commands)
|
|
|
|
{
|
|
|
|
key_commands = [NSMutableArray array];
|
|
|
|
|
2013-11-22 14:30:02 +00:00
|
|
|
for (int i = 0; i < 26; i ++)
|
2013-09-20 21:49:18 +00:00
|
|
|
{
|
|
|
|
[key_commands addObject:[UIKeyCommand keyCommandWithInput:[NSString stringWithFormat:@"%c", 'a' + i]
|
|
|
|
modifierFlags:0 action:@selector(keyGotten:)]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return key_commands;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)keyGotten:(UIKeyCommand *)keyCommand
|
|
|
|
{
|
|
|
|
apple_input_handle_key_event([keyCommand.input characterAtIndex:0] - 'a' + 4, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2013-08-14 14:07:36 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RetroArch_iOS
|
|
|
|
{
|
|
|
|
UIWindow* _window;
|
2013-08-25 00:27:04 +00:00
|
|
|
NSString* _path;
|
2013-08-14 14:07:36 +00:00
|
|
|
|
2013-11-22 14:30:02 +00:00
|
|
|
bool _isGameTop;
|
2013-08-14 14:07:36 +00:00
|
|
|
uint32_t _enabledOrientations;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (RetroArch_iOS*)get
|
|
|
|
{
|
|
|
|
return (RetroArch_iOS*)[[UIApplication sharedApplication] delegate];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark LIFECYCLE (UIApplicationDelegate)
|
|
|
|
- (void)applicationDidFinishLaunching:(UIApplication *)application
|
|
|
|
{
|
|
|
|
apple_platform = self;
|
|
|
|
self.delegate = self;
|
|
|
|
|
|
|
|
// Setup window
|
|
|
|
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
|
|
|
_window.rootViewController = self;
|
|
|
|
[_window makeKeyAndVisible];
|
|
|
|
|
|
|
|
// Build system paths and test permissions
|
|
|
|
self.documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
|
|
|
|
self.systemDirectory = [self.documentsDirectory stringByAppendingPathComponent:@".RetroArch"];
|
|
|
|
self.systemConfigPath = [self.systemDirectory stringByAppendingPathComponent:@"frontend.cfg"];
|
2013-09-09 23:25:34 +00:00
|
|
|
|
|
|
|
self.configDirectory = self.systemDirectory;
|
|
|
|
self.globalConfigFile = [NSString stringWithFormat:@"%@/retroarch.cfg", self.configDirectory];
|
|
|
|
self.coreDirectory = [NSBundle.mainBundle.bundlePath stringByAppendingPathComponent:@"modules"];
|
2013-11-22 14:30:02 +00:00
|
|
|
self.logPath = [self.systemDirectory stringByAppendingPathComponent:@"stdout.log"];
|
2013-11-22 00:56:54 +00:00
|
|
|
|
|
|
|
const char *path = self.documentsDirectory.UTF8String;
|
|
|
|
path_mkdir(path);
|
|
|
|
if (access(path, 0755) != 0)
|
2013-08-14 14:07:36 +00:00
|
|
|
apple_display_alert([NSString stringWithFormat:@"Failed to create or access base directory: %@", self.documentsDirectory], 0);
|
2013-11-22 00:56:54 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
path = self.systemDirectory.UTF8String;
|
|
|
|
path_mkdir(path);
|
|
|
|
if (access(path, 0755) != 0)
|
|
|
|
apple_display_alert([NSString stringWithFormat:@"Failed to create or access system directory: %@", self.systemDirectory], 0);
|
|
|
|
else
|
2013-11-22 14:30:02 +00:00
|
|
|
[self pushViewController:[RAMainMenu new] animated:YES];
|
2013-11-22 00:56:54 +00:00
|
|
|
}
|
2013-08-14 14:07:36 +00:00
|
|
|
|
|
|
|
// Warn if there are no cores present
|
2013-11-22 14:30:02 +00:00
|
|
|
apple_core_info_set_core_path(self.coreDirectory.UTF8String);
|
|
|
|
apple_core_info_set_config_path(self.configDirectory.UTF8String);
|
|
|
|
const core_info_list_t* core_list = apple_core_info_list_get();
|
|
|
|
|
|
|
|
if (!core_list || core_list->count == 0)
|
2013-11-29 15:39:47 +00:00
|
|
|
apple_display_alert(@"No libretro cores were found. You will not be able to run any content.", 0);
|
2013-08-14 14:07:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)applicationDidBecomeActive:(UIApplication *)application
|
|
|
|
{
|
2013-09-10 23:29:49 +00:00
|
|
|
apple_exit_stasis(false);
|
2013-08-14 14:07:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)applicationWillResignActive:(UIApplication *)application
|
|
|
|
{
|
2013-08-15 13:50:22 +00:00
|
|
|
apple_enter_stasis();
|
2013-08-14 14:07:36 +00:00
|
|
|
}
|
|
|
|
|
2013-08-25 00:27:04 +00:00
|
|
|
#pragma mark Frontend Browsing Logic
|
2013-09-20 23:04:04 +00:00
|
|
|
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
|
|
|
|
{
|
|
|
|
NSString* filename = url.path.lastPathComponent;
|
|
|
|
|
|
|
|
NSError* error = nil;
|
|
|
|
[NSFileManager.defaultManager moveItemAtPath:url.path toPath:[self.documentsDirectory stringByAppendingPathComponent:filename] error:&error];
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
printf("%s\n", error.description.UTF8String);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-14 14:07:36 +00:00
|
|
|
// UINavigationControllerDelegate
|
|
|
|
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
|
|
|
|
{
|
2013-11-22 14:30:02 +00:00
|
|
|
apple_input_reset_icade_buttons();
|
2013-08-14 14:07:36 +00:00
|
|
|
_isGameTop = [viewController isKindOfClass:[RAGameView class]];
|
2013-11-22 14:30:02 +00:00
|
|
|
g_extern.is_paused = !_isGameTop;
|
|
|
|
|
2013-08-14 14:07:36 +00:00
|
|
|
|
|
|
|
[[UIApplication sharedApplication] setStatusBarHidden:_isGameTop withAnimation:UIStatusBarAnimationNone];
|
|
|
|
[[UIApplication sharedApplication] setIdleTimerDisabled:_isGameTop];
|
|
|
|
|
2013-11-22 14:30:02 +00:00
|
|
|
[self setNavigationBarHidden:_isGameTop animated:!_isGameTop];
|
|
|
|
[self setToolbarHidden:!viewController.toolbarItems.count animated:YES];
|
2013-08-14 14:07:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: This version only runs on iOS6
|
|
|
|
- (NSUInteger)supportedInterfaceOrientations
|
|
|
|
{
|
|
|
|
return _isGameTop ? _enabledOrientations
|
|
|
|
: UIInterfaceOrientationMaskAll;
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: This version runs on iOS2-iOS5, but not iOS6
|
|
|
|
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
|
|
|
|
{
|
|
|
|
if (_isGameTop)
|
|
|
|
switch (interfaceOrientation)
|
|
|
|
{
|
|
|
|
case UIInterfaceOrientationPortrait:
|
|
|
|
return (_enabledOrientations & UIInterfaceOrientationMaskPortrait);
|
|
|
|
case UIInterfaceOrientationPortraitUpsideDown:
|
|
|
|
return (_enabledOrientations & UIInterfaceOrientationMaskPortraitUpsideDown);
|
|
|
|
case UIInterfaceOrientationLandscapeLeft:
|
|
|
|
return (_enabledOrientations & UIInterfaceOrientationMaskLandscapeLeft);
|
|
|
|
case UIInterfaceOrientationLandscapeRight:
|
|
|
|
return (_enabledOrientations & UIInterfaceOrientationMaskLandscapeRight);
|
|
|
|
}
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark RetroArch_Platform
|
2013-11-22 14:30:02 +00:00
|
|
|
- (void)loadingCore:(NSString*)core withFile:(const char*)file
|
2013-08-14 14:07:36 +00:00
|
|
|
{
|
|
|
|
[self pushViewController:RAGameView.get animated:NO];
|
2013-11-22 14:30:02 +00:00
|
|
|
(void)[[RACoreSettingsMenu alloc] initWithCore:core];
|
2013-08-14 14:07:36 +00:00
|
|
|
|
|
|
|
btpad_set_inquiry_state(false);
|
|
|
|
|
|
|
|
[self refreshSystemConfig];
|
|
|
|
}
|
|
|
|
|
2013-11-22 14:30:02 +00:00
|
|
|
- (void)unloadingCore:(NSString*)core
|
2013-08-14 14:07:36 +00:00
|
|
|
{
|
|
|
|
[self popToViewController:[RAGameView get] animated:NO];
|
|
|
|
[self popViewControllerAnimated:NO];
|
|
|
|
|
|
|
|
btpad_set_inquiry_state(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark FRONTEND CONFIG
|
|
|
|
- (void)refreshSystemConfig
|
|
|
|
{
|
2013-11-22 14:30:02 +00:00
|
|
|
const rarch_setting_t* frontend_settings = apple_get_frontend_settings();
|
|
|
|
|
|
|
|
setting_data_reset(frontend_settings);
|
|
|
|
setting_data_load_config_path(frontend_settings, self.systemConfigPath.UTF8String);
|
2013-08-14 14:07:36 +00:00
|
|
|
|
2013-09-20 19:14:38 +00:00
|
|
|
// Get enabled orientations
|
2013-12-04 00:46:30 +00:00
|
|
|
_enabledOrientations = UIInterfaceOrientationMaskAll;
|
2013-08-14 14:07:36 +00:00
|
|
|
|
2013-12-04 00:46:30 +00:00
|
|
|
if (strcmp(apple_frontend_settings.orientations, "landscape") == 0)
|
|
|
|
_enabledOrientations = UIInterfaceOrientationMaskLandscape;
|
|
|
|
else if (strcmp(apple_frontend_settings.orientations, "portrait") == 0)
|
|
|
|
_enabledOrientations = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
|
2013-08-14 14:07:36 +00:00
|
|
|
|
2013-11-22 14:30:02 +00:00
|
|
|
// Set bluetooth mode
|
|
|
|
ios_set_bluetooth_mode(@(apple_frontend_settings.bluetooth_mode));
|
2013-11-29 18:31:39 +00:00
|
|
|
ios_set_logging_state([RetroArch_iOS get].logPath.UTF8String, apple_frontend_settings.logging_enabled);
|
2013-08-14 14:07:36 +00:00
|
|
|
}
|
|
|
|
|
2013-11-22 14:30:02 +00:00
|
|
|
- (IBAction)showPauseMenu:(id)sender
|
2013-08-14 14:07:36 +00:00
|
|
|
{
|
2013-11-22 14:30:02 +00:00
|
|
|
[self pushViewController:[RAPauseMenu new] animated:YES];
|
2013-08-14 14:07:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
@autoreleasepool {
|
|
|
|
return UIApplicationMain(argc, argv, NSStringFromClass([RApplication class]), NSStringFromClass([RetroArch_iOS class]));
|
|
|
|
}
|
|
|
|
}
|