Re-working how DFInput on OS X stores preferences, making it match the rest of the OS X plug-ins.

Do some localization support work on DFInput on OS X.
Bump the version in the info.plist file for DFInput to 1.5.
Other code changes and improvements on the Mac port.

git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@87023 e17a0e51-4ae3-4d35-97c3-1a29b211df97
This commit is contained in:
SND\MaddTheSane_cp 2013-08-29 23:36:29 +00:00
parent 06f5ec54da
commit 460faedba4
15 changed files with 726 additions and 466 deletions

View File

@ -43,6 +43,8 @@
2BB3D6C305427FE200831ACB /* Plugin.c in Sources */ = {isa = PBXBuildFile; fileRef = 2BBB17DA051E4D0F00B84448 /* Plugin.c */; };
2BB3D6C405427FE200831ACB /* PcsxrPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = 2BA44361052DB2EA00E21DDD /* PcsxrPlugin.m */; };
550F023D17BFFD97002594DF /* PcsxrHexadecimalFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 550F023C17BFFD97002594DF /* PcsxrHexadecimalFormatter.m */; };
550FFAEF17CEE37D0003A2F3 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 551A76B2178693EA0052D185 /* CoreFoundation.framework */; };
550FFAF117CEEECA0003A2F3 /* cfgHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 550FFAF017CEEEC90003A2F3 /* cfgHelper.m */; };
551A75C917868C4E0052D185 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 551A749E17868B110052D185 /* Cocoa.framework */; };
551A75CF17868C860052D185 /* Bladesio1PluginConfig.xib in Resources */ = {isa = PBXBuildFile; fileRef = 551A74B417868BEA0052D185 /* Bladesio1PluginConfig.xib */; };
551A75D017868C860052D185 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 551A74B617868BEA0052D185 /* Credits.rtf */; };
@ -431,6 +433,7 @@
550F023B17BFFD97002594DF /* PcsxrHexadecimalFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PcsxrHexadecimalFormatter.h; sourceTree = "<group>"; };
550F023C17BFFD97002594DF /* PcsxrHexadecimalFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PcsxrHexadecimalFormatter.m; sourceTree = "<group>"; };
550FFAEE17CEB8780003A2F3 /* DFSound.exp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.exports; path = DFSound.exp; sourceTree = "<group>"; };
550FFAF017CEEEC90003A2F3 /* cfgHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = cfgHelper.m; sourceTree = "<group>"; };
551A749E17868B110052D185 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
551A74A117868B110052D185 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
551A74A217868B110052D185 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
@ -778,6 +781,7 @@
551A76891786919F0052D185 /* Cocoa.framework in Frameworks */,
551A77E71786A4DD0052D185 /* Carbon.framework in Frameworks */,
554FD70C17C6A1F10056CF66 /* SDL2.framework in Frameworks */,
550FFAEF17CEE37D0003A2F3 /* CoreFoundation.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -813,8 +817,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
551A7724178699250052D185 /* OpenAL.framework in Frameworks */,
551A7715178698C60052D185 /* libSPUSharedCode.dylib in Frameworks */,
551A7724178699250052D185 /* OpenAL.framework in Frameworks */,
551A7716178698C60052D185 /* Cocoa.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
@ -1099,6 +1103,7 @@
551A752617868BEB0052D185 /* macsrc */ = {
isa = PBXGroup;
children = (
550FFAF017CEEEC90003A2F3 /* cfgHelper.m */,
551A752717868BEB0052D185 /* cfg.c */,
551A752817868BEB0052D185 /* cfg.h */,
551A752917868BEB0052D185 /* ControllerList.h */,
@ -2061,6 +2066,7 @@
551A76981786923E0052D185 /* PadController.m in Sources */,
551A76991786923E0052D185 /* PadView.m in Sources */,
551A769A1786923E0052D185 /* xkb.c in Sources */,
550FFAF117CEEECA0003A2F3 /* cfgHelper.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -1,4 +1,4 @@
{\rtf1\ansi\ansicpg1252\cocoartf1138\cocoasubrtf510
{\rtf1\ansi\ansicpg1252\cocoartf1187\cocoasubrtf390
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\vieww9000\viewh9000\viewkind0
@ -9,6 +9,7 @@
Wei Mingzhi\
Gil Pedersen\
Nicolas P\'e9pin-Perreault\
C.W. "Madd the Sane" Betts\
\
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardirnatural

View File

@ -1,6 +1,6 @@
/* Localized versions of Info.plist keys */
CFBundleName = "DFInput PSX Controller Plugin";
CFBundleShortVersionString = "DFInput version 1.0";
CFBundleGetInfoString = "DFInput PSX Controller Plugin version 1.0, Copyright © 2009 Wei Mingzhi.";
CFBundleShortVersionString = "DFInput version 1.5";
CFBundleGetInfoString = "DFInput PSX Controller Plugin version 1.5, Copyright © 2009 Wei Mingzhi.";
NSHumanReadableCopyright = "Copyright © 2009 Wei Mingzhi.";

View File

@ -7,3 +7,36 @@
*/
"Gamepad/Keyboard/Mouse Input" = "Gamepad/Keyboard/Mouse Input";
"Joystick: Button %d" = "Joystick: Button %d";
"Joystick: Axis %d%c" = "Joystick: Axis %d%c";
"Joystick: Hat %d %s" = "Joystick: Hat %d %s";
"Keyboard: %s" = "Keyboard: %s";
"(Keyboard only)" = "(Keyboard only)";
"D-Pad Up" = "D-Pad Up";
"D-Pad Down" = "D-Pad Down";
"D-Pad Left" = "D-Pad Left";
"D-Pad Right" = "D-Pad Right";
"Cross" = "Cross";
"Circle" = "Circle";
"Square" = "Square";
"Triangle" = "Triangle";
"L1" = "L1";
"R1" = "R1";
"L2" = "L2";
"R2" = "R2";
"Select" = "Select";
"Start" = "Start";
"L3" = "L3";
"R3" = "R3";
"Analog" = "Analog";
"L-Stick Right" = "L-Stick Right";
"L-Stick Left" = "L-Stick Left";
"L-Stick Down" = "L-Stick Down";
"L-Stick Up" = "L-Stick Up";
"R-Stick Right" = "R-Stick Right";
"R-Stick Left" = "R-Stick Left";
"R-Stick Down" = "R-Stick Down";
"R-Stick Up" = "R-Stick Up";

View File

@ -9,7 +9,7 @@
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>net.pcsx.DFInputPlugin</string>
<string>net.pcsxr.DFInputPlugin</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
@ -17,7 +17,7 @@
<key>CFBundleSignature</key>
<string>DFI </string>
<key>CFBundleVersion</key>
<string>1.0</string>
<string>1.5</string>
<key>NSPrincipalClass</key>
<string>NetPcsxrHIDInputPluginPadController</string>
</dict>

View File

@ -28,7 +28,6 @@
@interface ControllerList : NSObject <NSTableViewDataSource> {
}
- (id)initWithConfig;
+ (void)setCurrentController:(int)which;

View File

@ -22,20 +22,53 @@
#import "ControllerList.h"
#include "pad.h"
#include "cfg.h"
#import "ARCBridge.h"
static int currentController;
static NSArray *labelText;
@implementation ControllerList
- (id)initWithConfig
{
if (self = [super init]) {
NSBundle *plugBundle = [NSBundle bundleForClass:[self class]];
if (!labelText) {
labelText = @[[plugBundle localizedStringForKey:@"D-Pad Up" value:@"" table:nil],
[plugBundle localizedStringForKey:@"D-Pad Down" value:@"" table:nil],
[plugBundle localizedStringForKey:@"D-Pad Left" value:@"" table:nil],
[plugBundle localizedStringForKey:@"D-Pad Right" value:@"" table:nil],
[plugBundle localizedStringForKey:@"Cross" value:@"" table:nil],
[plugBundle localizedStringForKey:@"Circle" value:@"" table:nil],
[plugBundle localizedStringForKey:@"Square" value:@"" table:nil],
[plugBundle localizedStringForKey:@"Triangle" value:@"" table:nil],
[plugBundle localizedStringForKey:@"L1" value:@"" table:nil],
[plugBundle localizedStringForKey:@"R1" value:@"" table:nil],
[plugBundle localizedStringForKey:@"L2" value:@"" table:nil],
[plugBundle localizedStringForKey:@"R2" value:@"" table:nil],
[plugBundle localizedStringForKey:@"Select" value:@"" table:nil],
[plugBundle localizedStringForKey:@"Start" value:@"" table:nil],
[plugBundle localizedStringForKey:@"L3" value:@"" table:nil],
[plugBundle localizedStringForKey:@"R3" value:@"" table:nil],
[plugBundle localizedStringForKey:@"Analog" value:@"" table:nil],
[plugBundle localizedStringForKey:@"L-Stick Right" value:@"" table:nil],
[plugBundle localizedStringForKey:@"L-Stick Left" value:@"" table:nil],
[plugBundle localizedStringForKey:@"L-Stick Down" value:@"" table:nil],
[plugBundle localizedStringForKey:@"L-Stick Up" value:@"" table:nil],
[plugBundle localizedStringForKey:@"R-Stick Right" value:@"" table:nil],
[plugBundle localizedStringForKey:@"R-Stick Left" value:@"" table:nil],
[plugBundle localizedStringForKey:@"R-Stick Down" value:@"" table:nil],
[plugBundle localizedStringForKey:@"R-Stick Up" value:@"" table:nil]];
RETAINOBJ(labelText);
}
}
return self;
}
#if !__has_feature(objc_arc)
//#if !__has_feature(objc_arc)
#if 0
- (void)dealloc
{
[super dealloc];
@ -59,34 +92,6 @@ static int currentController;
return DKEY_TOTAL + (g.cfg.PadDef[currentController].Type == PSE_PAD_TYPE_ANALOGPAD ? 8 : -3);
}
static const NSString *LabelText[DKEY_TOTAL + 8] = {
@"D-Pad Up",
@"D-Pad Down",
@"D-Pad Left",
@"D-Pad Right",
@"Cross",
@"Circle",
@"Square",
@"Triangle",
@"L1",
@"R1",
@"L2",
@"R2",
@"Select",
@"Start",
@"L3",
@"R3",
@"Analog",
@"L-Stick Right",
@"L-Stick Left",
@"L-Stick Down",
@"L-Stick Up",
@"R-Stick Right",
@"R-Stick Left",
@"R-Stick Down",
@"R-Stick Up"
};
static const int DPad[DKEY_TOTAL] = {
DKEY_UP,
DKEY_DOWN,
@ -115,11 +120,11 @@ static const int DPad[DKEY_TOTAL] = {
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(NSInteger)rowIndex
{
char buf[256];
if ([((NSString *)[aTableColumn identifier]) isEqualToString:@"key"])
return LabelText[rowIndex];
else {
char buf[256] = {0};
if ([[aTableColumn identifier] isEqualToString:@"key"]) {
return [labelText objectAtIndex:rowIndex];
} else {
// actual keys
if (rowIndex < DKEY_TOTAL) {
GetKeyDescription(buf, currentController, DPad[rowIndex]);
@ -127,7 +132,7 @@ static const int DPad[DKEY_TOTAL] = {
rowIndex -= DKEY_TOTAL;
GetAnalogDescription(buf, currentController, (int)(rowIndex / 4), rowIndex % 4);
}
return @(buf);
}
}

View File

@ -34,3 +34,7 @@
- (IBAction)cancel:(id)sender;
- (IBAction)ok:(id)sender;
@end
extern NSDictionary *DefaultPadArray(int padnum);
extern void LoadPadArray(int padnum, NSDictionary *nsPrefs);
extern NSDictionary *SavePadArray(int padnum);

View File

@ -21,8 +21,9 @@
#import <Cocoa/Cocoa.h>
#import "PadController.h"
#include "pad.h"
#import "ARCBridge.h"
#include "pad.h"
#include <sys/param.h>
static inline void RunOnMainThreadSync(dispatch_block_t block)
{
@ -37,6 +38,302 @@ static NSWindow *padWindow = nil;
static PadController *padController = nil;
#define APP_ID @"net.pcsxr.DFInputPlugin"
#define PrefsKey APP_ID @" Settings"
#define kDFThreading @"Threading"
#define kDFPad1 @"Pad 1"
#define kDFPad2 @"Pad 2"
static void SetDefaultConfig() {
memset(&g.cfg, 0, sizeof(g.cfg));
g.cfg.Threaded = 1;
g.cfg.PadDef[0].DevNum = 0;
g.cfg.PadDef[1].DevNum = 1;
g.cfg.PadDef[0].Type = PSE_PAD_TYPE_STANDARD;
g.cfg.PadDef[1].Type = PSE_PAD_TYPE_STANDARD;
// Pad1 keyboard
g.cfg.PadDef[0].KeyDef[DKEY_SELECT].Key = 9;
g.cfg.PadDef[0].KeyDef[DKEY_START].Key = 10;
g.cfg.PadDef[0].KeyDef[DKEY_UP].Key = 127;
g.cfg.PadDef[0].KeyDef[DKEY_RIGHT].Key = 125;
g.cfg.PadDef[0].KeyDef[DKEY_DOWN].Key = 126;
g.cfg.PadDef[0].KeyDef[DKEY_LEFT].Key = 124;
g.cfg.PadDef[0].KeyDef[DKEY_L2].Key = 16;
g.cfg.PadDef[0].KeyDef[DKEY_R2].Key = 18;
g.cfg.PadDef[0].KeyDef[DKEY_L1].Key = 14;
g.cfg.PadDef[0].KeyDef[DKEY_R1].Key = 15;
g.cfg.PadDef[0].KeyDef[DKEY_TRIANGLE].Key = 3;
g.cfg.PadDef[0].KeyDef[DKEY_CIRCLE].Key = 8;
g.cfg.PadDef[0].KeyDef[DKEY_CROSS].Key = 7;
g.cfg.PadDef[0].KeyDef[DKEY_SQUARE].Key = 2;
g.cfg.PadDef[0].KeyDef[DKEY_ANALOG].Key = 12;
// Pad1 joystick
g.cfg.PadDef[0].KeyDef[DKEY_SELECT].JoyEvType = BUTTON;
g.cfg.PadDef[0].KeyDef[DKEY_SELECT].J.Button = 8;
g.cfg.PadDef[0].KeyDef[DKEY_START].JoyEvType = BUTTON;
g.cfg.PadDef[0].KeyDef[DKEY_START].J.Button = 9;
g.cfg.PadDef[0].KeyDef[DKEY_UP].JoyEvType = AXIS;
g.cfg.PadDef[0].KeyDef[DKEY_UP].J.Axis = -2;
g.cfg.PadDef[0].KeyDef[DKEY_RIGHT].JoyEvType = AXIS;
g.cfg.PadDef[0].KeyDef[DKEY_RIGHT].J.Axis = 1;
g.cfg.PadDef[0].KeyDef[DKEY_DOWN].JoyEvType = AXIS;
g.cfg.PadDef[0].KeyDef[DKEY_DOWN].J.Axis = 2;
g.cfg.PadDef[0].KeyDef[DKEY_LEFT].JoyEvType = AXIS;
g.cfg.PadDef[0].KeyDef[DKEY_LEFT].J.Axis = -1;
g.cfg.PadDef[0].KeyDef[DKEY_L2].JoyEvType = BUTTON;
g.cfg.PadDef[0].KeyDef[DKEY_L2].J.Button = 4;
g.cfg.PadDef[0].KeyDef[DKEY_L1].JoyEvType = BUTTON;
g.cfg.PadDef[0].KeyDef[DKEY_L1].J.Button = 6;
g.cfg.PadDef[0].KeyDef[DKEY_R2].JoyEvType = BUTTON;
g.cfg.PadDef[0].KeyDef[DKEY_R2].J.Button = 5;
g.cfg.PadDef[0].KeyDef[DKEY_R1].JoyEvType = BUTTON;
g.cfg.PadDef[0].KeyDef[DKEY_R1].J.Button = 7;
g.cfg.PadDef[0].KeyDef[DKEY_TRIANGLE].JoyEvType = BUTTON;
g.cfg.PadDef[0].KeyDef[DKEY_TRIANGLE].J.Button = 0;
g.cfg.PadDef[0].KeyDef[DKEY_CIRCLE].JoyEvType = BUTTON;
g.cfg.PadDef[0].KeyDef[DKEY_CIRCLE].J.Button = 1;
g.cfg.PadDef[0].KeyDef[DKEY_CROSS].JoyEvType = BUTTON;
g.cfg.PadDef[0].KeyDef[DKEY_CROSS].J.Button = 2;
g.cfg.PadDef[0].KeyDef[DKEY_SQUARE].JoyEvType = BUTTON;
g.cfg.PadDef[0].KeyDef[DKEY_SQUARE].J.Button = 3;
// Pad2 joystick
g.cfg.PadDef[1].KeyDef[DKEY_SELECT].JoyEvType = BUTTON;
g.cfg.PadDef[1].KeyDef[DKEY_SELECT].J.Button = 8;
g.cfg.PadDef[1].KeyDef[DKEY_START].JoyEvType = BUTTON;
g.cfg.PadDef[1].KeyDef[DKEY_START].J.Button = 9;
g.cfg.PadDef[1].KeyDef[DKEY_UP].JoyEvType = AXIS;
g.cfg.PadDef[1].KeyDef[DKEY_UP].J.Axis = -2;
g.cfg.PadDef[1].KeyDef[DKEY_RIGHT].JoyEvType = AXIS;
g.cfg.PadDef[1].KeyDef[DKEY_RIGHT].J.Axis = 1;
g.cfg.PadDef[1].KeyDef[DKEY_DOWN].JoyEvType = AXIS;
g.cfg.PadDef[1].KeyDef[DKEY_DOWN].J.Axis = 2;
g.cfg.PadDef[1].KeyDef[DKEY_LEFT].JoyEvType = AXIS;
g.cfg.PadDef[1].KeyDef[DKEY_LEFT].J.Axis = -1;
g.cfg.PadDef[1].KeyDef[DKEY_L2].JoyEvType = BUTTON;
g.cfg.PadDef[1].KeyDef[DKEY_L2].J.Button = 4;
g.cfg.PadDef[1].KeyDef[DKEY_L1].JoyEvType = BUTTON;
g.cfg.PadDef[1].KeyDef[DKEY_L1].J.Button = 6;
g.cfg.PadDef[1].KeyDef[DKEY_R2].JoyEvType = BUTTON;
g.cfg.PadDef[1].KeyDef[DKEY_R2].J.Button = 5;
g.cfg.PadDef[1].KeyDef[DKEY_R1].JoyEvType = BUTTON;
g.cfg.PadDef[1].KeyDef[DKEY_R1].J.Button = 7;
g.cfg.PadDef[1].KeyDef[DKEY_TRIANGLE].JoyEvType = BUTTON;
g.cfg.PadDef[1].KeyDef[DKEY_TRIANGLE].J.Button = 0;
g.cfg.PadDef[1].KeyDef[DKEY_CIRCLE].JoyEvType = BUTTON;
g.cfg.PadDef[1].KeyDef[DKEY_CIRCLE].J.Button = 1;
g.cfg.PadDef[1].KeyDef[DKEY_CROSS].JoyEvType = BUTTON;
g.cfg.PadDef[1].KeyDef[DKEY_CROSS].J.Button = 2;
g.cfg.PadDef[1].KeyDef[DKEY_SQUARE].JoyEvType = BUTTON;
g.cfg.PadDef[1].KeyDef[DKEY_SQUARE].J.Button = 3;
}
void LoadPADConfig()
{
SetDefaultConfig();
[[NSUserDefaults standardUserDefaults] registerDefaults:
[NSDictionary dictionaryWithObject:[NSDictionary dictionaryWithObjectsAndKeys:
DefaultPadArray(0), kDFPad1,
DefaultPadArray(1), kDFPad2,
@YES, kDFThreading,
nil]
forKey:PrefsKey]];
//Load the old preferences if present.
NSFileManager *fm = [NSFileManager defaultManager];
NSString *oldPrefPath = [NSString pathWithComponents:@[NSHomeDirectory(), @"Library", @"Preferences", @"net.pcsxr.DFInput.plist"]];
if ([fm fileExistsAtPath:oldPrefPath]) {
char buf[256] = {0};
int current = 0, a = 0, b = 0, c = 0;
FILE *fp = fopen([oldPrefPath fileSystemRepresentation], "r");
if (fp == NULL) {
return;
}
while (fgets(buf, 256, fp) != NULL) {
if (strncmp(buf, "Threaded=", 9) == 0) {
g.cfg.Threaded = atoi(&buf[9]);
} else if (strncmp(buf, "[PAD", 4) == 0) {
current = atoi(&buf[4]) - 1;
if (current < 0) {
current = 0;
} else if (current > 1) {
current = 1;
}
} else if (strncmp(buf, "DevNum=", 7) == 0) {
g.cfg.PadDef[current].DevNum = atoi(&buf[7]);
} else if (strncmp(buf, "Type=", 5) == 0) {
g.cfg.PadDef[current].Type = atoi(&buf[5]);
} else if (strncmp(buf, "Select=", 7) == 0) {
sscanf(buf, "Select=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_SELECT].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_SELECT].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_SELECT].J.d = c;
} else if (strncmp(buf, "L3=", 3) == 0) {
sscanf(buf, "L3=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_L3].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_L3].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_L3].J.d = c;
} else if (strncmp(buf, "R3=", 3) == 0) {
sscanf(buf, "R3=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_R3].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_R3].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_R3].J.d = c;
} else if (strncmp(buf, "Analog=", 7) == 0) {
sscanf(buf, "Analog=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_ANALOG].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_ANALOG].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_ANALOG].J.d = c;
} else if (strncmp(buf, "Start=", 6) == 0) {
sscanf(buf, "Start=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_START].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_START].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_START].J.d = c;
} else if (strncmp(buf, "Up=", 3) == 0) {
sscanf(buf, "Up=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_UP].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_UP].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_UP].J.d = c;
} else if (strncmp(buf, "Right=", 6) == 0) {
sscanf(buf, "Right=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_RIGHT].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_RIGHT].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_RIGHT].J.d = c;
} else if (strncmp(buf, "Down=", 5) == 0) {
sscanf(buf, "Down=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_DOWN].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_DOWN].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_DOWN].J.d = c;
} else if (strncmp(buf, "Left=", 5) == 0) {
sscanf(buf, "Left=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_LEFT].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_LEFT].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_LEFT].J.d = c;
} else if (strncmp(buf, "L2=", 3) == 0) {
sscanf(buf, "L2=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_L2].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_L2].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_L2].J.d = c;
} else if (strncmp(buf, "R2=", 3) == 0) {
sscanf(buf, "R2=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_R2].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_R2].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_R2].J.d = c;
} else if (strncmp(buf, "L1=", 3) == 0) {
sscanf(buf, "L1=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_L1].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_L1].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_L1].J.d = c;
} else if (strncmp(buf, "R1=", 3) == 0) {
sscanf(buf, "R1=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_R1].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_R1].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_R1].J.d = c;
} else if (strncmp(buf, "Triangle=", 9) == 0) {
sscanf(buf, "Triangle=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_TRIANGLE].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_TRIANGLE].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_TRIANGLE].J.d = c;
} else if (strncmp(buf, "Circle=", 7) == 0) {
sscanf(buf, "Circle=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_CIRCLE].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_CIRCLE].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_CIRCLE].J.d = c;
} else if (strncmp(buf, "Cross=", 6) == 0) {
sscanf(buf, "Cross=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_CROSS].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_CROSS].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_CROSS].J.d = c;
} else if (strncmp(buf, "Square=", 7) == 0) {
sscanf(buf, "Square=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_SQUARE].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_SQUARE].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_SQUARE].J.d = c;
} else if (strncmp(buf, "LeftAnalogXP=", 13) == 0) {
sscanf(buf, "LeftAnalogXP=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].AnalogDef[ANALOG_LEFT][ANALOG_XP].Key = a;
g.cfg.PadDef[current].AnalogDef[ANALOG_LEFT][ANALOG_XP].JoyEvType = b;
g.cfg.PadDef[current].AnalogDef[ANALOG_LEFT][ANALOG_XP].J.d = c;
} else if (strncmp(buf, "LeftAnalogXM=", 13) == 0) {
sscanf(buf, "LeftAnalogXM=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].AnalogDef[ANALOG_LEFT][ANALOG_XM].Key = a;
g.cfg.PadDef[current].AnalogDef[ANALOG_LEFT][ANALOG_XM].JoyEvType = b;
g.cfg.PadDef[current].AnalogDef[ANALOG_LEFT][ANALOG_XM].J.d = c;
} else if (strncmp(buf, "LeftAnalogYP=", 13) == 0) {
sscanf(buf, "LeftAnalogYP=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].AnalogDef[ANALOG_LEFT][ANALOG_YP].Key = a;
g.cfg.PadDef[current].AnalogDef[ANALOG_LEFT][ANALOG_YP].JoyEvType = b;
g.cfg.PadDef[current].AnalogDef[ANALOG_LEFT][ANALOG_YP].J.d = c;
} else if (strncmp(buf, "LeftAnalogYM=", 13) == 0) {
sscanf(buf, "LeftAnalogYM=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].AnalogDef[ANALOG_LEFT][ANALOG_YM].Key = a;
g.cfg.PadDef[current].AnalogDef[ANALOG_LEFT][ANALOG_YM].JoyEvType = b;
g.cfg.PadDef[current].AnalogDef[ANALOG_LEFT][ANALOG_YM].J.d = c;
} else if (strncmp(buf, "RightAnalogXP=", 14) == 0) {
sscanf(buf, "RightAnalogXP=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].AnalogDef[ANALOG_RIGHT][ANALOG_XP].Key = a;
g.cfg.PadDef[current].AnalogDef[ANALOG_RIGHT][ANALOG_XP].JoyEvType = b;
g.cfg.PadDef[current].AnalogDef[ANALOG_RIGHT][ANALOG_XP].J.d = c;
} else if (strncmp(buf, "RightAnalogXM=", 14) == 0) {
sscanf(buf, "RightAnalogXM=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].AnalogDef[ANALOG_RIGHT][ANALOG_XM].Key = a;
g.cfg.PadDef[current].AnalogDef[ANALOG_RIGHT][ANALOG_XM].JoyEvType = b;
g.cfg.PadDef[current].AnalogDef[ANALOG_RIGHT][ANALOG_XM].J.d = c;
} else if (strncmp(buf, "RightAnalogYP=", 14) == 0) {
sscanf(buf, "RightAnalogYP=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].AnalogDef[ANALOG_RIGHT][ANALOG_YP].Key = a;
g.cfg.PadDef[current].AnalogDef[ANALOG_RIGHT][ANALOG_YP].JoyEvType = b;
g.cfg.PadDef[current].AnalogDef[ANALOG_RIGHT][ANALOG_YP].J.d = c;
} else if (strncmp(buf, "RightAnalogYM=", 14) == 0) {
sscanf(buf, "RightAnalogYM=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].AnalogDef[ANALOG_RIGHT][ANALOG_YM].Key = a;
g.cfg.PadDef[current].AnalogDef[ANALOG_RIGHT][ANALOG_YM].JoyEvType = b;
g.cfg.PadDef[current].AnalogDef[ANALOG_RIGHT][ANALOG_YM].J.d = c;
}
}
fclose(fp);
//Save to new preferences
SavePADConfig();
//Delete the old preferences
[fm removeItemAtPath:oldPrefPath error:NULL];
} else {
NSDictionary *dfPrefs = [[NSUserDefaults standardUserDefaults] dictionaryForKey:PrefsKey];
g.cfg.Threaded = [[dfPrefs objectForKey:kDFThreading] boolValue];
LoadPadArray(0, [dfPrefs objectForKey:kDFPad1]);
LoadPadArray(1, [dfPrefs objectForKey:kDFPad2]);
}
}
void SavePADConfig()
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSMutableDictionary *pad1Dict = nil, *pad2Dict = nil;
NSDictionary *prefDict = [defaults dictionaryForKey:PrefsKey];
pad1Dict = [[NSMutableDictionary alloc] initWithDictionary:[prefDict objectForKey:kDFPad1]];
pad2Dict = [[NSMutableDictionary alloc] initWithDictionary:[prefDict objectForKey:kDFPad2]];
prefDict = nil;
[pad1Dict addEntriesFromDictionary:SavePadArray(0)];
[pad2Dict addEntriesFromDictionary:SavePadArray(1)];
[defaults setObject:[NSDictionary dictionaryWithObjectsAndKeys:
g.cfg.Threaded ? @YES : @NO, kDFThreading,
pad1Dict, kDFPad1,
pad2Dict, kDFPad2,
nil] forKey:PrefsKey];
[defaults synchronize];
RELEASEOBJ(pad1Dict);
RELEASEOBJ(pad2Dict);
}
void DoAbout()
{

View File

@ -67,7 +67,7 @@
[tableView setDataSource:controller];
[deviceMenu removeAllItems];
[deviceMenu addItemWithTitle:@"(Keyboard only)"];
[deviceMenu addItemWithTitle:[[NSBundle bundleForClass:[self class]] localizedStringForKey:@"(Keyboard only)" value:@"" table:nil]];
for (i = 0; i < SDL_NumJoysticks(); i++) {
NSMenuItem *joystickItem = nil;

View File

@ -17,355 +17,19 @@
*/
#include "pad.h"
#include <sys/param.h>
#include "cfg.h"
GLOBALDATA g;
GLOBALDATA g;
long DoConfiguration();
void DoAbout();
static void SetDefaultConfig() {
memset(&g.cfg, 0, sizeof(g.cfg));
g.cfg.Threaded = 1;
g.cfg.PadDef[0].DevNum = 0;
g.cfg.PadDef[1].DevNum = 1;
g.cfg.PadDef[0].Type = PSE_PAD_TYPE_STANDARD;
g.cfg.PadDef[1].Type = PSE_PAD_TYPE_STANDARD;
// Pad1 keyboard
g.cfg.PadDef[0].KeyDef[DKEY_SELECT].Key = 9;
g.cfg.PadDef[0].KeyDef[DKEY_START].Key = 10;
g.cfg.PadDef[0].KeyDef[DKEY_UP].Key = 127;
g.cfg.PadDef[0].KeyDef[DKEY_RIGHT].Key = 125;
g.cfg.PadDef[0].KeyDef[DKEY_DOWN].Key = 126;
g.cfg.PadDef[0].KeyDef[DKEY_LEFT].Key = 124;
g.cfg.PadDef[0].KeyDef[DKEY_L2].Key = 16;
g.cfg.PadDef[0].KeyDef[DKEY_R2].Key = 18;
g.cfg.PadDef[0].KeyDef[DKEY_L1].Key = 14;
g.cfg.PadDef[0].KeyDef[DKEY_R1].Key = 15;
g.cfg.PadDef[0].KeyDef[DKEY_TRIANGLE].Key = 3;
g.cfg.PadDef[0].KeyDef[DKEY_CIRCLE].Key = 8;
g.cfg.PadDef[0].KeyDef[DKEY_CROSS].Key = 7;
g.cfg.PadDef[0].KeyDef[DKEY_SQUARE].Key = 2;
g.cfg.PadDef[0].KeyDef[DKEY_ANALOG].Key = 12;
// Pad1 joystick
g.cfg.PadDef[0].KeyDef[DKEY_SELECT].JoyEvType = BUTTON;
g.cfg.PadDef[0].KeyDef[DKEY_SELECT].J.Button = 8;
g.cfg.PadDef[0].KeyDef[DKEY_START].JoyEvType = BUTTON;
g.cfg.PadDef[0].KeyDef[DKEY_START].J.Button = 9;
g.cfg.PadDef[0].KeyDef[DKEY_UP].JoyEvType = AXIS;
g.cfg.PadDef[0].KeyDef[DKEY_UP].J.Axis = -2;
g.cfg.PadDef[0].KeyDef[DKEY_RIGHT].JoyEvType = AXIS;
g.cfg.PadDef[0].KeyDef[DKEY_RIGHT].J.Axis = 1;
g.cfg.PadDef[0].KeyDef[DKEY_DOWN].JoyEvType = AXIS;
g.cfg.PadDef[0].KeyDef[DKEY_DOWN].J.Axis = 2;
g.cfg.PadDef[0].KeyDef[DKEY_LEFT].JoyEvType = AXIS;
g.cfg.PadDef[0].KeyDef[DKEY_LEFT].J.Axis = -1;
g.cfg.PadDef[0].KeyDef[DKEY_L2].JoyEvType = BUTTON;
g.cfg.PadDef[0].KeyDef[DKEY_L2].J.Button = 4;
g.cfg.PadDef[0].KeyDef[DKEY_L1].JoyEvType = BUTTON;
g.cfg.PadDef[0].KeyDef[DKEY_L1].J.Button = 6;
g.cfg.PadDef[0].KeyDef[DKEY_R2].JoyEvType = BUTTON;
g.cfg.PadDef[0].KeyDef[DKEY_R2].J.Button = 5;
g.cfg.PadDef[0].KeyDef[DKEY_R1].JoyEvType = BUTTON;
g.cfg.PadDef[0].KeyDef[DKEY_R1].J.Button = 7;
g.cfg.PadDef[0].KeyDef[DKEY_TRIANGLE].JoyEvType = BUTTON;
g.cfg.PadDef[0].KeyDef[DKEY_TRIANGLE].J.Button = 0;
g.cfg.PadDef[0].KeyDef[DKEY_CIRCLE].JoyEvType = BUTTON;
g.cfg.PadDef[0].KeyDef[DKEY_CIRCLE].J.Button = 1;
g.cfg.PadDef[0].KeyDef[DKEY_CROSS].JoyEvType = BUTTON;
g.cfg.PadDef[0].KeyDef[DKEY_CROSS].J.Button = 2;
g.cfg.PadDef[0].KeyDef[DKEY_SQUARE].JoyEvType = BUTTON;
g.cfg.PadDef[0].KeyDef[DKEY_SQUARE].J.Button = 3;
// Pad2 joystick
g.cfg.PadDef[1].KeyDef[DKEY_SELECT].JoyEvType = BUTTON;
g.cfg.PadDef[1].KeyDef[DKEY_SELECT].J.Button = 8;
g.cfg.PadDef[1].KeyDef[DKEY_START].JoyEvType = BUTTON;
g.cfg.PadDef[1].KeyDef[DKEY_START].J.Button = 9;
g.cfg.PadDef[1].KeyDef[DKEY_UP].JoyEvType = AXIS;
g.cfg.PadDef[1].KeyDef[DKEY_UP].J.Axis = -2;
g.cfg.PadDef[1].KeyDef[DKEY_RIGHT].JoyEvType = AXIS;
g.cfg.PadDef[1].KeyDef[DKEY_RIGHT].J.Axis = 1;
g.cfg.PadDef[1].KeyDef[DKEY_DOWN].JoyEvType = AXIS;
g.cfg.PadDef[1].KeyDef[DKEY_DOWN].J.Axis = 2;
g.cfg.PadDef[1].KeyDef[DKEY_LEFT].JoyEvType = AXIS;
g.cfg.PadDef[1].KeyDef[DKEY_LEFT].J.Axis = -1;
g.cfg.PadDef[1].KeyDef[DKEY_L2].JoyEvType = BUTTON;
g.cfg.PadDef[1].KeyDef[DKEY_L2].J.Button = 4;
g.cfg.PadDef[1].KeyDef[DKEY_L1].JoyEvType = BUTTON;
g.cfg.PadDef[1].KeyDef[DKEY_L1].J.Button = 6;
g.cfg.PadDef[1].KeyDef[DKEY_R2].JoyEvType = BUTTON;
g.cfg.PadDef[1].KeyDef[DKEY_R2].J.Button = 5;
g.cfg.PadDef[1].KeyDef[DKEY_R1].JoyEvType = BUTTON;
g.cfg.PadDef[1].KeyDef[DKEY_R1].J.Button = 7;
g.cfg.PadDef[1].KeyDef[DKEY_TRIANGLE].JoyEvType = BUTTON;
g.cfg.PadDef[1].KeyDef[DKEY_TRIANGLE].J.Button = 0;
g.cfg.PadDef[1].KeyDef[DKEY_CIRCLE].JoyEvType = BUTTON;
g.cfg.PadDef[1].KeyDef[DKEY_CIRCLE].J.Button = 1;
g.cfg.PadDef[1].KeyDef[DKEY_CROSS].JoyEvType = BUTTON;
g.cfg.PadDef[1].KeyDef[DKEY_CROSS].J.Button = 2;
g.cfg.PadDef[1].KeyDef[DKEY_SQUARE].JoyEvType = BUTTON;
g.cfg.PadDef[1].KeyDef[DKEY_SQUARE].J.Button = 3;
}
void LoadPADConfig() {
FILE *fp;
char buf[PATH_MAX];
int current, a, b, c;
SetDefaultConfig();
sprintf(buf, "%s/Library/Preferences/net.pcsxr.DFInput.plist", getenv("HOME"));
fp = fopen(buf, "r");
if (fp == NULL) {
return;
}
current = 0;
while (fgets(buf, 256, fp) != NULL) {
if (strncmp(buf, "Threaded=", 9) == 0) {
g.cfg.Threaded = atoi(&buf[9]);
} else if (strncmp(buf, "[PAD", 4) == 0) {
current = atoi(&buf[4]) - 1;
if (current < 0) {
current = 0;
} else if (current > 1) {
current = 1;
}
} else if (strncmp(buf, "DevNum=", 7) == 0) {
g.cfg.PadDef[current].DevNum = atoi(&buf[7]);
} else if (strncmp(buf, "Type=", 5) == 0) {
g.cfg.PadDef[current].Type = atoi(&buf[5]);
} else if (strncmp(buf, "Select=", 7) == 0) {
sscanf(buf, "Select=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_SELECT].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_SELECT].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_SELECT].J.d = c;
} else if (strncmp(buf, "L3=", 3) == 0) {
sscanf(buf, "L3=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_L3].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_L3].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_L3].J.d = c;
} else if (strncmp(buf, "R3=", 3) == 0) {
sscanf(buf, "R3=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_R3].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_R3].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_R3].J.d = c;
} else if (strncmp(buf, "Analog=", 7) == 0) {
sscanf(buf, "Analog=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_ANALOG].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_ANALOG].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_ANALOG].J.d = c;
} else if (strncmp(buf, "Start=", 6) == 0) {
sscanf(buf, "Start=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_START].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_START].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_START].J.d = c;
} else if (strncmp(buf, "Up=", 3) == 0) {
sscanf(buf, "Up=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_UP].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_UP].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_UP].J.d = c;
} else if (strncmp(buf, "Right=", 6) == 0) {
sscanf(buf, "Right=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_RIGHT].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_RIGHT].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_RIGHT].J.d = c;
} else if (strncmp(buf, "Down=", 5) == 0) {
sscanf(buf, "Down=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_DOWN].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_DOWN].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_DOWN].J.d = c;
} else if (strncmp(buf, "Left=", 5) == 0) {
sscanf(buf, "Left=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_LEFT].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_LEFT].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_LEFT].J.d = c;
} else if (strncmp(buf, "L2=", 3) == 0) {
sscanf(buf, "L2=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_L2].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_L2].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_L2].J.d = c;
} else if (strncmp(buf, "R2=", 3) == 0) {
sscanf(buf, "R2=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_R2].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_R2].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_R2].J.d = c;
} else if (strncmp(buf, "L1=", 3) == 0) {
sscanf(buf, "L1=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_L1].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_L1].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_L1].J.d = c;
} else if (strncmp(buf, "R1=", 3) == 0) {
sscanf(buf, "R1=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_R1].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_R1].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_R1].J.d = c;
} else if (strncmp(buf, "Triangle=", 9) == 0) {
sscanf(buf, "Triangle=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_TRIANGLE].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_TRIANGLE].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_TRIANGLE].J.d = c;
} else if (strncmp(buf, "Circle=", 7) == 0) {
sscanf(buf, "Circle=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_CIRCLE].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_CIRCLE].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_CIRCLE].J.d = c;
} else if (strncmp(buf, "Cross=", 6) == 0) {
sscanf(buf, "Cross=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_CROSS].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_CROSS].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_CROSS].J.d = c;
} else if (strncmp(buf, "Square=", 7) == 0) {
sscanf(buf, "Square=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].KeyDef[DKEY_SQUARE].Key = a;
g.cfg.PadDef[current].KeyDef[DKEY_SQUARE].JoyEvType = b;
g.cfg.PadDef[current].KeyDef[DKEY_SQUARE].J.d = c;
} else if (strncmp(buf, "LeftAnalogXP=", 13) == 0) {
sscanf(buf, "LeftAnalogXP=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].AnalogDef[ANALOG_LEFT][ANALOG_XP].Key = a;
g.cfg.PadDef[current].AnalogDef[ANALOG_LEFT][ANALOG_XP].JoyEvType = b;
g.cfg.PadDef[current].AnalogDef[ANALOG_LEFT][ANALOG_XP].J.d = c;
} else if (strncmp(buf, "LeftAnalogXM=", 13) == 0) {
sscanf(buf, "LeftAnalogXM=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].AnalogDef[ANALOG_LEFT][ANALOG_XM].Key = a;
g.cfg.PadDef[current].AnalogDef[ANALOG_LEFT][ANALOG_XM].JoyEvType = b;
g.cfg.PadDef[current].AnalogDef[ANALOG_LEFT][ANALOG_XM].J.d = c;
} else if (strncmp(buf, "LeftAnalogYP=", 13) == 0) {
sscanf(buf, "LeftAnalogYP=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].AnalogDef[ANALOG_LEFT][ANALOG_YP].Key = a;
g.cfg.PadDef[current].AnalogDef[ANALOG_LEFT][ANALOG_YP].JoyEvType = b;
g.cfg.PadDef[current].AnalogDef[ANALOG_LEFT][ANALOG_YP].J.d = c;
} else if (strncmp(buf, "LeftAnalogYM=", 13) == 0) {
sscanf(buf, "LeftAnalogYM=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].AnalogDef[ANALOG_LEFT][ANALOG_YM].Key = a;
g.cfg.PadDef[current].AnalogDef[ANALOG_LEFT][ANALOG_YM].JoyEvType = b;
g.cfg.PadDef[current].AnalogDef[ANALOG_LEFT][ANALOG_YM].J.d = c;
} else if (strncmp(buf, "RightAnalogXP=", 14) == 0) {
sscanf(buf, "RightAnalogXP=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].AnalogDef[ANALOG_RIGHT][ANALOG_XP].Key = a;
g.cfg.PadDef[current].AnalogDef[ANALOG_RIGHT][ANALOG_XP].JoyEvType = b;
g.cfg.PadDef[current].AnalogDef[ANALOG_RIGHT][ANALOG_XP].J.d = c;
} else if (strncmp(buf, "RightAnalogXM=", 14) == 0) {
sscanf(buf, "RightAnalogXM=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].AnalogDef[ANALOG_RIGHT][ANALOG_XM].Key = a;
g.cfg.PadDef[current].AnalogDef[ANALOG_RIGHT][ANALOG_XM].JoyEvType = b;
g.cfg.PadDef[current].AnalogDef[ANALOG_RIGHT][ANALOG_XM].J.d = c;
} else if (strncmp(buf, "RightAnalogYP=", 14) == 0) {
sscanf(buf, "RightAnalogYP=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].AnalogDef[ANALOG_RIGHT][ANALOG_YP].Key = a;
g.cfg.PadDef[current].AnalogDef[ANALOG_RIGHT][ANALOG_YP].JoyEvType = b;
g.cfg.PadDef[current].AnalogDef[ANALOG_RIGHT][ANALOG_YP].J.d = c;
} else if (strncmp(buf, "RightAnalogYM=", 14) == 0) {
sscanf(buf, "RightAnalogYM=%d,%d,%d", &a, &b, &c);
g.cfg.PadDef[current].AnalogDef[ANALOG_RIGHT][ANALOG_YM].Key = a;
g.cfg.PadDef[current].AnalogDef[ANALOG_RIGHT][ANALOG_YM].JoyEvType = b;
g.cfg.PadDef[current].AnalogDef[ANALOG_RIGHT][ANALOG_YM].J.d = c;
}
}
fclose(fp);
}
void SavePADConfig() {
FILE *fp;
int i;
char buf[PATH_MAX];
sprintf(buf, "%s/Library/Preferences/net.pcsxr.DFInput.plist", getenv("HOME"));
fp = fopen(buf, "w");
if (fp == NULL) {
return;
}
fprintf(fp, "[CONFIG]\n");
fprintf(fp, "Threaded=%d\n", g.cfg.Threaded);
fprintf(fp, "\n");
for (i = 0; i < 2; i++) {
fprintf(fp, "[PAD%d]\n", i + 1);
fprintf(fp, "DevNum=%d\n", g.cfg.PadDef[i].DevNum);
fprintf(fp, "Type=%d\n", g.cfg.PadDef[i].Type);
fprintf(fp, "Select=%d,%d,%d\n", g.cfg.PadDef[i].KeyDef[DKEY_SELECT].Key,
g.cfg.PadDef[i].KeyDef[DKEY_SELECT].JoyEvType, g.cfg.PadDef[i].KeyDef[DKEY_SELECT].J.d);
fprintf(fp, "L3=%d,%d,%d\n", g.cfg.PadDef[i].KeyDef[DKEY_L3].Key,
g.cfg.PadDef[i].KeyDef[DKEY_L3].JoyEvType, g.cfg.PadDef[i].KeyDef[DKEY_L3].J.d);
fprintf(fp, "R3=%d,%d,%d\n", g.cfg.PadDef[i].KeyDef[DKEY_R3].Key,
g.cfg.PadDef[i].KeyDef[DKEY_R3].JoyEvType, g.cfg.PadDef[i].KeyDef[DKEY_R3].J.d);
fprintf(fp, "Analog=%d,%d,%d\n", g.cfg.PadDef[i].KeyDef[DKEY_ANALOG].Key,
g.cfg.PadDef[i].KeyDef[DKEY_ANALOG].JoyEvType, g.cfg.PadDef[i].KeyDef[DKEY_ANALOG].J.d);
fprintf(fp, "Start=%d,%d,%d\n", g.cfg.PadDef[i].KeyDef[DKEY_START].Key,
g.cfg.PadDef[i].KeyDef[DKEY_START].JoyEvType, g.cfg.PadDef[i].KeyDef[DKEY_START].J.d);
fprintf(fp, "Up=%d,%d,%d\n", g.cfg.PadDef[i].KeyDef[DKEY_UP].Key,
g.cfg.PadDef[i].KeyDef[DKEY_UP].JoyEvType, g.cfg.PadDef[i].KeyDef[DKEY_UP].J.d);
fprintf(fp, "Right=%d,%d,%d\n", g.cfg.PadDef[i].KeyDef[DKEY_RIGHT].Key,
g.cfg.PadDef[i].KeyDef[DKEY_RIGHT].JoyEvType, g.cfg.PadDef[i].KeyDef[DKEY_RIGHT].J.d);
fprintf(fp, "Down=%d,%d,%d\n", g.cfg.PadDef[i].KeyDef[DKEY_DOWN].Key,
g.cfg.PadDef[i].KeyDef[DKEY_DOWN].JoyEvType, g.cfg.PadDef[i].KeyDef[DKEY_DOWN].J.d);
fprintf(fp, "Left=%d,%d,%d\n", g.cfg.PadDef[i].KeyDef[DKEY_LEFT].Key,
g.cfg.PadDef[i].KeyDef[DKEY_LEFT].JoyEvType, g.cfg.PadDef[i].KeyDef[DKEY_LEFT].J.d);
fprintf(fp, "L2=%d,%d,%d\n", g.cfg.PadDef[i].KeyDef[DKEY_L2].Key,
g.cfg.PadDef[i].KeyDef[DKEY_L2].JoyEvType, g.cfg.PadDef[i].KeyDef[DKEY_L2].J.d);
fprintf(fp, "R2=%d,%d,%d\n", g.cfg.PadDef[i].KeyDef[DKEY_R2].Key,
g.cfg.PadDef[i].KeyDef[DKEY_R2].JoyEvType, g.cfg.PadDef[i].KeyDef[DKEY_R2].J.d);
fprintf(fp, "L1=%d,%d,%d\n", g.cfg.PadDef[i].KeyDef[DKEY_L1].Key,
g.cfg.PadDef[i].KeyDef[DKEY_L1].JoyEvType, g.cfg.PadDef[i].KeyDef[DKEY_L1].J.d);
fprintf(fp, "R1=%d,%d,%d\n", g.cfg.PadDef[i].KeyDef[DKEY_R1].Key,
g.cfg.PadDef[i].KeyDef[DKEY_R1].JoyEvType, g.cfg.PadDef[i].KeyDef[DKEY_R1].J.d);
fprintf(fp, "Triangle=%d,%d,%d\n", g.cfg.PadDef[i].KeyDef[DKEY_TRIANGLE].Key,
g.cfg.PadDef[i].KeyDef[DKEY_TRIANGLE].JoyEvType, g.cfg.PadDef[i].KeyDef[DKEY_TRIANGLE].J.d);
fprintf(fp, "Circle=%d,%d,%d\n", g.cfg.PadDef[i].KeyDef[DKEY_CIRCLE].Key,
g.cfg.PadDef[i].KeyDef[DKEY_CIRCLE].JoyEvType, g.cfg.PadDef[i].KeyDef[DKEY_CIRCLE].J.d);
fprintf(fp, "Cross=%d,%d,%d\n", g.cfg.PadDef[i].KeyDef[DKEY_CROSS].Key,
g.cfg.PadDef[i].KeyDef[DKEY_CROSS].JoyEvType, g.cfg.PadDef[i].KeyDef[DKEY_CROSS].J.d);
fprintf(fp, "Square=%d,%d,%d\n", g.cfg.PadDef[i].KeyDef[DKEY_SQUARE].Key,
g.cfg.PadDef[i].KeyDef[DKEY_SQUARE].JoyEvType, g.cfg.PadDef[i].KeyDef[DKEY_SQUARE].J.d);
fprintf(fp, "LeftAnalogXP=%d,%d,%d\n", g.cfg.PadDef[i].AnalogDef[ANALOG_LEFT][ANALOG_XP].Key,
g.cfg.PadDef[i].AnalogDef[ANALOG_LEFT][ANALOG_XP].JoyEvType,
g.cfg.PadDef[i].AnalogDef[ANALOG_LEFT][ANALOG_XP].J.d);
fprintf(fp, "LeftAnalogXM=%d,%d,%d\n", g.cfg.PadDef[i].AnalogDef[ANALOG_LEFT][ANALOG_XM].Key,
g.cfg.PadDef[i].AnalogDef[ANALOG_LEFT][ANALOG_XM].JoyEvType,
g.cfg.PadDef[i].AnalogDef[ANALOG_LEFT][ANALOG_XM].J.d);
fprintf(fp, "LeftAnalogYP=%d,%d,%d\n", g.cfg.PadDef[i].AnalogDef[ANALOG_LEFT][ANALOG_YP].Key,
g.cfg.PadDef[i].AnalogDef[ANALOG_LEFT][ANALOG_YP].JoyEvType,
g.cfg.PadDef[i].AnalogDef[ANALOG_LEFT][ANALOG_YP].J.d);
fprintf(fp, "LeftAnalogYM=%d,%d,%d\n", g.cfg.PadDef[i].AnalogDef[ANALOG_LEFT][ANALOG_YM].Key,
g.cfg.PadDef[i].AnalogDef[ANALOG_LEFT][ANALOG_YM].JoyEvType,
g.cfg.PadDef[i].AnalogDef[ANALOG_LEFT][ANALOG_YM].J.d);
fprintf(fp, "RightAnalogXP=%d,%d,%d\n", g.cfg.PadDef[i].AnalogDef[ANALOG_RIGHT][ANALOG_XP].Key,
g.cfg.PadDef[i].AnalogDef[ANALOG_RIGHT][ANALOG_XP].JoyEvType,
g.cfg.PadDef[i].AnalogDef[ANALOG_RIGHT][ANALOG_XP].J.d);
fprintf(fp, "RightAnalogXM=%d,%d,%d\n", g.cfg.PadDef[i].AnalogDef[ANALOG_RIGHT][ANALOG_XM].Key,
g.cfg.PadDef[i].AnalogDef[ANALOG_RIGHT][ANALOG_XM].JoyEvType,
g.cfg.PadDef[i].AnalogDef[ANALOG_RIGHT][ANALOG_XM].J.d);
fprintf(fp, "RightAnalogYP=%d,%d,%d\n", g.cfg.PadDef[i].AnalogDef[ANALOG_RIGHT][ANALOG_YP].Key,
g.cfg.PadDef[i].AnalogDef[ANALOG_RIGHT][ANALOG_YP].JoyEvType,
g.cfg.PadDef[i].AnalogDef[ANALOG_RIGHT][ANALOG_YP].J.d);
fprintf(fp, "RightAnalogYM=%d,%d,%d\n", g.cfg.PadDef[i].AnalogDef[ANALOG_RIGHT][ANALOG_YM].Key,
g.cfg.PadDef[i].AnalogDef[ANALOG_RIGHT][ANALOG_YM].JoyEvType,
g.cfg.PadDef[i].AnalogDef[ANALOG_RIGHT][ANALOG_YM].J.d);
fprintf(fp, "\n");
}
fclose(fp);
}
long PADconfigure(void) {
if (SDL_WasInit(SDL_INIT_JOYSTICK)) return -1; // cannot change settings on the fly
if (SDL_WasInit(SDL_INIT_JOYSTICK)) return PSE_ERR_FATAL; // cannot change settings on the fly
DoConfiguration();
LoadPADConfig();
return 0;
return PSE_ERR_SUCCESS;
}
void PADabout(void) {
@ -479,7 +143,7 @@ struct {
static const char *XKeysymToString(uint16_t key) {
static char buf[64];
int i = 0;
while (KeyString[i].code != 0) {
if (KeyString[i].code == key) {
strcpy(buf, KeyString[i].desc);
@ -487,82 +151,80 @@ static const char *XKeysymToString(uint16_t key) {
}
i++;
}
sprintf(buf, "0x%.2X", key);
return buf;
}
void GetKeyDescription(char *buf, int joynum, int key) {
const char *hatname[16] = {"Centered", "Up", "Right", "Rightup",
"Down", "", "Rightdown", "", "Left", "Leftup", "", "",
"Leftdown", "", "", ""};
static const char *hatname[16] = {"Centered", "Up", "Right", "Rightup",
"Down", "", "Rightdown", "", "Left", "Leftup", "", "",
"Leftdown", "", "", ""};
void GetKeyDescription(char *buf, int joynum, int key)
{
switch (g.cfg.PadDef[joynum].KeyDef[key].JoyEvType) {
case BUTTON:
sprintf(buf, "Joystick: Button %d", g.cfg.PadDef[joynum].KeyDef[key].J.Button);
sprintf(buf, _("Joystick: Button %d"), g.cfg.PadDef[joynum].KeyDef[key].J.Button);
break;
case AXIS:
sprintf(buf, "Joystick: Axis %d%c", abs(g.cfg.PadDef[joynum].KeyDef[key].J.Axis) - 1,
g.cfg.PadDef[joynum].KeyDef[key].J.Axis > 0 ? '+' : '-');
sprintf(buf, _("Joystick: Axis %d%c"), abs(g.cfg.PadDef[joynum].KeyDef[key].J.Axis) - 1,
g.cfg.PadDef[joynum].KeyDef[key].J.Axis > 0 ? '+' : '-');
break;
case HAT:
sprintf(buf, "Joystick: Hat %d %s", (g.cfg.PadDef[joynum].KeyDef[key].J.Hat >> 8),
hatname[g.cfg.PadDef[joynum].KeyDef[key].J.Hat & 0x0F]);
sprintf(buf, _("Joystick: Hat %d %s"), (g.cfg.PadDef[joynum].KeyDef[key].J.Hat >> 8),
hatname[g.cfg.PadDef[joynum].KeyDef[key].J.Hat & 0x0F]);
break;
case NONE:
default:
buf[0] = '\0';
break;
}
if (g.cfg.PadDef[joynum].KeyDef[key].Key != 0) {
if (buf[0] != '\0') {
strcat(buf, " / ");
}
strcat(buf, "Keyboard:");
strcat(buf, " ");
strcat(buf, XKeysymToString(g.cfg.PadDef[joynum].KeyDef[key].Key));
char keyboardBuf[64] = {0};
snprintf(keyboardBuf, 63, _("Keyboard: %s"), XKeysymToString(g.cfg.PadDef[joynum].KeyDef[key].Key));
strcat(buf, keyboardBuf);
}
}
void GetAnalogDescription(char *buf, int joynum, int analognum, int dir) {
const char *hatname[16] = {"Centered", "Up", "Right", "Rightup",
"Down", "", "Rightdown", "", "Left", "Leftup", "", "",
"Leftdown", "", "", ""};
void GetAnalogDescription(char *buf, int joynum, int analognum, int dir)
{
switch (g.cfg.PadDef[joynum].AnalogDef[analognum][dir].JoyEvType) {
case BUTTON:
sprintf(buf, "Joystick: Button %d", g.cfg.PadDef[joynum].AnalogDef[analognum][dir].J.Button);
sprintf(buf, _("Joystick: Button %d"), g.cfg.PadDef[joynum].AnalogDef[analognum][dir].J.Button);
break;
case AXIS:
sprintf(buf, "Joystick: Axis %d%c", abs(g.cfg.PadDef[joynum].AnalogDef[analognum][dir].J.Axis) - 1,
g.cfg.PadDef[joynum].AnalogDef[analognum][dir].J.Axis > 0 ? '+' : '-');
sprintf(buf, _("Joystick: Axis %d%c"), abs(g.cfg.PadDef[joynum].AnalogDef[analognum][dir].J.Axis) - 1,
g.cfg.PadDef[joynum].AnalogDef[analognum][dir].J.Axis > 0 ? '+' : '-');
break;
case HAT:
sprintf(buf, "Joystick: Hat %d %s", (g.cfg.PadDef[joynum].AnalogDef[analognum][dir].J.Hat >> 8),
hatname[g.cfg.PadDef[joynum].AnalogDef[analognum][dir].J.Hat & 0x0F]);
sprintf(buf, _("Joystick: Hat %d %s"), (g.cfg.PadDef[joynum].AnalogDef[analognum][dir].J.Hat >> 8),
hatname[g.cfg.PadDef[joynum].AnalogDef[analognum][dir].J.Hat & 0x0F]);
break;
case NONE:
default:
buf[0] = '\0';
break;
}
if (g.cfg.PadDef[joynum].AnalogDef[analognum][dir].Key != 0) {
if (buf[0] != '\0') {
strcat(buf, " / ");
}
strcat(buf, "Keyboard:");
strcat(buf, " ");
strcat(buf, XKeysymToString(g.cfg.PadDef[joynum].AnalogDef[analognum][dir].Key));
char keyboardBuf[64] = {0};
snprintf(keyboardBuf, 63, _("Keyboard: %s"), XKeysymToString(g.cfg.PadDef[joynum].AnalogDef[analognum][dir].Key));
strcat(buf, keyboardBuf);
}
}
@ -570,17 +232,17 @@ int CheckKeyDown() {
KeyMap theKeys;
unsigned char *keybytes;
int i;
GetKeys(theKeys);
keybytes = (unsigned char *) theKeys;
for (i = 0; i < 128; i++) {
if (i == kVK_CapsLock) continue; // Ignore capslock
if (keybytes[i >> 3] & (1 << (i & 7)))
return i + 1;
}
return 0;
}
@ -588,41 +250,43 @@ static Sint16 InitialAxisPos[256], PrevAxisPos[256];
#define NUM_AXES(js) (SDL_JoystickNumAxes(js) > 256 ? 256 : SDL_JoystickNumAxes(js))
void InitAxisPos(int padnum) {
void InitAxisPos(int padnum)
{
int i;
SDL_Joystick *js;
if (g.cfg.PadDef[padnum].DevNum >= 0) {
js = SDL_JoystickOpen(g.cfg.PadDef[padnum].DevNum);
SDL_JoystickEventState(SDL_IGNORE);
} else return;
SDL_JoystickUpdate();
for (i = 0; i < NUM_AXES(js); i++) {
InitialAxisPos[i] = PrevAxisPos[i] = SDL_JoystickGetAxis(js, i);
}
SDL_JoystickClose(js);
}
int ReadDKeyEvent(int padnum, int key) {
int ReadDKeyEvent(int padnum, int key)
{
SDL_Joystick *js;
int i, changed = 0, t;
Sint16 axis;
if (g.cfg.PadDef[padnum].DevNum >= 0) {
js = SDL_JoystickOpen(g.cfg.PadDef[padnum].DevNum);
SDL_JoystickEventState(SDL_IGNORE);
} else {
js = NULL;
}
for (t = 0; t < 1000000 / 1000; t++) {
// check joystick events
if (js != NULL) {
SDL_JoystickUpdate();
for (i = 0; i < SDL_JoystickNumButtons(js); i++) {
if (SDL_JoystickGetButton(js, i)) {
g.cfg.PadDef[padnum].KeyDef[key].JoyEvType = BUTTON;
@ -631,7 +295,7 @@ int ReadDKeyEvent(int padnum, int key) {
goto end;
}
}
for (i = 0; i < NUM_AXES(js); i++) {
axis = SDL_JoystickGetAxis(js, i);
if (abs(axis) > 16383 && (abs(axis - PrevAxisPos[i]) > 4096 || abs(axis - InitialAxisPos[i]) > 4096)) {
@ -642,12 +306,12 @@ int ReadDKeyEvent(int padnum, int key) {
}
PrevAxisPos[i] = axis;
}
for (i = 0; i < SDL_JoystickNumHats(js); i++) {
axis = SDL_JoystickGetHat(js, i);
if (axis != SDL_HAT_CENTERED) {
g.cfg.PadDef[padnum].KeyDef[key].JoyEvType = HAT;
if (axis & SDL_HAT_UP) {
g.cfg.PadDef[padnum].KeyDef[key].J.Hat = ((i << 8) | SDL_HAT_UP);
} else if (axis & SDL_HAT_DOWN) {
@ -657,13 +321,13 @@ int ReadDKeyEvent(int padnum, int key) {
} else if (axis & SDL_HAT_RIGHT) {
g.cfg.PadDef[padnum].KeyDef[key].J.Hat = ((i << 8) | SDL_HAT_RIGHT);
}
changed = 1;
goto end;
}
}
}
// check keyboard events
i = CheckKeyDown();
if (i != 0) {
@ -671,41 +335,42 @@ int ReadDKeyEvent(int padnum, int key) {
changed = 1;
goto end;
}
// check mouse events
if (GetCurrentButtonState()) {
changed = 2;
goto end;
}
usleep(1000);
}
end:
if (js != NULL) {
SDL_JoystickClose(js);
}
return changed;
}
int ReadAnalogEvent(int padnum, int analognum, int analogdir) {
int ReadAnalogEvent(int padnum, int analognum, int analogdir)
{
SDL_Joystick *js;
int i, changed = 0, t;
Sint16 axis;
if (g.cfg.PadDef[padnum].DevNum >= 0) {
js = SDL_JoystickOpen(g.cfg.PadDef[padnum].DevNum);
SDL_JoystickEventState(SDL_IGNORE);
} else {
js = NULL;
}
for (t = 0; t < 1000000 / 1000; t++) {
// check joystick events
if (js != NULL) {
SDL_JoystickUpdate();
for (i = 0; i < SDL_JoystickNumButtons(js); i++) {
if (SDL_JoystickGetButton(js, i)) {
g.cfg.PadDef[padnum].AnalogDef[analognum][analogdir].JoyEvType = BUTTON;
@ -714,7 +379,7 @@ int ReadAnalogEvent(int padnum, int analognum, int analogdir) {
goto end;
}
}
for (i = 0; i < NUM_AXES(js); i++) {
axis = SDL_JoystickGetAxis(js, i);
if (abs(axis) > 16383 && (abs(axis - PrevAxisPos[i]) > 4096 || abs(axis - InitialAxisPos[i]) > 4096)) {
@ -725,12 +390,12 @@ int ReadAnalogEvent(int padnum, int analognum, int analogdir) {
}
PrevAxisPos[i] = axis;
}
for (i = 0; i < SDL_JoystickNumHats(js); i++) {
axis = SDL_JoystickGetHat(js, i);
if (axis != SDL_HAT_CENTERED) {
g.cfg.PadDef[padnum].AnalogDef[analognum][analogdir].JoyEvType = HAT;
if (axis & SDL_HAT_UP) {
g.cfg.PadDef[padnum].AnalogDef[analognum][analogdir].J.Hat = ((i << 8) | SDL_HAT_UP);
} else if (axis & SDL_HAT_DOWN) {
@ -740,13 +405,13 @@ int ReadAnalogEvent(int padnum, int analognum, int analogdir) {
} else if (axis & SDL_HAT_RIGHT) {
g.cfg.PadDef[padnum].AnalogDef[analognum][analogdir].J.Hat = ((i << 8) | SDL_HAT_RIGHT);
}
changed = 1;
goto end;
}
}
}
// check keyboard events
i = CheckKeyDown();
if (i != 0) {
@ -754,20 +419,20 @@ int ReadAnalogEvent(int padnum, int analognum, int analogdir) {
changed = 1;
goto end;
}
// check mouse events
if (GetCurrentButtonState()) {
changed = 2;
goto end;
}
usleep(1000);
}
end:
if (js != NULL) {
SDL_JoystickClose(js);
}
return changed;
}

View File

@ -0,0 +1,243 @@
//
// cfgHelper.m
// Pcsxr
//
// Created by C.W. Betts on 8/28/13.
//
//
#include "cfg.h"
#import <Foundation/Foundation.h>
#import "ARCBridge.h"
#import "PadController.h"
#define padType @"Pad Type"
#define deviceNumber @"Device Number"
#define dfKey @"Key Value"
#define joyType @"Joystick Type"
#define joyVal @"Joystick Value"
#define dSelect @"DKEY_SELECT"
#define dStart @"DKEY_START"
#define dUp @"DKEY_UP"
#define dRight @"DKEY_RIGHT"
#define dDown @"DKEY_DOWN"
#define dLeft @"DKEY_LEFT"
#define dL1 @"DKEY_L1"
#define dL2 @"DKEY_L2"
#define dL3 @"DKEY_L3"
#define dR1 @"DKEY_R1"
#define dR2 @"DKEY_R2"
#define dR3 @"DKEY_R3"
#define dTriangle @"DKEY_TRIANGLE"
#define dCircle @"DKEY_CIRCLE"
#define dCross @"DKEY_CROSS"
#define dSquare @"DKEY_SQUARE"
#define dAnalog @"DKEY_ANALOG"
#define dLeftAnalogXP @"LeftAnalogXP"
#define dLeftAnalogXM @"LeftAnalogXM"
#define dLeftAnalogYP @"LeftAnalogYP"
#define dLeftAnalogYM @"LeftAnalogYM"
#define dRightAnalogXP @"RightAnalogXP"
#define dRightAnalogXM @"RightAnalogXM"
#define dRightAnalogYP @"RightAnalogYP"
#define dRightAnalogYM @"RightAnalogYM"
NSDictionary *DefaultPadArray(int padnum)
{
NSMutableDictionary *mutArray = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@(padnum), deviceNumber,
@(PSE_PAD_TYPE_STANDARD), padType,
[NSMutableDictionary dictionaryWithObjectsAndKeys:@8, joyVal, @(BUTTON), joyType, nil], dSelect,
[NSMutableDictionary dictionaryWithObjectsAndKeys:@9, joyVal, @(BUTTON), joyType, nil], dStart,
[NSMutableDictionary dictionaryWithObjectsAndKeys:@(-2), joyVal, @(AXIS), joyType, nil], dUp,
[NSMutableDictionary dictionaryWithObjectsAndKeys:@1, joyVal, @(AXIS), joyType, nil], dRight,
[NSMutableDictionary dictionaryWithObjectsAndKeys:@2, joyVal, @(AXIS), joyType, nil], dDown,
[NSMutableDictionary dictionaryWithObjectsAndKeys:@(-1), joyVal, @(AXIS), joyType, nil], dLeft,
[NSMutableDictionary dictionaryWithObjectsAndKeys:@4, joyVal, @(BUTTON), joyType, nil], dL2,
[NSMutableDictionary dictionaryWithObjectsAndKeys:@6, joyVal, @(BUTTON), joyType, nil], dL1,
[NSMutableDictionary dictionaryWithObjectsAndKeys:@5, joyVal, @(BUTTON), joyType, nil], dR2,
[NSMutableDictionary dictionaryWithObjectsAndKeys:@7, joyVal, @(BUTTON), joyType, nil], dR1,
[NSMutableDictionary dictionaryWithObjectsAndKeys:@0, joyVal, @(BUTTON), joyType, nil], dTriangle,
[NSMutableDictionary dictionaryWithObjectsAndKeys:@1, joyVal, @(BUTTON), joyType, nil], dCircle,
[NSMutableDictionary dictionaryWithObjectsAndKeys:@2, joyVal, @(BUTTON), joyType, nil], dCross,
[NSMutableDictionary dictionaryWithObjectsAndKeys:@3, joyVal, @(BUTTON), joyType, nil], dSquare,
nil];
if (padnum == 0) {
[[mutArray objectForKey:dSelect] setObject:@9 forKey:dfKey];
[[mutArray objectForKey:dStart] setObject:@10 forKey:dfKey];
[[mutArray objectForKey:dUp] setObject:@127 forKey:dfKey];
[[mutArray objectForKey:dRight] setObject:@125 forKey:dfKey];
[[mutArray objectForKey:dDown] setObject:@126 forKey:dfKey];
[[mutArray objectForKey:dLeft] setObject:@124 forKey:dfKey];
[[mutArray objectForKey:dL2] setObject:@16 forKey:dfKey];
[[mutArray objectForKey:dR2] setObject:@18 forKey:dfKey];
[[mutArray objectForKey:dL1] setObject:@14 forKey:dfKey];
[[mutArray objectForKey:dR1] setObject:@15 forKey:dfKey];
[[mutArray objectForKey:dTriangle] setObject:@3 forKey:dfKey];
[[mutArray objectForKey:dCircle] setObject:@8 forKey:dfKey];
[[mutArray objectForKey:dCross] setObject:@7 forKey:dfKey];
[[mutArray objectForKey:dSquare] setObject:@2 forKey:dfKey];
[mutArray setObject:[NSDictionary dictionaryWithObject:@12 forKey:dfKey] forKey:dAnalog];
}
return [NSDictionary dictionaryWithDictionary:mutArray];
}
static NSDictionary *DictionaryFromButtonDef(KEYDEF theKey)
{
NSMutableDictionary *mutDict = [NSMutableDictionary dictionaryWithCapacity:3];
if (theKey.Key) {
[mutDict setObject:@(theKey.Key) forKey:dfKey];
}
if (theKey.JoyEvType != NONE) {
[mutDict setObject:@(theKey.JoyEvType) forKey:joyType];
switch (theKey.JoyEvType) {
case BUTTON:
[mutDict setObject:@(theKey.J.Button) forKey:joyVal];
break;
case HAT:
[mutDict setObject:@(theKey.J.Hat) forKey:joyVal];
break;
case AXIS:
[mutDict setObject:@(theKey.J.Axis) forKey:joyVal];
break;
case NONE:
default:
//[mutDict setObject:@(theKey.J.d) forKey:joyVal];
[mutDict removeObjectForKey:joyType];
break;
}
}
return [NSDictionary dictionaryWithDictionary:mutDict];
}
static void SetKeyFromDictionary(NSDictionary *inDict, KEYDEF *outDef)
{
assert(outDef != NULL);
if (!inDict) {
return;
}
NSNumber *theJoyType = [inDict objectForKey:joyType];
if (theJoyType) {
NSNumber *theJoyVal = [inDict objectForKey:joyVal];
outDef->JoyEvType = [theJoyType unsignedCharValue];
switch (outDef->JoyEvType) {
case BUTTON:
outDef->J.Button = [theJoyVal unsignedShortValue];
break;
case HAT:
outDef->J.Hat = [theJoyVal unsignedShortValue];
break;
case AXIS:
outDef->J.Axis = [theJoyVal shortValue];
break;
default:
break;
}
}
NSNumber *keyVal = [inDict objectForKey:dfKey];
if (keyVal) {
outDef->Key = [keyVal unsignedShortValue];
}
}
void LoadPadArray(int padnum, NSDictionary *nsPrefs)
{
PADDEF *curDef = &g.cfg.PadDef[padnum];
curDef->DevNum = [[nsPrefs objectForKey:deviceNumber] charValue];
curDef->Type = [[nsPrefs objectForKey:padType] unsignedShortValue];
curDef->VisualVibration = 0; //Not implemented on OS X right now.
//Analog buttons
SetKeyFromDictionary([nsPrefs objectForKey:dL3], &curDef->KeyDef[DKEY_L3]);
SetKeyFromDictionary([nsPrefs objectForKey:dR3], &curDef->KeyDef[DKEY_R3]);
SetKeyFromDictionary([nsPrefs objectForKey:dAnalog], &curDef->KeyDef[DKEY_ANALOG]);
//Analog sticks
SetKeyFromDictionary([nsPrefs objectForKey:dLeftAnalogXP], &curDef->AnalogDef[ANALOG_LEFT][ANALOG_XP]);
SetKeyFromDictionary([nsPrefs objectForKey:dLeftAnalogXM], &curDef->AnalogDef[ANALOG_LEFT][ANALOG_XM]);
SetKeyFromDictionary([nsPrefs objectForKey:dLeftAnalogYP], &curDef->AnalogDef[ANALOG_LEFT][ANALOG_YP]);
SetKeyFromDictionary([nsPrefs objectForKey:dLeftAnalogYM], &curDef->AnalogDef[ANALOG_LEFT][ANALOG_YM]);
SetKeyFromDictionary([nsPrefs objectForKey:dRightAnalogXP], &curDef->AnalogDef[ANALOG_RIGHT][ANALOG_XP]);
SetKeyFromDictionary([nsPrefs objectForKey:dRightAnalogXM], &curDef->AnalogDef[ANALOG_RIGHT][ANALOG_XM]);
SetKeyFromDictionary([nsPrefs objectForKey:dRightAnalogYP], &curDef->AnalogDef[ANALOG_RIGHT][ANALOG_YP]);
SetKeyFromDictionary([nsPrefs objectForKey:dRightAnalogYM], &curDef->AnalogDef[ANALOG_RIGHT][ANALOG_YM]);
//Digital shouldurs
SetKeyFromDictionary([nsPrefs objectForKey:dL1], &curDef->KeyDef[DKEY_L1]);
SetKeyFromDictionary([nsPrefs objectForKey:dL2], &curDef->KeyDef[DKEY_L2]);
SetKeyFromDictionary([nsPrefs objectForKey:dR1], &curDef->KeyDef[DKEY_R1]);
SetKeyFromDictionary([nsPrefs objectForKey:dR2], &curDef->KeyDef[DKEY_R2]);
//Digital buttons
SetKeyFromDictionary([nsPrefs objectForKey:dSelect], &curDef->KeyDef[DKEY_SELECT]);
SetKeyFromDictionary([nsPrefs objectForKey:dStart], &curDef->KeyDef[DKEY_START]);
SetKeyFromDictionary([nsPrefs objectForKey:dUp], &curDef->KeyDef[DKEY_UP]);
SetKeyFromDictionary([nsPrefs objectForKey:dRight], &curDef->KeyDef[DKEY_RIGHT]);
SetKeyFromDictionary([nsPrefs objectForKey:dDown], &curDef->KeyDef[DKEY_DOWN]);
SetKeyFromDictionary([nsPrefs objectForKey:dLeft], &curDef->KeyDef[DKEY_LEFT]);
SetKeyFromDictionary([nsPrefs objectForKey:dTriangle], &curDef->KeyDef[DKEY_TRIANGLE]);
SetKeyFromDictionary([nsPrefs objectForKey:dCircle], &curDef->KeyDef[DKEY_CIRCLE]);
SetKeyFromDictionary([nsPrefs objectForKey:dCross], &curDef->KeyDef[DKEY_CROSS]);
SetKeyFromDictionary([nsPrefs objectForKey:dSquare], &curDef->KeyDef[DKEY_SQUARE]);
}
NSDictionary *SavePadArray(int padnum)
{
NSMutableDictionary *mutArray = [NSMutableDictionary dictionary];
PADDEF *curDef = &g.cfg.PadDef[padnum];
[mutArray setObject:@(curDef->DevNum) forKey:deviceNumber];
[mutArray setObject:@(curDef->Type) forKey:padType];
switch (curDef->Type) {
case PSE_PAD_TYPE_ANALOGPAD:
{
[mutArray setObject:DictionaryFromButtonDef(curDef->KeyDef[DKEY_L3]) forKey:dL3];
[mutArray setObject:DictionaryFromButtonDef(curDef->KeyDef[DKEY_R3]) forKey:dR3];
[mutArray setObject:DictionaryFromButtonDef(curDef->KeyDef[DKEY_ANALOG]) forKey:dAnalog];
[mutArray setObject:DictionaryFromButtonDef(curDef->AnalogDef[ANALOG_LEFT][ANALOG_XP]) forKey:dLeftAnalogXP];
[mutArray setObject:DictionaryFromButtonDef(curDef->AnalogDef[ANALOG_LEFT][ANALOG_XM]) forKey:dLeftAnalogXM];
[mutArray setObject:DictionaryFromButtonDef(curDef->AnalogDef[ANALOG_LEFT][ANALOG_YP]) forKey:dLeftAnalogYP];
[mutArray setObject:DictionaryFromButtonDef(curDef->AnalogDef[ANALOG_LEFT][ANALOG_YM]) forKey:dLeftAnalogYM];
[mutArray setObject:DictionaryFromButtonDef(curDef->AnalogDef[ANALOG_RIGHT][ANALOG_XP]) forKey:dRightAnalogXP];
[mutArray setObject:DictionaryFromButtonDef(curDef->AnalogDef[ANALOG_RIGHT][ANALOG_XM]) forKey:dRightAnalogXM];
[mutArray setObject:DictionaryFromButtonDef(curDef->AnalogDef[ANALOG_RIGHT][ANALOG_YP]) forKey:dRightAnalogYP];
[mutArray setObject:DictionaryFromButtonDef(curDef->AnalogDef[ANALOG_RIGHT][ANALOG_YM]) forKey:dRightAnalogYM];
}
//Fall through
case PSE_PAD_TYPE_STANDARD:
{
[mutArray setObject:DictionaryFromButtonDef(curDef->KeyDef[DKEY_L1]) forKey:dL1];
[mutArray setObject:DictionaryFromButtonDef(curDef->KeyDef[DKEY_L2]) forKey:dL2];
[mutArray setObject:DictionaryFromButtonDef(curDef->KeyDef[DKEY_R1]) forKey:dR1];
[mutArray setObject:DictionaryFromButtonDef(curDef->KeyDef[DKEY_R2]) forKey:dR2];
[mutArray setObject:DictionaryFromButtonDef(curDef->KeyDef[DKEY_SELECT]) forKey:dSelect];
[mutArray setObject:DictionaryFromButtonDef(curDef->KeyDef[DKEY_START]) forKey:dStart];
[mutArray setObject:DictionaryFromButtonDef(curDef->KeyDef[DKEY_UP]) forKey:dUp];
[mutArray setObject:DictionaryFromButtonDef(curDef->KeyDef[DKEY_RIGHT]) forKey:dRight];
[mutArray setObject:DictionaryFromButtonDef(curDef->KeyDef[DKEY_DOWN]) forKey:dDown];
[mutArray setObject:DictionaryFromButtonDef(curDef->KeyDef[DKEY_LEFT]) forKey:dLeft];
[mutArray setObject:DictionaryFromButtonDef(curDef->KeyDef[DKEY_TRIANGLE]) forKey:dTriangle];
[mutArray setObject:DictionaryFromButtonDef(curDef->KeyDef[DKEY_CIRCLE]) forKey:dCircle];
[mutArray setObject:DictionaryFromButtonDef(curDef->KeyDef[DKEY_CROSS]) forKey:dCross];
[mutArray setObject:DictionaryFromButtonDef(curDef->KeyDef[DKEY_SQUARE]) forKey:dSquare];
}
break;
default:
break;
}
return [NSDictionary dictionaryWithDictionary:mutArray];
}

View File

@ -8,6 +8,6 @@
NSArray *strings;
__unsafe_unretained Class pluginClass;
}
@property (retain) NSArray *strings;
@property (arcretain) NSArray *strings;
@property (unsafe_unretained) Class pluginClass;
@end

View File

@ -2,18 +2,18 @@
@implementation NamedSlider
@synthesize pluginClass;
@synthesize strings;
#if !__has_feature(objc_arc)
- (void)dealloc
{
self.strings = nil;
self.pluginClass = nil;
[super dealloc];
}
#endif
@synthesize strings;
- (NSString *)stringValue
{
NSInteger index = [self integerValue];
@ -34,4 +34,11 @@
[self sendAction:[self action] to:[self target]];
}
- (void)setIntegerValue:(NSInteger)anInteger
{
[super setIntegerValue:anInteger];
[self sendAction:[self action] to:[self target]];
}
@end

View File

@ -122,17 +122,17 @@ void ReadConfig(void)
@3, @"Volume",
nil], PrefsKey,
nil]];
keyValues = [defaults dictionaryForKey:PrefsKey];
iUseTimer = [[keyValues objectForKey:@"High Compatibility Mode"] boolValue] ? 2 : 0;
iSPUIRQWait = [[keyValues objectForKey:@"SPU IRQ Wait"] boolValue];
iDisStereo = [[keyValues objectForKey:@"Mono Sound Output"] boolValue];
iXAPitch = [[keyValues objectForKey:@"XA Pitch"] boolValue];
iUseInterpolation = [[keyValues objectForKey:@"Interpolation Quality"] intValue];
iUseReverb = [[keyValues objectForKey:@"Reverb Quality"] intValue];
iVolume = 5 - [[keyValues objectForKey:@"Volume"] intValue];
}