1 /*****************************************************************************/
5 /* Read the joystick on systems that support it */
9 /* (C) 1998-2011, Ullrich von Bassewitz */
10 /* Roemerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
41 /*****************************************************************************/
43 /*****************************************************************************/
48 #define JOY_ERR_OK 0 /* No error */
49 #define JOY_ERR_NO_DRIVER 1 /* No driver available */
50 #define JOY_ERR_CANNOT_LOAD 2 /* Error loading driver */
51 #define JOY_ERR_INV_DRIVER 3 /* Invalid driver */
52 #define JOY_ERR_NO_DEVICE 4 /* Device (hardware) not found */
54 /* Argument for the joy_read function */
58 /* The following codes are *indices* into the joy_masks array */
60 #define JOY_DOWN_IDX 1
61 #define JOY_LEFT_IDX 2
62 #define JOY_RIGHT_IDX 3
63 #define JOY_BTN_1_IDX 4 /* Universally available */
64 #define JOY_BTN_2_IDX 5 /* Second fire button if available */
65 #define JOY_BTN_3_IDX 6 /* Third fire button if available */
66 #define JOY_BTN_4_IDX 7 /* Fourth fire button if available */
68 /* Array of masks used to check the return value of joy_read for a state */
69 extern const unsigned char joy_masks[8];
71 /* Macros that evaluate the return code of joy_read */
72 #define JOY_UP(v) ((v) & joy_masks[JOY_UP_IDX])
73 #define JOY_DOWN(v) ((v) & joy_masks[JOY_DOWN_IDX])
74 #define JOY_LEFT(v) ((v) & joy_masks[JOY_LEFT_IDX])
75 #define JOY_RIGHT(v) ((v) & joy_masks[JOY_RIGHT_IDX])
76 #define JOY_BTN_1(v) ((v) & joy_masks[JOY_BTN_1_IDX])
77 #define JOY_BTN_2(v) ((v) & joy_masks[JOY_BTN_2_IDX])
78 #define JOY_BTN_3(v) ((v) & joy_masks[JOY_BTN_3_IDX])
79 #define JOY_BTN_4(v) ((v) & joy_masks[JOY_BTN_4_IDX])
81 /* The name of the standard joystick driver for a platform */
82 extern const char joy_stddrv[];
84 /* The address of the static standard joystick driver for a platform */
85 extern const void joy_static_stddrv[];
89 /*****************************************************************************/
91 /*****************************************************************************/
95 unsigned char __fastcall__ joy_load_driver (const char* driver);
96 /* Load and install a joystick driver. Return an error code. */
98 unsigned char joy_unload (void);
99 /* Uninstall, then unload the currently loaded driver. */
101 unsigned char __fastcall__ joy_install (void* driver);
102 /* Install an already loaded driver. Return an error code. */
104 unsigned char joy_uninstall (void);
105 /* Uninstall the currently loaded driver and return an error code.
106 ** Note: This call does not free allocated memory.
109 unsigned char joy_count (void);
110 /* Return the number of joysticks supported by the driver */
112 unsigned char __fastcall__ joy_read (unsigned char joystick);
113 /* Read a particular joystick */
117 /* End of joystick.h */