1 /** \file   joy-osx.h
2  * \brief   Joystick support for Mac OS X - header
3  *
4  * \author  Christian Vogelgsang <chris@vogelgsang.org>
5  */
6 
7 /*
8  * This file is part of VICE, the Versatile Commodore Emulator.
9  * See README for copyright notice.
10  *
11  *  This program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This program is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24  *  02111-1307  USA.
25  *
26  */
27 
28 #ifndef VICE_JOY_OSX_H
29 #define VICE_JOY_OSX_H
30 
31 #define JOYDEV_NONE    0
32 #define JOYDEV_NUMPAD  1
33 #define JOYDEV_KEYSET1 2
34 #define JOYDEV_KEYSET2 3
35 #define JOYDEV_HID_0   4
36 #define JOYDEV_HID_1   5
37 
38 /* obsolete fallbacks for X11/Gtk */
39 #define JOYDEV_ANALOG_0 4
40 #define JOYDEV_ANALOG_1 5
41 #define JOYDEV_ANALOG_2 6
42 #define JOYDEV_ANALOG_3 7
43 #define JOYDEV_ANALOG_4 8
44 #define JOYDEV_ANALOG_5 9
45 
46 #define JOYSTICK_DESCRIPTOR_MAX_BUTTONS 32
47 #define JOYSTICK_DESCRIPTOR_MAX_AXIS    6
48 #define JOYSTICK_DESCRIPTOR_MAX_HAT_SWITCHES 4
49 
50 #define HID_FIRE        0
51 #define HID_ALT_FIRE    1
52 #define HID_LEFT        2
53 #define HID_RIGHT       3
54 #define HID_UP          4
55 #define HID_DOWN        5
56 #define HID_NUM_BUTTONS 6
57 
58 #define HID_AUTO_FIRE   6
59 #define HID_AUTO_ALT_FIRE 7
60 #define HID_NUM_AUTO_BUTTONS 2
61 
62 #define HID_TOTAL_BUTTONS (HID_NUM_BUTTONS + HID_NUM_AUTO_BUTTONS)
63 
64 #define HID_INVALID_BUTTON  0 /* invalid USB HID button ID */
65 
66 #define HID_X_AXIS      0
67 #define HID_Y_AXIS      1
68 #define HID_NUM_AXIS    2
69 
70 #ifdef HAS_JOYSTICK
71 
72 #include "vice.h"
73 #include "types.h"
74 
75 #ifndef JOY_INTERNAL
76 typedef void joy_hid_descriptor_t;
77 #else
78 #include "joy-osx-hid.h"
79 #endif
80 
81 /* describe an axis */
82 struct joy_axis {
83     char *name;             /* name from joy_hid_axis_map used in VICE */
84     int threshold;          /* threshold given in VICE */
85 
86     int  min_threshold;     /* calculated internal value */
87     int  max_threshold;     /* calculated internal value */
88 
89     int  logical;            /* read logical values instead of physical values */
90     int  min,max;           /* min, max values */
91 
92     int  mapped;            /* is axis successfully mapped by HID driver? */
93 };
94 typedef struct joy_axis joy_axis_t;
95 
96 /* describe a button */
97 struct joy_button {
98     int id;                 /* id of button in HID device */
99     int press;              /* auto fire press delay */
100     int release;            /* auto fire release delay */
101     int counter;            /* counter for auto fire */
102 
103     int mapped;             /* is button successfully mapped by HID driver? */
104 };
105 typedef struct joy_button joy_button_t;
106 
107 /* describe a hat switch */
108 struct joy_hat_switch {
109     int id;
110     int mapped;
111 };
112 typedef struct joy_hat_switch joy_hat_switch_t;
113 
114 /* describe a generic joystick HID device */
115 struct joystick_descriptor  {
116     char *device_name;      /* device name: vid:pid:num */
117     char *button_mapping;   /* set button mapping */
118     char *auto_button_mapping; /* auto fire button mapping */
119 
120     joy_axis_t axis[HID_NUM_AXIS];
121     joy_button_t buttons[HID_TOTAL_BUTTONS];
122     joy_hat_switch_t hat_switch;
123 
124     /* number of buttons and axis available in device */
125     int num_hid_buttons;
126     int num_hid_axis;
127     int num_hid_hat_switches;
128 
129     int mapped; /* is device mapped ? */
130 
131     joy_hid_descriptor_t *hid;
132 };
133 typedef struct joystick_descriptor joystick_descriptor_t;
134 
135 /* access number of joyports and extra joyports for machine */
136 int joy_num_ports;
137 int joy_num_extra_ports;
138 
139 /* UI accesses joy descriptors */
140 joystick_descriptor_t joy_a;
141 joystick_descriptor_t joy_b;
142 
143 /* functions */
144 void joystick_close(void);
145 void joystick(void);
146 
147 void joy_reload_device_list(void);
148 void joy_calc_threshold(int min, int max, int threshold, int *min_t, int *max_t);
149 
150 void joy_reset_axis_range(joystick_descriptor_t *joy, int id);
151 
152 void joystick_ui_reset_device_list(void);
153 const char *joystick_ui_get_next_device_name(int *id);
154 
155 #else
156 
157 void joystick_close(void);
158 
159 #endif  /* HAS_JOYSTICK */
160 
161 #endif /* VICE_JOY_H */
162