From a1a5e67d90db96b00dfa07efd7b315a74e440293 Mon Sep 17 00:00:00 2001 From: Clinton Ebadi Date: Sun, 23 Nov 2014 22:03:22 -0500 Subject: [PATCH] dualshock 3 -> zsnes button converter zsnes explodes when you attempt to configure a dualshock 3 button in the gui. This lets you convert whatever button/joystick numbers reported by your favorite input driver for a dualshock 3 to the internal button codes used by zsnes. This will work for arbitrary joysticks. You must redefine axis-count and button-count to match your device. --- zsnes-dualshock3-buttons.scm | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 zsnes-dualshock3-buttons.scm diff --git a/zsnes-dualshock3-buttons.scm b/zsnes-dualshock3-buttons.scm new file mode 100644 index 0000000..f457b2a --- /dev/null +++ b/zsnes-dualshock3-buttons.scm @@ -0,0 +1,37 @@ +;;; Calculate ZSNES buttons for Dualshock controllers + +;; From: http://blog.brokenfunction.com/2009/07/zsnes-and-a-sixaxis-controller/#comment-56667 +;; Run zsnes and quit. +;; Look for the lines (something like) +;; Device 0 Sony PLAYSTATION(R)3 Controller +;; 27 axis, 19 buttons, 0 hats, 0 balls +;; Device 1 Sony PLAYSTATION(R)3 Controller +;; 27 axis, 19 buttons, 0 hats, 0 balls + +;; Note the number of axes and buttons for controller 1 (first) and second (2). +;; e.g. axes1, buttons1, axes2, buttons2 + +;; Controller 1′s select button (base) will be 256 + (axes1*2) + +;; Controller 2′s select button (base) will be 256 + (axes1*2) + buttons1 + (axes2*2) +;; Equivalently, it’s Controller 1′s base + buttons1 + (axes2*2) + +;; Unfortunately, you can’t use 3 controllers this way, because it has +;; a hardcoded max offset of 448 (not sure why). It would have to be +;; recompiled at least to get around this but that might be based on a +;; dependency. + +;; You can see the logic for this in zsnes’s source code, in src/linux/sdllink.c in +;; BOOL InitJoystickInput(void){} + +(define axis-count 29) +(define button-count 17) + +(define (base-button) (+ 256 (* 2 axis-count))) + +(define (base-button-2) + (+ (base-button) button-count (* 2 axis-count))) + +(define (zsnes-buttons js-button) + (values (+ (base-button) js-button) + (+ (base-button-2) js-button))) \ No newline at end of file -- 2.20.1