Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Classes/ControlPadEventDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// ControlPadEventDelegate.h
// SNES4iOS
//
// Created by Shawn Allen on 9/28/12.
//
//

#import <Foundation/Foundation.h>

typedef enum ControlPadState {
ControlPadStateNone = 0x000,
ControlPadStateUp = 0x001,
ControlPadStateRight = 0x002,
ControlPadStateDown = 0x004,
ControlPadStateLeft = 0x008,

ControlPadStateUpRight = ControlPadStateUp | ControlPadStateRight,
ControlPadStateDownRight = ControlPadStateDown | ControlPadStateRight,
ControlPadStateUpLeft = ControlPadStateUp | ControlPadStateLeft,
ControlPadStateDownLeft = ControlPadStateDown | ControlPadStateLeft,

ControlPadStateButtonA = 0x010,
ControlPadStateButtonB = 0x020,
ControlPadStateButtonC = 0x040,
ControlPadStateButtonD = 0x080,
ControlPadStateButtonE = 0x100,
ControlPadStateButtonF = 0x200,
ControlPadStateButtonG = 0x400,
ControlPadStateButtonH = 0x800,

} ControlPadState;

@protocol ControlPadEventDelegate <NSObject>

@required
- (void)padChangedState:(ControlPadState)changedState pressed:(BOOL)pressed;

@end
3 changes: 2 additions & 1 deletion Classes/ControlPadManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@

#import <Foundation/Foundation.h>
#import <GameKit/GameKit.h>
#import "ControlPadEventDelegate.h"

#define MAX_CONTROL_PADS 4

extern unsigned long padStatusForPadNumber(int which);

