Skip to content

Commit

Permalink
PSX: Add L2 & R2 mappings for extended controller
Browse files Browse the repository at this point in the history
- Moved PSX Start & Select to the menu
- Had to use a bit of a hack and set a bool which is read during the controller polling as it seems that setting the inputBuffer manually outside of a poll has some issues where it’s ignored — probably due to threading.
- It appears that other cores that move the start/select buttons to the menu (eg, when using the micro controller on tvOS), have the same issue where pressing the start button in the menu is ignored if controller polling is in use. Micro gamepad is a bit of an edge case though, so I haven’t updated those cores. Other cores that have Start/Select mapped to the triggers should continue to work.
  • Loading branch information
jasarien committed Dec 18, 2017
1 parent e97b993 commit c2237d6
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 55 deletions.
3 changes: 3 additions & 0 deletions Mednafen/MednafenGameCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ typedef NS_ENUM(NSInteger, OENGPButton) {
__attribute__((visibility("default")))
@interface MednafenGameCore : PVEmulatorCore

@property (nonatomic) BOOL isStartPressed;
@property (nonatomic) BOOL isSelectPressed;

// Atari Lynx
- (oneway void)didPushLynxButton:(OELynxButton)button forPlayer:(NSUInteger)player;
- (oneway void)didReleaseLynxButton:(OELynxButton)button forPlayer:(NSUInteger)player;
Expand Down
8 changes: 6 additions & 2 deletions Mednafen/MednafenGameCore.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1793,10 +1793,14 @@ - (NSInteger)PSXcontrollerValueForButtonID:(unsigned)buttonID forController:(GCC
return [[pad buttonY] isPressed];
case PVPSXButtonR1:
return [[pad rightShoulder] isPressed];
case PVPSXButtonStart:
case PVPSXButtonL2:
return [[pad leftTrigger] isPressed];
case PVPSXButtonSelect:
case PVPSXButtonR2:
return [[pad rightTrigger] isPressed];
case PVPSXButtonStart:
return self.isStartPressed;
case PVPSXButtonSelect:
return self.isSelectPressed;
default:
break;
}
Expand Down
8 changes: 4 additions & 4 deletions Provenance.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2598,7 +2598,7 @@
ORGANIZATIONNAME = "James Addyman";
TargetAttributes = {
1A3D409317B2DCE4004DFFFC = {
DevelopmentTeam = V78REPMQFZ;
DevelopmentTeam = 63497P68S6;
LastSwiftMigration = 0830;
};
1AD481B31BA350A400FDA50A = {
Expand Down Expand Up @@ -3411,7 +3411,7 @@
CLANG_ENABLE_OBJC_ARC = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = V78REPMQFZ;
DEVELOPMENT_TEAM = 63497P68S6;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)",
Expand Down Expand Up @@ -3452,7 +3452,7 @@
CLANG_ENABLE_OBJC_ARC = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = V78REPMQFZ;
DEVELOPMENT_TEAM = 63497P68S6;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)",
Expand Down Expand Up @@ -3849,7 +3849,7 @@
CLANG_ENABLE_OBJC_ARC = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = V78REPMQFZ;
DEVELOPMENT_TEAM = 63497P68S6;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)",
Expand Down
4 changes: 4 additions & 0 deletions Provenance/Controller/PVPSXControllerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -125,24 +125,28 @@ - (void)pressStartForPlayer:(NSUInteger)player
{
MednafenGameCore *psxCore = (MednafenGameCore *)self.emulatorCore;
[psxCore didPushPSXButton:PVPSXButtonStart forPlayer:player];
psxCore.isStartPressed = YES;
}

- (void)releaseStartForPlayer:(NSUInteger)player
{
MednafenGameCore *psxCore = (MednafenGameCore *)self.emulatorCore;
[psxCore didReleasePSXButton:PVPSXButtonStart forPlayer:player];
psxCore.isStartPressed = NO;
}

- (void)pressSelectForPlayer:(NSUInteger)player
{
MednafenGameCore *psxCore = (MednafenGameCore *)self.emulatorCore;
[psxCore didPushPSXButton:PVPSXButtonSelect forPlayer:player];
psxCore.isSelectPressed = YES;
}

