| 1 | ;;; Calculate ZSNES buttons for Dualshock controllers |
| 2 | |
| 3 | ;; From: http://blog.brokenfunction.com/2009/07/zsnes-and-a-sixaxis-controller/#comment-56667 |
| 4 | ;; Run zsnes and quit. |
| 5 | ;; Look for the lines (something like) |
| 6 | ;; Device 0 Sony PLAYSTATION(R)3 Controller |
| 7 | ;; 27 axis, 19 buttons, 0 hats, 0 balls |
| 8 | ;; Device 1 Sony PLAYSTATION(R)3 Controller |
| 9 | ;; 27 axis, 19 buttons, 0 hats, 0 balls |
| 10 | |
| 11 | ;; Note the number of axes and buttons for controller 1 (first) and second (2). |
| 12 | ;; e.g. axes1, buttons1, axes2, buttons2 |
| 13 | |
| 14 | ;; Controller 1′s select button (base) will be 256 + (axes1*2) |
| 15 | |
| 16 | ;; Controller 2′s select button (base) will be 256 + (axes1*2) + buttons1 + (axes2*2) |
| 17 | ;; Equivalently, it’s Controller 1′s base + buttons1 + (axes2*2) |
| 18 | |
| 19 | ;; Unfortunately, you can’t use 3 controllers this way, because it has |
| 20 | ;; a hardcoded max offset of 448 (not sure why). It would have to be |
| 21 | ;; recompiled at least to get around this but that might be based on a |
| 22 | ;; dependency. |
| 23 | |
| 24 | ;; You can see the logic for this in zsnes’s source code, in src/linux/sdllink.c in |
| 25 | ;; BOOL InitJoystickInput(void){} |
| 26 | |
| 27 | (define axis-count 29) |
| 28 | (define button-count 17) |
| 29 | |
| 30 | (define (base-button) (+ 256 (* 2 axis-count))) |
| 31 | |
| 32 | (define (base-button-2) |
| 33 | (+ (base-button) button-count (* 2 axis-count))) |
| 34 | |
| 35 | (define (zsnes-buttons js-button) |
| 36 | (values (+ (base-button) js-button) |
| 37 | (+ (base-button-2) js-button))) |