@interface ControlPadManager : NSObject <GKSessionDelegate> {
@interface ControlPadManager : NSObject <GKSessionDelegate, ControlPadEventDelegate> {
GKSession *gkSession;

NSMutableArray *controlPadPeerIDs;
Expand Down
82 changes: 82 additions & 0 deletions Classes/ControlPadManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,88 @@ - (void) denyPendingConnection
self.pendingConnectionPeerID = nil;
}

#pragma mark -
#pragma mark ControlPadEventDelegate

enum { GP2X_UP=0x1, GP2X_LEFT=0x4, GP2X_DOWN=0x10, GP2X_RIGHT=0x40,
GP2X_START=1<<8, GP2X_SELECT=1<<9, GP2X_L=1<<10, GP2X_R=1<<11,
GP2X_A=1<<12, GP2X_B=1<<13, GP2X_X=1<<14, GP2X_Y=1<<15,
GP2X_VOL_UP=1<<23, GP2X_VOL_DOWN=1<<22, GP2X_PUSH=1<<27 };

- (void)padChangedState:(ControlPadState)changedState pressed:(BOOL)pressed;
{
static unsigned long padState = 0;

unsigned long stateInGP2XValue = 0;

/*
A SELECT
B LEFT SHOULDER
C START
D RIGHT SHOULDER
E Y
F A
G B
H X
*/

switch (changedState) {
case ControlPadStateNone:
stateInGP2XValue = 0;
break;
case ControlPadStateUp:
stateInGP2XValue = GP2X_UP;
break;
case ControlPadStateDown:
stateInGP2XValue = GP2X_DOWN;
break;
case ControlPadStateLeft:
stateInGP2XValue = GP2X_LEFT;
break;
case ControlPadStateRight:
stateInGP2XValue = GP2X_RIGHT;
break;
case ControlPadStateButtonA:
stateInGP2XValue = GP2X_SELECT;
break;
case ControlPadStateButtonB:
stateInGP2XValue = GP2X_L;
break;
case ControlPadStateButtonC:
stateInGP2XValue = GP2X_START;
break;
case ControlPadStateButtonD:
stateInGP2XValue = GP2X_R;
break;
case ControlPadStateButtonE:
stateInGP2XValue = GP2X_Y;
break;
case ControlPadStateButtonF:
stateInGP2XValue = GP2X_A;
break;
case ControlPadStateButtonG:
stateInGP2XValue = GP2X_B;
break;
case ControlPadStateButtonH:
stateInGP2XValue = GP2X_X;
break;
case ControlPadStateDownLeft:
case ControlPadStateDownRight:
case ControlPadStateUpLeft:
case ControlPadStateUpRight:
default:
NSLog(@"%s Compound pad movement sent, but was unhandled.", __PRETTY_FUNCTION__);
break;
}

if (pressed)
padState |= stateInGP2XValue;
else
padState ^= stateInGP2XValue;

[self convertData:[NSData dataWithBytes:&padState length:sizeof(padState)] padNumber:0];
}

#pragma mark -
#pragma mark GKSession Delegate methods
- (void)session:(GKSession *)session peer:(NSString *)peerID didChangeState:(GKPeerConnectionState)state {
Expand Down
2 changes: 2 additions & 0 deletions Classes/SNES4iOSAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "SNESControllerAppDelegate.h"
#import "SNESControllerViewController.h"

@class iCadeViewController;
@class EmulationViewController;
@class RomSelectionViewController;
@class RomDetailViewController;
Expand Down Expand Up @@ -46,6 +47,7 @@
@property (nonatomic, strong) ControlPadManager *controlPadManager;

@property (nonatomic, strong) EmulationViewController *emulationViewController;
@property (nonatomic, strong) iCadeViewController *iCadeViewController;
@property (nonatomic, strong) WebBrowserViewController *webViewController;
@property (nonatomic, strong) UINavigationController *webNavController;
@property (strong, nonatomic) UITabBarController *tabBarController;
Expand Down
7 changes: 6 additions & 1 deletion Classes/SNES4iOSAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ @implementation SNES4iOSAppDelegate
@synthesize window, splitViewController, romSelectionViewController, romDetailViewController, settingsViewController;
@synthesize controlPadConnectViewController, controlPadManager;
@synthesize romDirectoryPath, saveDirectoryPath, snapshotDirectoryPath;
@synthesize emulationViewController, webViewController, webNavController;
@synthesize emulationViewController, iCadeViewController, webViewController, webNavController;
@synthesize tabBarController;
@synthesize snesControllerAppDelegate, snesControllerViewController;
@synthesize sramDirectoryPath;
Expand Down Expand Up @@ -69,6 +69,11 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
// Make the main emulator view controller
emulationViewController = [[EmulationViewController alloc] init];
emulationViewController.view.hidden = YES;

// Construct and attach the iCade view controller into the emulation view controller's view hierarchy
[self setICadeViewController:[[iCadeViewController alloc] init]];
[[[self emulationViewController] view] addSubview:[[self iCadeViewController] view]];
[[self iCadeViewController] setDelegate:[self controlPadManager]];

// Make the web browser view controller
webViewController = [[WebBrowserViewController alloc] initWithNibName:@"WebBrowserViewController" bundle:nil];
Expand Down
17 changes: 17 additions & 0 deletions Classes/iCadeViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// iCadeViewController.h
// SNES4iOS
//
// Created by Shawn Allen on 9/28/12.
//
//

#import <UIKit/UIKit.h>
#import "iCadeReaderView.h"
#import "ControlPadEventDelegate.h"

@interface iCadeViewController : UIViewController<iCadeEventDelegate>

@property (nonatomic, weak) IBOutlet id<ControlPadEventDelegate> delegate;

@end
95 changes: 95 additions & 0 deletions Classes/iCadeViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//
// iCadeViewController.m
// SNES4iOS
//
// Created by Shawn Allen on 9/28/12.
//
//

#import "iCadeViewController.h"

@interface iCadeViewController ()

- (void)setState:(BOOL)state forButton:(iCadeState)button;

@end

@implementation iCadeViewController

#pragma mark -
#pragma mark Class extension

- (void)setState:(BOOL)state forButton:(iCadeState)button;
{
ControlPadState padButton = ControlPadStateNone;

switch (button) {
case iCadeButtonA:
padButton = ControlPadStateButtonA;
break;
case iCadeButtonB:
padButton = ControlPadStateButtonB;
break;
case iCadeButtonC:
padButton = ControlPadStateButtonC;
break;
case iCadeButtonD:
padButton = ControlPadStateButtonD;
break;
case iCadeButtonE:
padButton = ControlPadStateButtonE;
break;
case iCadeButtonF:
padButton = ControlPadStateButtonF;
break;
case iCadeButtonG:
padButton = ControlPadStateButtonG;
break;
case iCadeButtonH:
padButton = ControlPadStateButtonH;
break;
case iCadeJoystickUp:
padButton = ControlPadStateUp;
break;
case iCadeJoystickRight:
padButton = ControlPadStateRight;
break;
case iCadeJoystickDown:
padButton = ControlPadStateDown;
break;
case iCadeJoystickLeft:
padButton = ControlPadStateLeft;
break;
default:
break;
}

[[self delegate] padChangedState:padButton pressed:state];
}

#pragma mark -
#pragma mark UIViewController

- (void)viewDidLoad
{
[super viewDidLoad];
iCadeReaderView *control = [[iCadeReaderView alloc] initWithFrame:CGRectZero];
[[self view] addSubview:control];
[control setActive:YES];
[control setDelegate:self];
}

#pragma mark -
#pragma mark iCadeEventDelegate

- (void)buttonDown:(iCadeState)button;
{
[self setState:YES forButton:button];
}

- (void)buttonUp:(iCadeState)button;
{
[self setState:NO forButton:button];
}

@end
32 changes: 32 additions & 0 deletions SNES4iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
2804200B108E984D000629CD /* RomSelectionViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 28042008108E984D000629CD /* RomSelectionViewController.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
2804200C108E984D000629CD /* RomDetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2804200A108E984D000629CD /* RomDetailViewController.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
2892E4100DC94CBA00A64D0F /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2892E40F0DC94CBA00A64D0F /* CoreGraphics.framework */; };
520D7C3E1618A9C4009306B7 /* iCadeReaderView.m in Sources */ = {isa = PBXBuildFile; fileRef = 520D7C3C1618A9C4009306B7 /* iCadeReaderView.m */; };
520D7C441618AA10009306B7 /* iCadeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 520D7C431618AA10009306B7 /* iCadeViewController.m */; };
6C3CE6EB135BCD0400D61F53 /* IOSurface.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6C3CE6EA135BCD0400D61F53 /* IOSurface.framework */; };
6CD00F45135FED04003E789A /* libpocketsnes.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6CD00F44135FED04003E789A /* libpocketsnes.a */; };
6CD00F60135FEE9C003E789A /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6CD00F5F135FEE9C003E789A /* AudioToolbox.framework */; };
Expand Down Expand Up @@ -99,6 +101,12 @@
2892E40F0DC94CBA00A64D0F /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
28A0AAE50D9B0CCF005BE974 /* SNES4iOS_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SNES4iOS_Prefix.pch; sourceTree = "<group>"; };
29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
520D7C3B1618A9C4009306B7 /* iCadeReaderView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = iCadeReaderView.h; sourceTree = "<group>"; };
520D7C3C1618A9C4009306B7 /* iCadeReaderView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = iCadeReaderView.m; sourceTree = "<group>"; };
520D7C3D1618A9C4009306B7 /* iCadeState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = iCadeState.h; sourceTree = "<group>"; };
520D7C411618AA10009306B7 /* ControlPadEventDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ControlPadEventDelegate.h; sourceTree = "<group>"; };
520D7C421618AA10009306B7 /* iCadeViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = iCadeViewController.h; sourceTree = "<group>"; };
520D7C431618AA10009306B7 /* iCadeViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = iCadeViewController.m; sourceTree = "<group>"; };
6C3CE6EA135BCD0400D61F53 /* IOSurface.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOSurface.framework; path = System/Library/PrivateFrameworks/IOSurface.framework; sourceTree = SDKROOT; };
6CD00F44135FED04003E789A /* libpocketsnes.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libpocketsnes.a; path = src/snes4iphone_src/libpocketsnes.a; sourceTree = "<group>"; };
6CD00F5F135FEE9C003E789A /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -222,6 +230,9 @@
080E96DDFE201D6D7F000001 /* Classes */ = {
isa = PBXGroup;
children = (
520D7C411618AA10009306B7 /* ControlPadEventDelegate.h */,
520D7C421618AA10009306B7 /* iCadeViewController.h */,
520D7C431618AA10009306B7 /* iCadeViewController.m */,
1D3623240D0F684500981E51 /* SNES4iOSAppDelegate.h */,
1D3623250D0F684500981E51 /* SNES4iOSAppDelegate.m */,
28042007108E984D000629CD /* RomSelectionViewController.h */,
Expand Down Expand Up @@ -264,6 +275,7 @@
080E96DDFE201D6D7F000001 /* Classes */,
CE43A4CC119DFEF70007E399 /* Resources */,
29B97315FDCFA39411CA2CEA /* Other Sources */,
520D7C401618A9F1009306B7 /* External Libraries */,
29B97323FDCFA39411CA2CEA /* Frameworks */,
19C28FACFE9D520D11CA2CBB /* Products */,
);
Expand Down Expand Up @@ -301,6 +313,24 @@
name = Frameworks;
sourceTree = "<group>";
};
520D7C3A1618A9C4009306B7 /* iCade */ = {
isa = PBXGroup;
children = (
520D7C3B1618A9C4009306B7 /* iCadeReaderView.h */,
520D7C3C1618A9C4009306B7 /* iCadeReaderView.m */,
520D7C3D1618A9C4009306B7 /* iCadeState.h */,
);
path = iCade;
sourceTree = "<group>";
};
520D7C401618A9F1009306B7 /* External Libraries */ = {
isa = PBXGroup;
children = (
520D7C3A1618A9C4009306B7 /* iCade */,
);
name = "External Libraries";
sourceTree = "<group>";
};
BF7B7A0C14A64BEE00014E61 /* SNES Controller */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -544,6 +574,8 @@
BF7B7A0914A64BEA00014E61 /* SessionController.m in Sources */,
BF7B7A0A14A64BEA00014E61 /* SNESControllerAppDelegate.m in Sources */,
BF7B7A0B14A64BEA00014E61 /* SNESControllerViewController.m in Sources */,
520D7C3E1618A9C4009306B7 /* iCadeReaderView.m in Sources */,
520D7C441618AA10009306B7 /* iCadeViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Loading