- (void)releaseSelectForPlayer:(NSUInteger)player
{
MednafenGameCore *psxCore = (MednafenGameCore *)self.emulatorCore;
[psxCore didReleasePSXButton:PVPSXButtonSelect forPlayer:player];
psxCore.isSelectPressed = NO;
}

@end
1 change: 1 addition & 0 deletions Provenance/Emulator/PVEmulatorConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
- (NSString * _Nullable)nameForSystemIdentifier:(NSString* _Nonnull)systemID;
- (NSString * _Nullable)shortNameForSystemIdentifier:(NSString * _Nonnull)systemID;
- (NSArray * _Nullable)controllerLayoutForSystem:(NSString * _Nonnull)systemID;
- (BOOL)systemIDWantsStartAndSelectInMenu:(NSString * _Nonnull)systemID;
- (NSString * _Nullable)databaseIDForSystemID:(NSString * _Nonnull)systemID;
- (NSString *)systemIDForDatabaseID:(NSString *)databaseID;

Expand Down
8 changes: 8 additions & 0 deletions Provenance/Emulator/PVEmulatorConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ - (PVControllerViewController *)controllerViewControllerForSystemIdentifier:(NSS
return controller;
}

- (BOOL)systemIDWantsStartAndSelectInMenu:(NSString *)systemID {
if ([systemID isEqualToString:PVPSXSystemIdentifier]) {
return YES;
}

return NO;
}

- (NSDictionary *)systemForIdentifier:(NSString *)systemID
{
for (NSDictionary *system in self.systems)
Expand Down
3 changes: 2 additions & 1 deletion Provenance/Emulator/PVEmulatorViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#import "JSButton.h"
#import "PVControllerViewController.h"

@class PVEmulatorCore, PVGame;
@class PVEmulatorCore, PVGame, PVEmulatorConfiguration;

#if TARGET_OS_TV
@interface PVEmulatorViewController : GCEventViewController
Expand All @@ -22,6 +22,7 @@

@property (nonatomic, strong) PVEmulatorCore *emulatorCore;
@property (nonatomic, strong) PVGame *game;
@property (nonatomic, strong) NSString *systemID;
@property (nonatomic, copy) NSString *batterySavesPath;
@property (nonatomic, copy) NSString *saveStatePath;
@property (nonatomic, copy) NSString *BIOSPath;
Expand Down
97 changes: 51 additions & 46 deletions Provenance/Emulator/PVEmulatorViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -444,61 +444,66 @@ - (void)showMenu:(id)sender
}]];
}

#if TARGET_OS_TV
PVControllerManager *controllerManager = [PVControllerManager sharedManager];
if (![[controllerManager player1] extendedGamepad])
{
// left trigger bound to Start
// right trigger bound to Select
[actionsheet addAction:[UIAlertAction actionWithTitle:@"P1 Start" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[weakSelf.emulatorCore setPauseEmulation:NO];
weakSelf.isShowingMenu = NO;
[weakSelf.controllerViewController pressStartForPlayer:0];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[weakSelf.controllerViewController releaseStartForPlayer:0];
});
BOOL wantsStartSelectInMenu = [[PVEmulatorConfiguration sharedInstance] systemIDWantsStartAndSelectInMenu: self.systemID];

if ([controllerManager player1]) {
if (![[controllerManager player1] extendedGamepad] || wantsStartSelectInMenu)
{
// left trigger bound to Start
// right trigger bound to Select
[actionsheet addAction:[UIAlertAction actionWithTitle:@"P1 Start" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[weakSelf.emulatorCore setPauseEmulation:NO];
weakSelf.isShowingMenu = NO;
[weakSelf.controllerViewController pressStartForPlayer:0];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[weakSelf.controllerViewController releaseStartForPlayer:0];
});
#if TARGET_OS_TV
weakSelf.controllerUserInteractionEnabled = NO;
weakSelf.controllerUserInteractionEnabled = NO;
#endif
}]];
[actionsheet addAction:[UIAlertAction actionWithTitle:@"P1 Select" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[weakSelf.emulatorCore setPauseEmulation:NO];
weakSelf.isShowingMenu = NO;
[weakSelf.controllerViewController pressSelectForPlayer:0];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[weakSelf.controllerViewController releaseSelectForPlayer:0];
});
}]];
[actionsheet addAction:[UIAlertAction actionWithTitle:@"P1 Select" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[weakSelf.emulatorCore setPauseEmulation:NO];
weakSelf.isShowingMenu = NO;
[weakSelf.controllerViewController pressSelectForPlayer:0];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[weakSelf.controllerViewController releaseSelectForPlayer:0];
});
#if TARGET_OS_TV
weakSelf.controllerUserInteractionEnabled = NO;
weakSelf.controllerUserInteractionEnabled = NO;
#endif
}]];
}
if (![[controllerManager player2] extendedGamepad])
{
[actionsheet addAction:[UIAlertAction actionWithTitle:@"P2 Start" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[weakSelf.emulatorCore setPauseEmulation:NO];
weakSelf.isShowingMenu = NO;
[weakSelf.controllerViewController pressStartForPlayer:1];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[weakSelf.controllerViewController releaseStartForPlayer:1];
});
}]];
}
}

if ([controllerManager player2]) {
if (![[controllerManager player2] extendedGamepad] || wantsStartSelectInMenu)
{
[actionsheet addAction:[UIAlertAction actionWithTitle:@"P2 Start" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[weakSelf.emulatorCore setPauseEmulation:NO];
weakSelf.isShowingMenu = NO;
[weakSelf.controllerViewController pressStartForPlayer:1];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[weakSelf.controllerViewController releaseStartForPlayer:1];
});
#if TARGET_OS_TV
weakSelf.controllerUserInteractionEnabled = NO;
weakSelf.controllerUserInteractionEnabled = NO;
#endif
}]];
[actionsheet addAction:[UIAlertAction actionWithTitle:@"P2 Select" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[weakSelf.emulatorCore setPauseEmulation:NO];
weakSelf.isShowingMenu = NO;
[weakSelf.controllerViewController pressSelectForPlayer:1];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[weakSelf.controllerViewController releaseSelectForPlayer:1];
});
}]];
[actionsheet addAction:[UIAlertAction actionWithTitle:@"P2 Select" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[weakSelf.emulatorCore setPauseEmulation:NO];
weakSelf.isShowingMenu = NO;
[weakSelf.controllerViewController pressSelectForPlayer:1];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[weakSelf.controllerViewController releaseSelectForPlayer:1];
});
#if TARGET_OS_TV
weakSelf.controllerUserInteractionEnabled = NO;
#endif
}]];
}
weakSelf.controllerUserInteractionEnabled = NO;
#endif
}]];
}
}

if ([self.emulatorCore supportsDiskSwapping])
{
Expand Down
1 change: 1 addition & 0 deletions Provenance/Game Library/PVGameLibraryViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,7 @@ - (void)loadGame:(PVGame *)game
[emulatorViewController setBatterySavesPath:[config batterySavesPathForROM:[[config romsPath] stringByAppendingPathComponent:[game romPath]]]];
[emulatorViewController setSaveStatePath:[config saveStatePathForROM:[[config romsPath] stringByAppendingPathComponent:[game romPath]]]];
[emulatorViewController setBIOSPath:[config BIOSPathForSystemID:[game systemIdentifier]]];
[emulatorViewController setSystemID:[game systemIdentifier]];
[emulatorViewController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];

[self presentViewController:emulatorViewController animated:YES completion:NULL];
Expand Down
4 changes: 2 additions & 2 deletions Provenance/Provenance-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>683</string>
<string>815</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
Expand All @@ -54,7 +54,7 @@
<key>NSPhotoLibraryUsageDescription</key>
<string>Provenance can set custom artworks from your photos or save screenshots to your photos library.</string>
<key>Revision</key>
<string>439486d</string>
<string>e97b993</string>
<key>UIFileSharingEnabled</key>
<true/>
<key>UILaunchStoryboardName</key>
Expand Down

0 comments on commit c2237d6

Please sign in to comment.