mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-29 12:32:52 +00:00
Remove joystick stuff from Allegro source code.
This commit is contained in:
parent
0d4c1dbf9c
commit
13bb881151
@ -27,7 +27,6 @@ set(ALLEGRO_SRC_FILES
|
||||
src/graphics.c
|
||||
src/gsprite.c
|
||||
src/inline.c
|
||||
src/joystick.c
|
||||
src/keyboard.c
|
||||
src/lbm.c
|
||||
src/libc.c
|
||||
@ -119,10 +118,6 @@ set(ALLEGRO_SRC_WIN_FILES
|
||||
src/win/wgdi.c
|
||||
src/win/wgfxdrv.c
|
||||
src/win/winput.c
|
||||
src/win/wjoydrv.c
|
||||
src/win/wjoydx.c
|
||||
src/win/wjoyhelp.c
|
||||
src/win/wjoyw32.c
|
||||
src/win/wkeybd.c
|
||||
src/win/wmidi.c
|
||||
src/win/wmouse.c
|
||||
@ -138,8 +133,6 @@ set(ALLEGRO_SRC_LINUX_FILES
|
||||
src/linux/fbcon.c
|
||||
src/linux/lconsole.c
|
||||
src/linux/lgfxdrv.c
|
||||
# Listed with UNIX files.
|
||||
# src/linux/ljoy.c
|
||||
src/linux/lkeybd.c
|
||||
src/linux/lmemory.c
|
||||
src/linux/lmouse.c
|
||||
@ -160,8 +153,6 @@ set(ALLEGRO_SRC_LINUX_FILES
|
||||
src/misc/vbeafs.s
|
||||
src/misc/vgaregs.c
|
||||
src/misc/vga.c
|
||||
# src/misc/modex.c
|
||||
# src/misc/modexgfx.s
|
||||
)
|
||||
|
||||
set(ALLEGRO_SRC_UNIX_FILES
|
||||
@ -176,7 +167,6 @@ set(ALLEGRO_SRC_UNIX_FILES
|
||||
src/unix/uesd.c
|
||||
src/unix/ufile.c
|
||||
src/unix/ugfxdrv.c
|
||||
src/unix/ujoydrv.c
|
||||
src/unix/ukeybd.c
|
||||
src/unix/umain.c
|
||||
src/unix/umodules.c
|
||||
@ -190,10 +180,6 @@ set(ALLEGRO_SRC_UNIX_FILES
|
||||
src/unix/usystem.c
|
||||
src/unix/uthreads.c
|
||||
src/unix/utimer.c
|
||||
# src/misc/modexsms.c
|
||||
|
||||
# May be used without enabling the entire Linux console port.
|
||||
src/linux/ljoy.c
|
||||
)
|
||||
|
||||
set(ALLEGRO_SRC_X_FILES
|
||||
@ -214,7 +200,6 @@ set(ALLEGRO_SRC_MACOSX_FILES
|
||||
src/macosx/cadigi.m
|
||||
src/macosx/camidi.m
|
||||
src/macosx/drivers.m
|
||||
src/macosx/hidjoy.m
|
||||
src/macosx/hidman.m
|
||||
src/macosx/keybd.m
|
||||
src/macosx/pcpu.m
|
||||
@ -254,7 +239,6 @@ set(ALLEGRO_INCLUDE_ALLEGRO_FILES
|
||||
include/allegro/font.h
|
||||
include/allegro/gfx.h
|
||||
include/allegro/graphics.h
|
||||
include/allegro/joystick.h
|
||||
include/allegro/keyboard.h
|
||||
include/allegro/lzss.h
|
||||
include/allegro/matrix.h
|
||||
|
@ -32,7 +32,6 @@
|
||||
#include "allegro/mouse.h"
|
||||
#include "allegro/timer.h"
|
||||
#include "allegro/keyboard.h"
|
||||
#include "allegro/joystick.h"
|
||||
|
||||
#include "allegro/palette.h"
|
||||
#include "allegro/gfx.h"
|
||||
|
@ -71,47 +71,6 @@
|
||||
#define cpu_3dnow (cpu_capabilities & CPU_3DNOW)
|
||||
#define cpu_cpuid (cpu_capabilities & CPU_ID)
|
||||
|
||||
#define joy_x (joy[0].stick[0].axis[0].pos)
|
||||
#define joy_y (joy[0].stick[0].axis[1].pos)
|
||||
#define joy_left (joy[0].stick[0].axis[0].d1)
|
||||
#define joy_right (joy[0].stick[0].axis[0].d2)
|
||||
#define joy_up (joy[0].stick[0].axis[1].d1)
|
||||
#define joy_down (joy[0].stick[0].axis[1].d2)
|
||||
#define joy_b1 (joy[0].button[0].b)
|
||||
#define joy_b2 (joy[0].button[1].b)
|
||||
#define joy_b3 (joy[0].button[2].b)
|
||||
#define joy_b4 (joy[0].button[3].b)
|
||||
#define joy_b5 (joy[0].button[4].b)
|
||||
#define joy_b6 (joy[0].button[5].b)
|
||||
#define joy_b7 (joy[0].button[6].b)
|
||||
#define joy_b8 (joy[0].button[7].b)
|
||||
|
||||
#define joy2_x (joy[1].stick[0].axis[0].pos)
|
||||
#define joy2_y (joy[1].stick[0].axis[1].pos)
|
||||
#define joy2_left (joy[1].stick[0].axis[0].d1)
|
||||
#define joy2_right (joy[1].stick[0].axis[0].d2)
|
||||
#define joy2_up (joy[1].stick[0].axis[1].d1)
|
||||
#define joy2_down (joy[1].stick[0].axis[1].d2)
|
||||
#define joy2_b1 (joy[1].button[0].b)
|
||||
#define joy2_b2 (joy[1].button[1].b)
|
||||
|
||||
#define joy_throttle (joy[0].stick[2].axis[0].pos)
|
||||
|
||||
#define joy_hat ((joy[0].stick[1].axis[0].d1) ? 1 : \
|
||||
((joy[0].stick[1].axis[0].d2) ? 3 : \
|
||||
((joy[0].stick[1].axis[1].d1) ? 4 : \
|
||||
((joy[0].stick[1].axis[1].d2) ? 2 : \
|
||||
0))))
|
||||
|
||||
#define JOY_HAT_CENTRE 0
|
||||
#define JOY_HAT_CENTER 0
|
||||
#define JOY_HAT_LEFT 1
|
||||
#define JOY_HAT_DOWN 2
|
||||
#define JOY_HAT_RIGHT 3
|
||||
#define JOY_HAT_UP 4
|
||||
|
||||
AL_FUNC_DEPRECATED(int, initialise_joystick, (void));
|
||||
|
||||
|
||||
/* in case you want to spell 'palette' as 'pallete' */
|
||||
#define PALLETE PALETTE
|
||||
|
@ -247,12 +247,6 @@ AL_VAR(char *, _keyboard_layout);
|
||||
#endif
|
||||
|
||||
|
||||
/* various bits of joystick stuff */
|
||||
AL_VAR(int, _joy_type);
|
||||
|
||||
AL_VAR(int, _joystick_installed);
|
||||
|
||||
|
||||
/* text- and font-related stuff */
|
||||
typedef struct FONT_VTABLE
|
||||
{
|
||||
|
@ -1,145 +0,0 @@
|
||||
/* ______ ___ ___
|
||||
* /\ _ \ /\_ \ /\_ \
|
||||
* \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
|
||||
* \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
|
||||
* \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
|
||||
* \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
|
||||
* \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
|
||||
* /\____/
|
||||
* \_/__/
|
||||
*
|
||||
* Joystick routines.
|
||||
*
|
||||
* By Shawn Hargreaves.
|
||||
*
|
||||
* See readme.txt for copyright information.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ALLEGRO_JOYSTICK_H
|
||||
#define ALLEGRO_JOYSTICK_H
|
||||
|
||||
#include "base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define JOY_TYPE_AUTODETECT -1
|
||||
#define JOY_TYPE_NONE 0
|
||||
|
||||
|
||||
#define MAX_JOYSTICKS 8
|
||||
#define MAX_JOYSTICK_AXIS 3
|
||||
#define MAX_JOYSTICK_STICKS 5
|
||||
#define MAX_JOYSTICK_BUTTONS 32
|
||||
|
||||
|
||||
/* information about a single joystick axis */
|
||||
typedef struct JOYSTICK_AXIS_INFO
|
||||
{
|
||||
int pos;
|
||||
int d1, d2;
|
||||
AL_CONST char *name;
|
||||
} JOYSTICK_AXIS_INFO;
|
||||
|
||||
|
||||
/* information about one or more axis (a slider or directional control) */
|
||||
typedef struct JOYSTICK_STICK_INFO
|
||||
{
|
||||
int flags;
|
||||
int num_axis;
|
||||
JOYSTICK_AXIS_INFO axis[MAX_JOYSTICK_AXIS];
|
||||
AL_CONST char *name;
|
||||
} JOYSTICK_STICK_INFO;
|
||||
|
||||
|
||||
/* information about a joystick button */
|
||||
typedef struct JOYSTICK_BUTTON_INFO
|
||||
{
|
||||
int b;
|
||||
AL_CONST char *name;
|
||||
} JOYSTICK_BUTTON_INFO;
|
||||
|
||||
|
||||
/* information about an entire joystick */
|
||||
typedef struct JOYSTICK_INFO
|
||||
{
|
||||
int flags;
|
||||
int num_sticks;
|
||||
int num_buttons;
|
||||
JOYSTICK_STICK_INFO stick[MAX_JOYSTICK_STICKS];
|
||||
JOYSTICK_BUTTON_INFO button[MAX_JOYSTICK_BUTTONS];
|
||||
} JOYSTICK_INFO;
|
||||
|
||||
|
||||
/* joystick status flags */
|
||||
#define JOYFLAG_DIGITAL 1
|
||||
#define JOYFLAG_ANALOGUE 2
|
||||
#define JOYFLAG_CALIB_DIGITAL 4
|
||||
#define JOYFLAG_CALIB_ANALOGUE 8
|
||||
#define JOYFLAG_CALIBRATE 16
|
||||
#define JOYFLAG_SIGNED 32
|
||||
#define JOYFLAG_UNSIGNED 64
|
||||
|
||||
|
||||
/* alternative spellings */
|
||||
#define JOYFLAG_ANALOG JOYFLAG_ANALOGUE
|
||||
#define JOYFLAG_CALIB_ANALOG JOYFLAG_CALIB_ANALOGUE
|
||||
|
||||
|
||||
/* global joystick information */
|
||||
AL_ARRAY(JOYSTICK_INFO, joy);
|
||||
AL_VAR(int, num_joysticks);
|
||||
|
||||
|
||||
typedef struct JOYSTICK_DRIVER /* driver for reading joystick input */
|
||||
{
|
||||
int id;
|
||||
AL_CONST char *name;
|
||||
AL_CONST char *desc;
|
||||
AL_CONST char *ascii_name;
|
||||
AL_METHOD(int, init, (void));
|
||||
AL_METHOD(void, exit, (void));
|
||||
AL_METHOD(int, poll, (void));
|
||||
AL_METHOD(int, save_data, (void));
|
||||
AL_METHOD(int, load_data, (void));
|
||||
AL_METHOD(AL_CONST char *, calibrate_name, (int n));
|
||||
AL_METHOD(int, calibrate, (int n));
|
||||
} JOYSTICK_DRIVER;
|
||||
|
||||
|
||||
AL_VAR(JOYSTICK_DRIVER, joystick_none);
|
||||
AL_VAR(JOYSTICK_DRIVER *, joystick_driver);
|
||||
AL_ARRAY(_DRIVER_INFO, _joystick_driver_list);
|
||||
|
||||
|
||||
/* macros for constructing the driver list */
|
||||
#define BEGIN_JOYSTICK_DRIVER_LIST \
|
||||
_DRIVER_INFO _joystick_driver_list[] = \
|
||||
{
|
||||
|
||||
#define END_JOYSTICK_DRIVER_LIST \
|
||||
{ JOY_TYPE_NONE, &joystick_none, TRUE }, \
|
||||
{ 0, NULL, 0 } \
|
||||
};
|
||||
|
||||
|
||||
AL_FUNC(int, install_joystick, (int type));
|
||||
AL_FUNC(void, remove_joystick, (void));
|
||||
|
||||
AL_FUNC(int, poll_joystick, (void));
|
||||
|
||||
AL_FUNC(int, save_joystick_data, (AL_CONST char *filename));
|
||||
AL_FUNC(int, load_joystick_data, (AL_CONST char *filename));
|
||||
|
||||
AL_FUNC(AL_CONST char *, calibrate_joystick_name, (int n));
|
||||
AL_FUNC(int, calibrate_joystick, (int n));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ifndef ALLEGRO_JOYSTICK_H */
|
||||
|
||||
|
@ -31,7 +31,6 @@ extern _DRIVER_INFO _linux_gfx_driver_list[];
|
||||
extern _DRIVER_INFO _linux_keyboard_driver_list[];
|
||||
extern _DRIVER_INFO _linux_mouse_driver_list[];
|
||||
extern _DRIVER_INFO _linux_timer_driver_list[];
|
||||
/* _linux_joystick_driver_list is in aintunix.h */
|
||||
|
||||
|
||||
/****************************************/
|
||||
|
@ -181,8 +181,6 @@ extern struct bg_manager _bg_man_sigalrm;
|
||||
|
||||
extern struct bg_manager *_unix_bg_man;
|
||||
|
||||
extern _DRIVER_INFO _linux_joystick_driver_list[]; /* also in aintlnx.h */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -134,32 +134,6 @@ AL_FUNC(int, mouse_set_syscursor, (void));
|
||||
AL_FUNC(int, mouse_set_sysmenu, (int state));
|
||||
|
||||
|
||||
/* joystick routines */
|
||||
#define WINDOWS_MAX_AXES 6
|
||||
|
||||
#define WINDOWS_JOYSTICK_INFO_MEMBERS \
|
||||
int caps; \
|
||||
int num_axes; \
|
||||
int axis[WINDOWS_MAX_AXES]; \
|
||||
char *axis_name[WINDOWS_MAX_AXES]; \
|
||||
int hat; \
|
||||
char *hat_name; \
|
||||
int num_buttons; \
|
||||
int button[MAX_JOYSTICK_BUTTONS]; \
|
||||
char *button_name[MAX_JOYSTICK_BUTTONS];
|
||||
|
||||
typedef struct WINDOWS_JOYSTICK_INFO {
|
||||
WINDOWS_JOYSTICK_INFO_MEMBERS
|
||||
} WINDOWS_JOYSTICK_INFO;
|
||||
|
||||
AL_FUNC(int, win_add_joystick, (WINDOWS_JOYSTICK_INFO *win_joy));
|
||||
AL_FUNC(void, win_remove_all_joysticks, (void));
|
||||
AL_FUNC(int, win_update_joystick_status, (int n, WINDOWS_JOYSTICK_INFO *win_joy));
|
||||
|
||||
AL_FUNC(int, joystick_dinput_acquire, (void));
|
||||
AL_FUNC(int, joystick_dinput_unacquire, (void));
|
||||
|
||||
|
||||
/* thread routines */
|
||||
AL_FUNC(void, _win_thread_init, (void));
|
||||
AL_FUNC(void, _win_thread_exit, (void));
|
||||
|
@ -107,9 +107,5 @@ AL_VAR(DIGI_DRIVER, digi_sound_manager);
|
||||
AL_VAR(MIDI_DRIVER, midi_core_audio);
|
||||
AL_VAR(MIDI_DRIVER, midi_quicktime);
|
||||
|
||||
/* Joystick drivers */
|
||||
#define JOYSTICK_HID AL_ID('H','I','D','J')
|
||||
AL_VAR(JOYSTICK_DRIVER, joystick_hid);
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -130,18 +130,3 @@ AL_VAR(GFX_DRIVER, gfx_gdi);
|
||||
#define MIDI_WIN32_IN(n) AL_ID('W','3','2','A'+(n))
|
||||
|
||||
|
||||
|
||||
/*******************************************/
|
||||
/************ joystick drivers *************/
|
||||
/*******************************************/
|
||||
#define JOY_TYPE_DIRECTX AL_ID('D','X',' ',' ')
|
||||
#define JOY_TYPE_WIN32 AL_ID('W','3','2',' ')
|
||||
|
||||
AL_VAR(JOYSTICK_DRIVER, joystick_directx);
|
||||
AL_VAR(JOYSTICK_DRIVER, joystick_win32);
|
||||
|
||||
#define JOYSTICK_DRIVER_DIRECTX \
|
||||
{ JOY_TYPE_DIRECTX, &joystick_directx, TRUE },
|
||||
|
||||
#define JOYSTICK_DRIVER_WIN32 \
|
||||
{ JOY_TYPE_WIN32, &joystick_win32, TRUE },
|
||||
|
@ -234,7 +234,6 @@ typedef struct SYSTEM_DRIVER
|
||||
AL_METHOD(_DRIVER_INFO *, midi_drivers, (void));
|
||||
AL_METHOD(_DRIVER_INFO *, keyboard_drivers, (void));
|
||||
AL_METHOD(_DRIVER_INFO *, mouse_drivers, (void));
|
||||
AL_METHOD(_DRIVER_INFO *, joystick_drivers, (void));
|
||||
AL_METHOD(_DRIVER_INFO *, timer_drivers, (void));
|
||||
} SYSTEM_DRIVER;
|
||||
|
||||
|
@ -758,7 +758,7 @@ SYSTEM_DRIVER system_none =
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
||||
sys_no_driver, sys_no_driver, sys_no_driver, sys_no_driver,
|
||||
sys_no_driver, sys_no_driver, sys_no_driver,
|
||||
sys_no_driver, sys_no_driver, sys_no_driver
|
||||
};
|
||||
|
||||
|
@ -1,358 +0,0 @@
|
||||
/* ______ ___ ___
|
||||
* /\ _ \ /\_ \ /\_ \
|
||||
* \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
|
||||
* \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
|
||||
* \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
|
||||
* \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
|
||||
* \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
|
||||
* /\____/
|
||||
* \_/__/
|
||||
*
|
||||
* High level joystick input framework.
|
||||
*
|
||||
* By Shawn Hargreaves.
|
||||
*
|
||||
* See readme.txt for copyright information.
|
||||
*/
|
||||
|
||||
|
||||
#include "allegro.h"
|
||||
#include "allegro/internal/aintern.h"
|
||||
|
||||
|
||||
|
||||
/* dummy driver for when no joystick is present */
|
||||
static int nojoy_ret0(void) { return 0; }
|
||||
static void nojoy_void(void) { }
|
||||
|
||||
|
||||
JOYSTICK_DRIVER joystick_none =
|
||||
{
|
||||
JOY_TYPE_NONE,
|
||||
empty_string,
|
||||
empty_string,
|
||||
"No joystick",
|
||||
nojoy_ret0,
|
||||
nojoy_void,
|
||||
nojoy_ret0,
|
||||
NULL, NULL,
|
||||
NULL, NULL
|
||||
};
|
||||
|
||||
|
||||
int _joystick_installed = FALSE;
|
||||
|
||||
JOYSTICK_DRIVER *joystick_driver = NULL;
|
||||
|
||||
int _joy_type = JOY_TYPE_NONE;
|
||||
|
||||
JOYSTICK_INFO joy[MAX_JOYSTICKS];
|
||||
int num_joysticks = 0;
|
||||
|
||||
static int joy_loading = FALSE;
|
||||
|
||||
|
||||
|
||||
/* clear_joystick_vars:
|
||||
* Resets the joystick state variables to their default values.
|
||||
*/
|
||||
static void clear_joystick_vars(void)
|
||||
{
|
||||
AL_CONST char *unused = get_config_text("unused");
|
||||
int i, j, k;
|
||||
|
||||
#define ARRAY_SIZE(a) ((int)sizeof((a)) / (int)sizeof((a)[0]))
|
||||
|
||||
for (i=0; i<ARRAY_SIZE(joy); i++) {
|
||||
joy[i].flags = 0;
|
||||
joy[i].num_sticks = 0;
|
||||
joy[i].num_buttons = 0;
|
||||
|
||||
for (j=0; j<ARRAY_SIZE(joy[i].stick); j++) {
|
||||
joy[i].stick[j].flags = 0;
|
||||
joy[i].stick[j].num_axis = 0;
|
||||
joy[i].stick[j].name = unused;
|
||||
|
||||
for (k=0; k<ARRAY_SIZE(joy[i].stick[j].axis); k++) {
|
||||
joy[i].stick[j].axis[k].pos = 0;
|
||||
joy[i].stick[j].axis[k].d1 = FALSE;
|
||||
joy[i].stick[j].axis[k].d2 = FALSE;
|
||||
joy[i].stick[j].axis[k].name = unused;
|
||||
}
|
||||
}
|
||||
|
||||
for (j=0; j<ARRAY_SIZE(joy[i].button); j++) {
|
||||
joy[i].button[j].b = FALSE;
|
||||
joy[i].button[j].name = unused;
|
||||
}
|
||||
}
|
||||
|
||||
num_joysticks = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* update_calib:
|
||||
* Updates the calibration flags for the specified joystick structure.
|
||||
*/
|
||||
static void update_calib(int n)
|
||||
{
|
||||
int c = FALSE;
|
||||
int i;
|
||||
|
||||
for (i=0; i<joy[n].num_sticks; i++) {
|
||||
if (joy[n].stick[i].flags & (JOYFLAG_CALIB_DIGITAL | JOYFLAG_CALIB_ANALOGUE)) {
|
||||
joy[n].stick[i].flags |= JOYFLAG_CALIBRATE;
|
||||
c = TRUE;
|
||||
}
|
||||
else
|
||||
joy[n].stick[i].flags &= ~JOYFLAG_CALIBRATE;
|
||||
}
|
||||
|
||||
if (c)
|
||||
joy[n].flags |= JOYFLAG_CALIBRATE;
|
||||
else
|
||||
joy[n].flags &= ~JOYFLAG_CALIBRATE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* install_joystick:
|
||||
* Initialises the joystick module.
|
||||
*/
|
||||
int install_joystick(int type)
|
||||
{
|
||||
_DRIVER_INFO *driver_list;
|
||||
int c;
|
||||
|
||||
if (_joystick_installed)
|
||||
return 0;
|
||||
|
||||
clear_joystick_vars();
|
||||
|
||||
usetc(allegro_error, 0);
|
||||
|
||||
if (system_driver->joystick_drivers)
|
||||
driver_list = system_driver->joystick_drivers();
|
||||
else
|
||||
driver_list = _joystick_driver_list;
|
||||
|
||||
/* search table for a specific driver */
|
||||
for (c=0; driver_list[c].driver; c++) {
|
||||
if (driver_list[c].id == type) {
|
||||
joystick_driver = driver_list[c].driver;
|
||||
joystick_driver->name = joystick_driver->desc = get_config_text(joystick_driver->ascii_name);
|
||||
_joy_type = type;
|
||||
if (joystick_driver->init() != 0) {
|
||||
if (!ugetc(allegro_error))
|
||||
uszprintf(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("%s not found"), joystick_driver->name);
|
||||
joystick_driver = NULL;
|
||||
_joy_type = JOY_TYPE_NONE;
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* autodetect driver */
|
||||
if (!joystick_driver) {
|
||||
if (!joy_loading) {
|
||||
if (load_joystick_data(NULL) != -1)
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (c=0; driver_list[c].driver; c++) {
|
||||
if (driver_list[c].autodetect) {
|
||||
joystick_driver = driver_list[c].driver;
|
||||
joystick_driver->name = joystick_driver->desc = get_config_text(joystick_driver->ascii_name);
|
||||
_joy_type = driver_list[c].id;
|
||||
if (joystick_driver->init() == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!driver_list[c].driver) {
|
||||
ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text ("No joysticks found"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (c=0; c<num_joysticks; c++)
|
||||
update_calib(c);
|
||||
|
||||
poll_joystick();
|
||||
|
||||
_add_exit_func(remove_joystick, "remove_joystick");
|
||||
_joystick_installed = TRUE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* remove_joystick:
|
||||
* Shuts down the joystick module.
|
||||
*/
|
||||
void remove_joystick(void)
|
||||
{
|
||||
if (_joystick_installed) {
|
||||
joystick_driver->exit();
|
||||
|
||||
joystick_driver = NULL;
|
||||
_joy_type = JOY_TYPE_NONE;
|
||||
|
||||
clear_joystick_vars();
|
||||
|
||||
_remove_exit_func(remove_joystick);
|
||||
_joystick_installed = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* poll_joystick:
|
||||
* Reads the current input state into the joystick status variables.
|
||||
*/
|
||||
int poll_joystick(void)
|
||||
{
|
||||
if ((joystick_driver) && (joystick_driver->poll))
|
||||
return joystick_driver->poll();
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* save_joystick_data:
|
||||
* After calibrating a joystick, this function can be used to save the
|
||||
* information into the specified file, from where it can later be
|
||||
* restored by calling load_joystick_data().
|
||||
*/
|
||||
int save_joystick_data(AL_CONST char *filename)
|
||||
{
|
||||
char tmp1[64], tmp2[64];
|
||||
|
||||
if (filename) {
|
||||
push_config_state();
|
||||
set_config_file(filename);
|
||||
}
|
||||
|
||||
set_config_id(uconvert_ascii("joystick", tmp1), uconvert_ascii("joytype", tmp2), _joy_type);
|
||||
|
||||
if ((joystick_driver) && (joystick_driver->save_data))
|
||||
joystick_driver->save_data();
|
||||
|
||||
if (filename)
|
||||
pop_config_state();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* load_joystick_data:
|
||||
* Restores a set of joystick calibration data previously saved by
|
||||
* save_joystick_data().
|
||||
*/
|
||||
int load_joystick_data(AL_CONST char *filename)
|
||||
{
|
||||
char tmp1[64], tmp2[64];
|
||||
int ret, c;
|
||||
|
||||
joy_loading = TRUE;
|
||||
|
||||
if (_joystick_installed)
|
||||
remove_joystick();
|
||||
|
||||
if (filename) {
|
||||
push_config_state();
|
||||
set_config_file(filename);
|
||||
}
|
||||
|
||||
_joy_type = get_config_id(uconvert_ascii("joystick", tmp1), uconvert_ascii("joytype", tmp2), -1);
|
||||
|
||||
if (_joy_type < 0) {
|
||||
_joy_type = JOY_TYPE_NONE;
|
||||
ret = -1;
|
||||
}
|
||||
else {
|
||||
ret = install_joystick(_joy_type);
|
||||
|
||||
if (ret == 0) {
|
||||
if (joystick_driver->load_data)
|
||||
ret = joystick_driver->load_data();
|
||||
}
|
||||
else
|
||||
ret = -2;
|
||||
}
|
||||
|
||||
if (filename)
|
||||
pop_config_state();
|
||||
|
||||
if (ret == 0) {
|
||||
for (c=0; c<num_joysticks; c++)
|
||||
update_calib(c);
|
||||
|
||||
poll_joystick();
|
||||
}
|
||||
|
||||
joy_loading = FALSE;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* calibrate_joystick_name:
|
||||
* Returns the name of the next calibration operation to be performed on
|
||||
* the specified stick.
|
||||
*/
|
||||
AL_CONST char *calibrate_joystick_name(int n)
|
||||
{
|
||||
if ((!joystick_driver) || (!joystick_driver->calibrate_name) ||
|
||||
(!(joy[n].flags & JOYFLAG_CALIBRATE)))
|
||||
return NULL;
|
||||
|
||||
return joystick_driver->calibrate_name(n);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* calibrate_joystick:
|
||||
* Performs the next caliabration operation required for the specified stick.
|
||||
*/
|
||||
int calibrate_joystick(int n)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if ((!joystick_driver) || (!joystick_driver->calibrate) ||
|
||||
(!(joy[n].flags & JOYFLAG_CALIBRATE)))
|
||||
return -1;
|
||||
|
||||
ret = joystick_driver->calibrate(n);
|
||||
|
||||
if (ret == 0)
|
||||
update_calib(n);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* initialise_joystick:
|
||||
* Bodge function to preserve backward compatibility with the old API.
|
||||
*/
|
||||
int initialise_joystick(void)
|
||||
{
|
||||
int type = _joy_type;
|
||||
|
||||
if (_joystick_installed)
|
||||
remove_joystick();
|
||||
|
||||
#ifdef JOY_TYPE_STANDARD
|
||||
if (type == JOY_TYPE_NONE)
|
||||
type = JOY_TYPE_STANDARD;
|
||||
#endif
|
||||
|
||||
return install_joystick(type);
|
||||
}
|
@ -1,288 +0,0 @@
|
||||
/* ______ ___ ___
|
||||
* /\ _ \ /\_ \ /\_ \
|
||||
* \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
|
||||
* \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
|
||||
* \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
|
||||
* \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
|
||||
* \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
|
||||
* /\____/
|
||||
* \_/__/
|
||||
*
|
||||
* Linux joystick driver.
|
||||
*
|
||||
* By George Foot.
|
||||
*
|
||||
* Modified by Peter Wang.
|
||||
*
|
||||
* See readme.txt for copyright information.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#define ALLEGRO_NO_KEY_DEFINES
|
||||
|
||||
#include "allegro.h"
|
||||
#include "allegro/platform/aintunix.h"
|
||||
#include "allegro/internal/aintern.h"
|
||||
|
||||
|
||||
#ifdef ALLEGRO_HAVE_LINUX_JOYSTICK_H
|
||||
|
||||
/* To be safe, include sys/types.h before linux/joystick.h to avoid conflicting
|
||||
* definitions of fd_set.
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <linux/joystick.h>
|
||||
|
||||
|
||||
#define TOTAL_JOYSTICK_AXES (MAX_JOYSTICK_STICKS * MAX_JOYSTICK_AXIS)
|
||||
|
||||
static int joy_fd[MAX_JOYSTICKS];
|
||||
static JOYSTICK_AXIS_INFO *axis[MAX_JOYSTICKS][TOTAL_JOYSTICK_AXES];
|
||||
|
||||
|
||||
|
||||
static int joy_init(void)
|
||||
{
|
||||
JOYSTICK_INFO *j;
|
||||
AL_CONST char *device_name = NULL;
|
||||
char tmp[128], tmp1[128], tmp2[128];
|
||||
unsigned int raw_version;
|
||||
struct {
|
||||
unsigned char build, minor, major;
|
||||
} version;
|
||||
char num_axes, num_buttons;
|
||||
int throttle;
|
||||
int i, s, a, b;
|
||||
|
||||
for (i = 0; i < MAX_JOYSTICKS; i++) {
|
||||
/* Check for a user override on the device to use. */
|
||||
uszprintf(tmp, sizeof(tmp), uconvert_ascii("joystick_device_%d", tmp1), i);
|
||||
device_name = get_config_string(uconvert_ascii("joystick", tmp1), tmp, NULL);
|
||||
|
||||
/* Special case for the first joystick. */
|
||||
if (!device_name && (i == 0))
|
||||
device_name = get_config_string(uconvert_ascii("joystick", tmp1),
|
||||
uconvert_ascii("joystick_device", tmp2),
|
||||
NULL);
|
||||
|
||||
if (device_name) {
|
||||
joy_fd[i] = open(uconvert_toascii(device_name, tmp), O_RDONLY|O_NONBLOCK);
|
||||
if (joy_fd[i] == -1)
|
||||
break;
|
||||
}
|
||||
else {
|
||||
snprintf(tmp, sizeof(tmp), "/dev/input/js%d", i);
|
||||
tmp[sizeof(tmp)-1] = 0;
|
||||
|
||||
joy_fd[i] = open(tmp, O_RDONLY|O_NONBLOCK);
|
||||
if (joy_fd[i] == -1) {
|
||||
snprintf(tmp, sizeof(tmp), "/dev/js%d", i);
|
||||
tmp[sizeof(tmp)-1] = 0;
|
||||
|
||||
joy_fd[i] = open(tmp, O_RDONLY|O_NONBLOCK);
|
||||
if (joy_fd[i] == -1)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ioctl(joy_fd[i], JSIOCGVERSION, &raw_version) < 0) {
|
||||
/* NOTE: IOCTL fails if the joystick API is version 0.x */
|
||||
uszprintf(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Your Linux joystick API is version 0.x which is unsupported."));
|
||||
return -1;
|
||||
}
|
||||
|
||||
version.major = (raw_version & 0xFF0000) >> 16;
|
||||
version.minor = (raw_version & 0xFF00) >> 8;
|
||||
version.build = (raw_version & 0xFF);
|
||||
|
||||
ioctl(joy_fd[i], JSIOCGAXES, &num_axes);
|
||||
ioctl(joy_fd[i], JSIOCGBUTTONS, &num_buttons);
|
||||
|
||||
if (num_axes > TOTAL_JOYSTICK_AXES)
|
||||
num_axes = TOTAL_JOYSTICK_AXES;
|
||||
|
||||
if (num_buttons > MAX_JOYSTICK_BUTTONS)
|
||||
num_buttons = MAX_JOYSTICK_BUTTONS;
|
||||
|
||||
/* User is allowed to override our simple assumption of which
|
||||
* axis number (kernel) the throttle is located at. */
|
||||
uszprintf(tmp, sizeof(tmp), uconvert_ascii("throttle_axis_%d", tmp1), i);
|
||||
throttle = get_config_int(uconvert_ascii("joystick", tmp1), tmp, -1);
|
||||
if (throttle == -1) {
|
||||
throttle = get_config_int(uconvert_ascii("joystick", tmp1),
|
||||
uconvert_ascii("throttle_axis", tmp2), -1);
|
||||
}
|
||||
|
||||
/* Each pair of axes is assumed to make up a stick unless it
|
||||
* is the sole remaining axis, or has been user specified, in
|
||||
* which case it is a throttle. */
|
||||
|
||||
j = &joy[i];
|
||||
j->flags = JOYFLAG_ANALOGUE;
|
||||
|
||||
for (s = 0, a = 0; (s < MAX_JOYSTICK_STICKS) && (a < num_axes); s++) {
|
||||
if ((a == throttle) || (a == num_axes-1)) {
|
||||
/* One axis throttle */
|
||||
j->stick[s].flags = JOYFLAG_ANALOGUE | JOYFLAG_UNSIGNED;
|
||||
j->stick[s].num_axis = 1;
|
||||
j->stick[s].axis[0].name = get_config_text("Throttle");
|
||||
j->stick[s].name = ustrdup(j->stick[s].axis[0].name);
|
||||
axis[i][a++] = &j->stick[s].axis[0];
|
||||
}
|
||||
else {
|
||||
/* Two axis stick. */
|
||||
j->stick[s].flags = JOYFLAG_ANALOGUE | JOYFLAG_SIGNED;
|
||||
j->stick[s].num_axis = 2;
|
||||
j->stick[s].axis[0].name = get_config_text("X");
|
||||
j->stick[s].axis[1].name = get_config_text("Y");
|
||||
j->stick[s].name = _AL_MALLOC_ATOMIC(32);
|
||||
ASSERT(j->stick[s].name);
|
||||
uszprintf((char *)j->stick[s].name, 32, get_config_text("Stick %d"), s+1);
|
||||
axis[i][a++] = &j->stick[s].axis[0];
|
||||
axis[i][a++] = &j->stick[s].axis[1];
|
||||
}
|
||||
}
|
||||
|
||||
j->num_sticks = s;
|
||||
|
||||
for (b = 0; b < num_buttons; b++) {
|
||||
j->button[b].name = _AL_MALLOC_ATOMIC(16);
|
||||
ASSERT(j->button[b].name);
|
||||
uszprintf((char *)j->button[b].name, 16, uconvert_ascii("%c", tmp), 'A' + b);
|
||||
}
|
||||
|
||||
j->num_buttons = num_buttons;
|
||||
}
|
||||
|
||||
num_joysticks = i;
|
||||
if (num_joysticks == 0) {
|
||||
uszprintf(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Unable to open %s: %s"),
|
||||
device_name ? device_name : uconvert_ascii("/dev/js0", tmp), ustrerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void joy_exit(void)
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0; i < num_joysticks; i++) {
|
||||
close(joy_fd[i]);
|
||||
for (j = 0; j < joy[i].num_sticks; j++)
|
||||
_AL_FREE((void *)joy[i].stick[j].name);
|
||||
for (j = 0; j < joy[i].num_buttons; j++)
|
||||
_AL_FREE((void *)joy[i].button[j].name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void set_axis(JOYSTICK_AXIS_INFO *axis, int value)
|
||||
{
|
||||
if (axis) {
|
||||
axis->pos = value * 127 / 32767;
|
||||
axis->d1 = (value < -8192);
|
||||
axis->d2 = (value > 8192);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int joy_poll(void)
|
||||
{
|
||||
fd_set set;
|
||||
struct timeval tv;
|
||||
struct js_event e[32];
|
||||
int i, ready;
|
||||
int bytes, n, k;
|
||||
|
||||
for (i = 0; i < num_joysticks; i++) {
|
||||
tv.tv_sec = tv.tv_usec = 0;
|
||||
FD_ZERO(&set);
|
||||
FD_SET(joy_fd[i], &set);
|
||||
|
||||
ready = select(FD_SETSIZE, &set, NULL, NULL, &tv);
|
||||
if (ready <= 0)
|
||||
continue;
|
||||
|
||||
while ((bytes = read(joy_fd[i], e, sizeof(e))) > 0) {
|
||||
n = bytes / sizeof(e[0]);
|
||||
for (k = 0; k < n; k++) {
|
||||
if (e[k].type & JS_EVENT_BUTTON) {
|
||||
if (e[k].number < joy[i].num_buttons)
|
||||
joy[i].button[e[k].number].b = e[k].value;
|
||||
}
|
||||
else if (e[k].type & JS_EVENT_AXIS) {
|
||||
if (e[k].number < TOTAL_JOYSTICK_AXES)
|
||||
set_axis (axis[i][e[k].number], e[k].value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int joy_save(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int joy_load(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static AL_CONST char *joy_calib_name(int n)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int joy_calib(int n)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
static JOYSTICK_DRIVER joystick_linux_analogue = {
|
||||
JOY_TYPE_LINUX_ANALOGUE,
|
||||
empty_string,
|
||||
empty_string,
|
||||
"Linux analogue joystick(s)",
|
||||
joy_init,
|
||||
joy_exit,
|
||||
joy_poll,
|
||||
joy_save,
|
||||
joy_load,
|
||||
joy_calib_name,
|
||||
joy_calib
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* list the available drivers */
|
||||
_DRIVER_INFO _linux_joystick_driver_list[] = {
|
||||
#ifdef ALLEGRO_HAVE_LINUX_JOYSTICK_H
|
||||
{ JOY_TYPE_LINUX_ANALOGUE, &joystick_linux_analogue, TRUE },
|
||||
#endif
|
||||
{ JOY_TYPE_NONE, &joystick_none, TRUE },
|
||||
{ 0, 0, 0 }
|
||||
};
|
||||
|
@ -55,7 +55,6 @@ static void sys_linux_message (AL_CONST char *msg);
|
||||
make_getter (_linux, keyboard)
|
||||
make_getter (_linux, mouse)
|
||||
make_getter (_linux, timer)
|
||||
make_getter (_linux, joystick)
|
||||
#undef make_getter
|
||||
|
||||
|
||||
@ -111,7 +110,6 @@ SYSTEM_DRIVER system_linux =
|
||||
get_midi_driver_list,
|
||||
get_keyboard_driver_list,
|
||||
get_mouse_driver_list,
|
||||
get_joystick_driver_list,
|
||||
get_timer_driver_list
|
||||
};
|
||||
|
||||
|
@ -62,8 +62,3 @@ BEGIN_MIDI_DRIVER_LIST
|
||||
{ MIDI_CORE_AUDIO, &midi_core_audio, TRUE },
|
||||
{ MIDI_QUICKTIME, &midi_quicktime, TRUE },
|
||||
END_MIDI_DRIVER_LIST
|
||||
|
||||
|
||||
BEGIN_JOYSTICK_DRIVER_LIST
|
||||
{ JOYSTICK_HID, &joystick_hid, TRUE },
|
||||
END_JOYSTICK_DRIVER_LIST
|
||||
|
@ -1,299 +0,0 @@
|
||||
/* ______ ___ ___
|
||||
* /\ _ \ /\_ \ /\_ \
|
||||
* \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
|
||||
* \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
|
||||
* \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
|
||||
* \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
|
||||
* \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
|
||||
* /\____/
|
||||
* \_/__/
|
||||
*
|
||||
* HID Joystick driver routines for MacOS X.
|
||||
*
|
||||
* By Angelo Mottola.
|
||||
*
|
||||
* See readme.txt for copyright information.
|
||||
*/
|
||||
|
||||
#include "allegro.h"
|
||||
#include "allegro/internal/aintern.h"
|
||||
#include "allegro/platform/aintosx.h"
|
||||
|
||||
#ifndef ALLEGRO_MACOSX
|
||||
#error something is wrong with the makefile
|
||||
#endif
|
||||
|
||||
|
||||
static int hid_joy_init(void);
|
||||
static void hid_joy_exit(void);
|
||||
static int hid_joy_poll(void);
|
||||
|
||||
|
||||
JOYSTICK_DRIVER joystick_hid = {
|
||||
JOYSTICK_HID, // int id;
|
||||
empty_string, // AL_CONST char *name;
|
||||
empty_string, // AL_CONST char *desc;
|
||||
"HID Joystick", // AL_CONST char *ascii_name;
|
||||
hid_joy_init, // AL_METHOD(int, init, (void));
|
||||
hid_joy_exit, // AL_METHOD(void, exit, (void));
|
||||
hid_joy_poll, // AL_METHOD(int, poll, (void));
|
||||
NULL, // AL_METHOD(int, save_data, (void));
|
||||
NULL, // AL_METHOD(int, load_data, (void));
|
||||
NULL, // AL_METHOD(AL_CONST char *, calibrate_name, (int n));
|
||||
NULL // AL_METHOD(int, calibrate, (int n));
|
||||
};
|
||||
|
||||
|
||||
static HID_DEVICE_COLLECTION hid_devices;
|
||||
|
||||
|
||||
|
||||
/* hid_joy_init:
|
||||
* Initializes the HID joystick driver.
|
||||
*/
|
||||
static int hid_joy_init(void)
|
||||
{
|
||||
static char *name_stick = "stick";
|
||||
static char *name_hat = "hat";
|
||||
static char *name_x = "x";
|
||||
static char *name_y = "y";
|
||||
static char *name_b[] =
|
||||
{ "B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8", "B9", "B10", "B11", "B12", "B13", "B14", "B15", "B16" };
|
||||
HID_ELEMENT *element;
|
||||
int i, j;
|
||||
hid_devices.count=hid_devices.capacity=0;
|
||||
hid_devices.devices=NULL;
|
||||
osx_hid_scan(HID_JOYSTICK, &hid_devices);
|
||||
osx_hid_scan(HID_GAMEPAD, &hid_devices);
|
||||
num_joysticks = hid_devices.count > 0 ? hid_devices.devices[hid_devices.count - 1].cur_app : 0;
|
||||
for (i = 0; i < num_joysticks; i++) {
|
||||
memset(&joy[i], 0, sizeof(joy[i]));
|
||||
}
|
||||
for (i=0; i<hid_devices.count; ++i) {
|
||||
for (j = 0; j < hid_devices.devices[i].num_elements; j++) {
|
||||
element = &hid_devices.devices[i].element[j];
|
||||
switch (element->type) {
|
||||
case HID_ELEMENT_BUTTON:
|
||||
if (element->index >= MAX_JOYSTICK_BUTTONS || element->app>=MAX_JOYSTICKS) {
|
||||
element->cookie=0x0;
|
||||
break;
|
||||
}
|
||||
if (element->name)
|
||||
joy[element->app].button[element->index].name = element->name;
|
||||
else
|
||||
joy[element->app].button[element->index].name = name_b[element->index];
|
||||
joy[element->app].num_buttons++;
|
||||
break;
|
||||
|
||||
case HID_ELEMENT_AXIS:
|
||||
case HID_ELEMENT_AXIS_PRIMARY_X:
|
||||
case HID_ELEMENT_AXIS_PRIMARY_Y:
|
||||
/* Changes here may need to be duplicated in case below. */
|
||||
if (element->app>=MAX_JOYSTICKS || element->col>=MAX_JOYSTICK_STICKS || element->index>=MAX_JOYSTICK_AXIS) {
|
||||
element->cookie=0x0;
|
||||
break;
|
||||
}
|
||||
joy[element->app].stick[element->col].name = name_stick;
|
||||
joy[element->app].stick[element->col].num_axis++;
|
||||
if (joy[element->app].num_sticks<(element->col+1))
|
||||
joy[element->app].num_sticks=element->col+1;
|
||||
joy[element->app].stick[element->col].flags = JOYFLAG_DIGITAL | JOYFLAG_ANALOGUE | JOYFLAG_SIGNED;
|
||||
if (element->name)
|
||||
joy[element->app].stick[element->col].axis[element->index].name = element->name;
|
||||
else
|
||||
joy[element->app].stick[element->col].axis[element->index].name = element->index==0 ? name_x : name_y;
|
||||
|
||||
break;
|
||||
|
||||
case HID_ELEMENT_STANDALONE_AXIS:
|
||||
/* Changes here may need to be duplicated in case directly above. */
|
||||
if (element->app>=MAX_JOYSTICKS || element->col>=MAX_JOYSTICK_STICKS || element->index>=MAX_JOYSTICK_AXIS) {
|
||||
element->cookie=0x0;
|
||||
break;
|
||||
}
|
||||
joy[element->app].stick[element->col].name = name_stick;
|
||||
joy[element->app].stick[element->col].num_axis++;
|
||||
if (joy[element->app].num_sticks<(element->col+1))
|
||||
joy[element->app].num_sticks=element->col+1;
|
||||
joy[element->app].stick[element->col].flags = JOYFLAG_ANALOGUE | JOYFLAG_UNSIGNED;
|
||||
if (element->name)
|
||||
joy[element->app].stick[element->col].axis[element->index].name = element->name;
|
||||
else
|
||||
joy[element->app].stick[element->col].axis[element->index].name = element->index==0 ? name_x : name_y;
|
||||
|
||||
break;
|
||||
|
||||
case HID_ELEMENT_HAT:
|
||||
if (element->app>=MAX_JOYSTICKS || element->col >= MAX_JOYSTICK_STICKS) {
|
||||
element->cookie=0x0;
|
||||
break;
|
||||
}
|
||||
if (joy[element->app].num_sticks<(element->col+1))
|
||||
joy[element->app].num_sticks=element->col+1;
|
||||
|
||||
if (element->name)
|
||||
joy[element->app].stick[element->col].name = element->name;
|
||||
else
|
||||
joy[element->app].stick[element->col].name = name_hat;
|
||||
joy[element->app].stick[element->col].num_axis = 2;
|
||||
joy[element->app].stick[element->col].flags = JOYFLAG_DIGITAL | JOYFLAG_ANALOGUE | JOYFLAG_SIGNED;
|
||||
joy[element->app].stick[element->col].axis[0].name = name_x;
|
||||
joy[element->app].stick[element->col].axis[1].name = name_y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return hid_joy_poll();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* hid_joy_exit:
|
||||
* Shuts down the HID joystick driver.
|
||||
*/
|
||||
static void hid_joy_exit(void)
|
||||
{
|
||||
osx_hid_free(&hid_devices);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* hid_joy_poll:
|
||||
* Polls the active joystick devices and updates internal states.
|
||||
*/
|
||||
static int hid_joy_poll(void)
|
||||
{
|
||||
HID_DEVICE *device;
|
||||
HID_ELEMENT *element;
|
||||
IOHIDEventStruct hid_event;
|
||||
int i, j, pos;
|
||||
|
||||
if (num_joysticks <= 0)
|
||||
return -1;
|
||||
|
||||
for (i = 0; i < hid_devices.count; i++) {
|
||||
device = &hid_devices.devices[i];
|
||||
if (device->interface) {
|
||||
for (j = 0; j < device->num_elements; j++) {
|
||||
element = &device->element[j];
|
||||
if ((element->cookie==0x0) || (*(device->interface))->getElementValue(device->interface, element->cookie, &hid_event))
|
||||
continue;
|
||||
switch (element->type) {
|
||||
|
||||
case HID_ELEMENT_BUTTON:
|
||||
joy[element->app].button[element->index].b = hid_event.value;
|
||||
break;
|
||||
|
||||
case HID_ELEMENT_AXIS:
|
||||
case HID_ELEMENT_AXIS_PRIMARY_X:
|
||||
case HID_ELEMENT_AXIS_PRIMARY_Y:
|
||||
pos = (((hid_event.value - element->min) * 256) / (element->max - element->min + 1)) - 128;
|
||||
joy[element->app].stick[element->col].axis[element->index].pos = pos;
|
||||
joy[element->app].stick[element->col].axis[element->index].d1 = FALSE;
|
||||
joy[element->app].stick[element->col].axis[element->index].d2 = FALSE;
|
||||
if (pos < 0)
|
||||
joy[element->app].stick[element->col].axis[element->index].d1 = TRUE;
|
||||
else if (pos > 0)
|
||||
joy[element->app].stick[element->col].axis[element->index].d2 = TRUE;
|
||||
break;
|
||||
|
||||
case HID_ELEMENT_STANDALONE_AXIS:
|
||||
pos = (((hid_event.value - element->min) * 255) / (element->max - element->min + 1));
|
||||
joy[element->app].stick[element->col].axis[element->index].pos = pos;
|
||||
break;
|
||||
|
||||
case HID_ELEMENT_HAT:
|
||||
switch (hid_event.value) {
|
||||
|
||||
case 0: /* up */
|
||||
joy[element->app].stick[element->col].axis[0].pos = 0;
|
||||
joy[element->app].stick[element->col].axis[0].d1 = 0;
|
||||
joy[element->app].stick[element->col].axis[0].d2 = 0;
|
||||
joy[element->app].stick[element->col].axis[1].pos = -128;
|
||||
joy[element->app].stick[element->col].axis[1].d1 = 1;
|
||||
joy[element->app].stick[element->col].axis[1].d2 = 0;
|
||||
break;
|
||||
|
||||
case 1: /* up and right */
|
||||
joy[element->app].stick[element->col].axis[0].pos = 128;
|
||||
joy[element->app].stick[element->col].axis[0].d1 = 0;
|
||||
joy[element->app].stick[element->col].axis[0].d2 = 1;
|
||||
joy[element->app].stick[element->col].axis[1].pos = -128;
|
||||
joy[element->app].stick[element->col].axis[1].d1 = 1;
|
||||
joy[element->app].stick[element->col].axis[1].d2 = 0;
|
||||
break;
|
||||
|
||||
case 2: /* right */
|
||||
joy[element->app].stick[element->col].axis[0].pos = 128;
|
||||
joy[element->app].stick[element->col].axis[0].d1 = 0;
|
||||
joy[element->app].stick[element->col].axis[0].d2 = 1;
|
||||
joy[element->app].stick[element->col].axis[1].pos = 0;
|
||||
joy[element->app].stick[element->col].axis[1].d1 = 0;
|
||||
joy[element->app].stick[element->col].axis[1].d2 = 0;
|
||||
break;
|
||||
|
||||
case 3: /* down and right */
|
||||
joy[element->app].stick[element->col].axis[0].pos = 128;
|
||||
joy[element->app].stick[element->col].axis[0].d1 = 0;
|
||||
joy[element->app].stick[element->col].axis[0].d2 = 1;
|
||||
joy[element->app].stick[element->col].axis[1].pos = 128;
|
||||
joy[element->app].stick[element->col].axis[1].d1 = 0;
|
||||
joy[element->app].stick[element->col].axis[1].d2 = 1;
|
||||
break;
|
||||
|
||||
case 4: /* down */
|
||||
joy[element->app].stick[element->col].axis[0].pos = 0;
|
||||
joy[element->app].stick[element->col].axis[0].d1 = 0;
|
||||
joy[element->app].stick[element->col].axis[0].d2 = 0;
|
||||
joy[element->app].stick[element->col].axis[1].pos = 128;
|
||||
joy[element->app].stick[element->col].axis[1].d1 = 0;
|
||||
joy[element->app].stick[element->col].axis[1].d2 = 1;
|
||||
break;
|
||||
|
||||
case 5: /* down and left */
|
||||
joy[element->app].stick[element->col].axis[0].pos = -128;
|
||||
joy[element->app].stick[element->col].axis[0].d1 = 1;
|
||||
joy[element->app].stick[element->col].axis[0].d2 = 0;
|
||||
joy[element->app].stick[element->col].axis[1].pos = 128;
|
||||
joy[element->app].stick[element->col].axis[1].d1 = 0;
|
||||
joy[element->app].stick[element->col].axis[1].d2 = 1;
|
||||
break;
|
||||
|
||||
case 6: /* left */
|
||||
joy[element->app].stick[element->col].axis[0].pos = -128;
|
||||
joy[element->app].stick[element->col].axis[0].d1 = 1;
|
||||
joy[element->app].stick[element->col].axis[0].d2 = 0;
|
||||
joy[element->app].stick[element->col].axis[1].pos = 0;
|
||||
joy[element->app].stick[element->col].axis[1].d1 = 0;
|
||||
joy[element->app].stick[element->col].axis[1].d2 = 0;
|
||||
break;
|
||||
|
||||
case 7: /* up and left */
|
||||
joy[element->app].stick[element->col].axis[0].pos = -128;
|
||||
joy[element->app].stick[element->col].axis[0].d1 = 1;
|
||||
joy[element->app].stick[element->col].axis[0].d2 = 0;
|
||||
joy[element->app].stick[element->col].axis[1].pos = -128;
|
||||
joy[element->app].stick[element->col].axis[1].d1 = 1;
|
||||
joy[element->app].stick[element->col].axis[1].d2 = 0;
|
||||
break;
|
||||
|
||||
case 15: /* centered */
|
||||
joy[element->app].stick[element->col].axis[0].pos = 0;
|
||||
joy[element->app].stick[element->col].axis[0].d1 = 0;
|
||||
joy[element->app].stick[element->col].axis[0].d2 = 0;
|
||||
joy[element->app].stick[element->col].axis[1].pos = 0;
|
||||
joy[element->app].stick[element->col].axis[1].d1 = 0;
|
||||
joy[element->app].stick[element->col].axis[1].d2 = 0;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/* Local variables: */
|
||||
/* c-basic-offset: 3 */
|
||||
/* indent-tabs-mode: nil */
|
||||
/* End: */
|
@ -125,7 +125,6 @@ SYSTEM_DRIVER system_macosx =
|
||||
NULL, /* AL_METHOD(_DRIVER_INFO *, midi_drivers, (void)); */
|
||||
NULL, /* AL_METHOD(_DRIVER_INFO *, keyboard_drivers, (void)); */
|
||||
NULL, /* AL_METHOD(_DRIVER_INFO *, mouse_drivers, (void)); */
|
||||
NULL, /* AL_METHOD(_DRIVER_INFO *, joystick_drivers, (void)); */
|
||||
NULL, /* AL_METHOD(_DRIVER_INFO *, timer_drivers, (void)); */
|
||||
};
|
||||
|
||||
|
@ -1,25 +0,0 @@
|
||||
/* ______ ___ ___
|
||||
* /\ _ \ /\_ \ /\_ \
|
||||
* \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
|
||||
* \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
|
||||
* \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
|
||||
* \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
|
||||
* \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
|
||||
* /\____/
|
||||
* \_/__/
|
||||
*
|
||||
* List of Unix joystick drivers.
|
||||
*
|
||||
* By Shawn Hargreaves.
|
||||
*
|
||||
* See readme.txt for copyright information.
|
||||
*/
|
||||
|
||||
|
||||
#include "allegro.h"
|
||||
|
||||
|
||||
|
||||
BEGIN_JOYSTICK_DRIVER_LIST
|
||||
/* todo */
|
||||
END_JOYSTICK_DRIVER_LIST
|
@ -115,7 +115,6 @@ void _win_switch_in(void)
|
||||
|
||||
key_dinput_acquire();
|
||||
mouse_dinput_acquire();
|
||||
joystick_dinput_acquire();
|
||||
|
||||
if (win_gfx_driver && win_gfx_driver->switch_in)
|
||||
win_gfx_driver->switch_in();
|
||||
@ -149,7 +148,6 @@ void _win_switch_out(void)
|
||||
|
||||
key_dinput_unacquire();
|
||||
mouse_dinput_unacquire();
|
||||
joystick_dinput_unacquire();
|
||||
|
||||
midi_switch_out();
|
||||
|
||||
|
@ -1,31 +0,0 @@
|
||||
/* ______ ___ ___
|
||||
* /\ _ \ /\_ \ /\_ \
|
||||
* \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
|
||||
* \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
|
||||
* \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
|
||||
* \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
|
||||
* \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
|
||||
* /\____/
|
||||
* \_/__/
|
||||
*
|
||||
* List of Windows joystick drivers, kept in a seperate file so that
|
||||
* they can be overriden by user programs.
|
||||
*
|
||||
* By Shawn Hargreaves.
|
||||
*
|
||||
* See readme.txt for copyright information.
|
||||
*/
|
||||
|
||||
|
||||
#include "allegro.h"
|
||||
|
||||
#ifndef ALLEGRO_WINDOWS
|
||||
#error something is wrong with the makefile
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
BEGIN_JOYSTICK_DRIVER_LIST
|
||||
JOYSTICK_DRIVER_DIRECTX
|
||||
JOYSTICK_DRIVER_WIN32
|
||||
END_JOYSTICK_DRIVER_LIST
|
@ -1,497 +0,0 @@
|
||||
/* ______ ___ ___
|
||||
* /\ _ \ /\_ \ /\_ \
|
||||
* \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
|
||||
* \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
|
||||
* \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
|
||||
* \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
|
||||
* \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
|
||||
* /\____/
|
||||
* \_/__/
|
||||
*
|
||||
* Windows DirectInput joystick driver.
|
||||
*
|
||||
* By Eric Botcazou.
|
||||
*
|
||||
* Omar Cornut fixed it to handle a weird peculiarity of
|
||||
* the DirectInput joystick API.
|
||||
*
|
||||
* See readme.txt for copyright information.
|
||||
*/
|
||||
|
||||
|
||||
#define DIRECTINPUT_VERSION 0x0500
|
||||
|
||||
#include "allegro.h"
|
||||
#include "allegro/internal/aintern.h"
|
||||
#include "allegro/platform/aintwin.h"
|
||||
|
||||
#ifndef SCAN_DEPEND
|
||||
#ifdef ALLEGRO_MINGW32
|
||||
#undef MAKEFOURCC
|
||||
#endif
|
||||
|
||||
#include <mmsystem.h>
|
||||
#include <dinput.h>
|
||||
#endif
|
||||
|
||||
#ifndef ALLEGRO_WINDOWS
|
||||
#error something is wrong with the makefile
|
||||
#endif
|
||||
|
||||
#define PREFIX_I "al-wjoy INFO: "
|
||||
#define PREFIX_W "al-wjoy WARNING: "
|
||||
#define PREFIX_E "al-wjoy ERROR: "
|
||||
|
||||
|
||||
static int joystick_dinput_init(void);
|
||||
static void joystick_dinput_exit(void);
|
||||
static int joystick_dinput_poll(void);
|
||||
|
||||
|
||||
JOYSTICK_DRIVER joystick_directx =
|
||||
{
|
||||
JOY_TYPE_DIRECTX,
|
||||
empty_string,
|
||||
empty_string,
|
||||
"DirectInput joystick",
|
||||
joystick_dinput_init,
|
||||
joystick_dinput_exit,
|
||||
joystick_dinput_poll,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
struct DINPUT_JOYSTICK_INFO {
|
||||
WINDOWS_JOYSTICK_INFO_MEMBERS
|
||||
LPDIRECTINPUTDEVICE2 device;
|
||||
};
|
||||
|
||||
static LPDIRECTINPUT joystick_dinput = NULL;
|
||||
static struct DINPUT_JOYSTICK_INFO dinput_joystick[MAX_JOYSTICKS];
|
||||
static int dinput_joy_num = 0;
|
||||
|
||||
|
||||
|
||||
/* dinput_err_str:
|
||||
* Returns a DirectInput error string.
|
||||
*/
|
||||
#ifdef DEBUGMODE
|
||||
static char* dinput_err_str(long err)
|
||||
{
|
||||
static char err_str[64];
|
||||
|
||||
switch (err) {
|
||||
|
||||
case DIERR_NOTACQUIRED:
|
||||
_al_sane_strncpy(err_str, "the device is not acquired", sizeof(err_str));
|
||||
break;
|
||||
|
||||
case DIERR_INPUTLOST:
|
||||
_al_sane_strncpy(err_str, "access to the device was not granted", sizeof(err_str));
|
||||
break;
|
||||
|
||||
case DIERR_INVALIDPARAM:
|
||||
_al_sane_strncpy(err_str, "the device does not have a selected data format", sizeof(err_str));
|
||||
break;
|
||||
|
||||
case DIERR_OTHERAPPHASPRIO:
|
||||
_al_sane_strncpy(err_str, "can't acquire the device in background", sizeof(err_str));
|
||||
break;
|
||||
|
||||
default:
|
||||
_al_sane_strncpy(err_str, "unknown error", sizeof(err_str));
|
||||
}
|
||||
|
||||
return err_str;
|
||||
}
|
||||
#else
|
||||
#define dinput_err_str(hr) "\0"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* joystick_dinput_acquire: [window thread]
|
||||
* Acquires the joystick devices.
|
||||
*/
|
||||
int joystick_dinput_acquire(void)
|
||||
{
|
||||
HRESULT hr;
|
||||
int i;
|
||||
|
||||
if (joystick_dinput) {
|
||||
for (i=0; i<dinput_joy_num; i++) {
|
||||
hr = IDirectInputDevice2_Acquire(dinput_joystick[i].device);
|
||||
|
||||
if (FAILED(hr))
|
||||
_TRACE(PREFIX_E "acquire joystick %d failed: %s\n", i, dinput_err_str(hr));
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* joystick_dinput_unacquire: [window thread]
|
||||
* Unacquires the joystick devices.
|
||||
*/
|
||||
int joystick_dinput_unacquire(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (joystick_dinput) {
|
||||
for (i=0; i<dinput_joy_num; i++) {
|
||||
IDirectInputDevice2_Unacquire(dinput_joystick[i].device);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* joystick_dinput_poll: [primary thread]
|
||||
* Polls the DirectInput joystick devices.
|
||||
*/
|
||||
static int joystick_dinput_poll(void)
|
||||
{
|
||||
int n_joy, n_axis, n_but;
|
||||
DIJOYSTATE js;
|
||||
HRESULT hr;
|
||||
|
||||
for (n_joy = 0; n_joy < dinput_joy_num; n_joy++) {
|
||||
/* poll the device */
|
||||
IDirectInputDevice2_Poll(dinput_joystick[n_joy].device);
|
||||
|
||||
hr = IDirectInputDevice2_GetDeviceState(dinput_joystick[n_joy].device, sizeof(DIJOYSTATE), &js);
|
||||
|
||||
if (hr == DI_OK) {
|
||||
/* axes */
|
||||
dinput_joystick[n_joy].axis[0] = js.lX;
|
||||
dinput_joystick[n_joy].axis[1] = js.lY;
|
||||
n_axis = 2;
|
||||
|
||||
if (dinput_joystick[n_joy].caps & JOYCAPS_HASZ) {
|
||||
dinput_joystick[n_joy].axis[n_axis] = js.lZ;
|
||||
n_axis++;
|
||||
}
|
||||
|
||||
if (dinput_joystick[n_joy].caps & JOYCAPS_HASR) {
|
||||
dinput_joystick[n_joy].axis[n_axis] = js.lRz;
|
||||
n_axis++;
|
||||
}
|
||||
|
||||
/* In versions of the DirectInput joystick API earlier than 8.00, slider
|
||||
* data is to be found in the Z axis data member, although the object was
|
||||
* reported as a slider during enumeration.
|
||||
*
|
||||
* Very few locations seem to describe this "feature". Here is one:
|
||||
* http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dx81_vb/directx_vb/Input/VB_Ref/Types/dijoystate2.asp
|
||||
*
|
||||
* The interesting part is the note at the bottom of the page:
|
||||
* " Note: Under Microsoft DirectX 7, sliders on some joysticks could be assigned
|
||||
* to the Z axis, with subsequent code retrieving data from that member.
|
||||
* Using DirectX 8, those same sliders will be assigned to the slider array.
|
||||
* This should be taken into account when porting applications to DirectX 8.
|
||||
* Make any necessary alterations to ensure that slider data is retrieved from
|
||||
* the slider array. "
|
||||
*/
|
||||
|
||||
/* For U axis (slider 0), get data from Z axis member if API < 0x0800
|
||||
* and if a real Z axis is not present. Otherwise get it from slider 0 member.
|
||||
*/
|
||||
if (dinput_joystick[n_joy].caps & JOYCAPS_HASU) {
|
||||
#if DIRECTINPUT_VERSION < 0x0800
|
||||
if (dinput_joystick[n_joy].caps & JOYCAPS_HASZ)
|
||||
dinput_joystick[n_joy].axis[n_axis] = js.rglSlider[0];
|
||||
else
|
||||
dinput_joystick[n_joy].axis[n_axis] = js.lZ;
|
||||
#else
|
||||
dinput_joystick[n_joy].axis[n_axis] = js.rglSlider[0];
|
||||
#endif
|
||||
n_axis++;
|
||||
}
|
||||
|
||||
/* For V axis (slider 1), get data from slider 0 member if API < 0x0800
|
||||
* and if a real Z axis is not present. Otherwise get it from slider 1 member.
|
||||
*/
|
||||
if (dinput_joystick[n_joy].caps & JOYCAPS_HASV) {
|
||||
#if DIRECTINPUT_VERSION < 0x0800
|
||||
if (dinput_joystick[n_joy].caps & JOYCAPS_HASZ)
|
||||
dinput_joystick[n_joy].axis[n_axis] = js.rglSlider[1];
|
||||
else
|
||||
dinput_joystick[n_joy].axis[n_axis] = js.rglSlider[0];
|
||||
#else
|
||||
dinput_joystick[n_joy].axis[n_axis] = js.rglSlider[1];
|
||||
#endif
|
||||
n_axis++;
|
||||
}
|
||||
|
||||
/* hat */
|
||||
if (dinput_joystick[n_joy].caps & JOYCAPS_HASPOV)
|
||||
dinput_joystick[n_joy].hat = js.rgdwPOV[0];
|
||||
|
||||
/* buttons */
|
||||
for (n_but = 0; n_but < dinput_joystick[n_joy].num_buttons; n_but++)
|
||||
dinput_joystick[n_joy].button[n_but] = ((js.rgbButtons[n_but] & 0x80) != 0);
|
||||
|
||||
win_update_joystick_status(n_joy, (WINDOWS_JOYSTICK_INFO *)&dinput_joystick[n_joy]);
|
||||
}
|
||||
else {
|
||||
if ((hr == DIERR_NOTACQUIRED) || (hr == DIERR_INPUTLOST)) {
|
||||
/* reacquire device */
|
||||
_TRACE(PREFIX_W "joystick device not acquired or lost\n");
|
||||
wnd_schedule_proc(joystick_dinput_acquire);
|
||||
}
|
||||
else {
|
||||
_TRACE(PREFIX_E "unexpected error while polling the joystick\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* object_enum_callback:
|
||||
* Helper function to find out how many objects we have on the device.
|
||||
*/
|
||||
static BOOL CALLBACK object_enum_callback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef)
|
||||
{
|
||||
struct DINPUT_JOYSTICK_INFO *joy = (struct DINPUT_JOYSTICK_INFO *)pvRef;
|
||||
char tmp[128];
|
||||
|
||||
if (memcmp(&lpddoi->guidType, &GUID_XAxis, sizeof(GUID)) == 0) {
|
||||
joy->axis_name[0] = _al_ustrdup(uconvert_ascii(lpddoi->tszName, tmp));
|
||||
joy->num_axes++;
|
||||
}
|
||||
else if (memcmp(&lpddoi->guidType, &GUID_YAxis, sizeof(GUID)) == 0) {
|
||||
joy->axis_name[1] = _al_ustrdup(uconvert_ascii(lpddoi->tszName, tmp));
|
||||
joy->num_axes++;
|
||||
}
|
||||
else if (memcmp(&lpddoi->guidType, &GUID_ZAxis, sizeof(GUID)) == 0) {
|
||||
joy->axis_name[2] = _al_ustrdup(uconvert_ascii(lpddoi->tszName, tmp));
|
||||
joy->caps |= JOYCAPS_HASZ;
|
||||
joy->num_axes++;
|
||||
}
|
||||
else if (memcmp(&lpddoi->guidType, &GUID_RzAxis, sizeof(GUID)) == 0) {
|
||||
joy->axis_name[joy->num_axes] = _al_ustrdup(uconvert_ascii(lpddoi->tszName, tmp));
|
||||
joy->caps |= JOYCAPS_HASR;
|
||||
joy->num_axes++;
|
||||
}
|
||||
else if (memcmp(&lpddoi->guidType, &GUID_Slider, sizeof(GUID)) == 0) {
|
||||
if (joy->caps & JOYCAPS_HASV) {
|
||||
/* we support at most 2 sliders */
|
||||
return DIENUM_CONTINUE;
|
||||
}
|
||||
else {
|
||||
if (joy->caps & JOYCAPS_HASU)
|
||||
joy->caps |= JOYCAPS_HASV;
|
||||
else
|
||||
joy->caps |= JOYCAPS_HASU;
|
||||
|
||||
joy->axis_name[joy->num_axes] = _al_ustrdup(uconvert_ascii(lpddoi->tszName, tmp));
|
||||
joy->num_axes++;
|
||||
}
|
||||
}
|
||||
else if (memcmp(&lpddoi->guidType, &GUID_POV, sizeof(GUID)) == 0) {
|
||||
if (joy->caps & JOYCAPS_HASPOV) {
|
||||
/* we support at most 1 point-of-view device */
|
||||
return DIENUM_CONTINUE;
|
||||
}
|
||||
else {
|
||||
joy->hat_name = _al_ustrdup(uconvert_ascii(lpddoi->tszName, tmp));
|
||||
joy->caps |= JOYCAPS_HASPOV;
|
||||
}
|
||||
}
|
||||
else if (memcmp(&lpddoi->guidType, &GUID_Button, sizeof(GUID)) == 0) {
|
||||
if (joy->num_buttons == MAX_JOYSTICK_BUTTONS-1) {
|
||||
return DIENUM_CONTINUE;
|
||||
}
|
||||
else {
|
||||
joy->button_name[joy->num_buttons] = _al_ustrdup(uconvert_ascii(lpddoi->tszName, tmp));
|
||||
joy->num_buttons++;
|
||||
}
|
||||
}
|
||||
|
||||
return DIENUM_CONTINUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* joystick_enum_callback:
|
||||
* Helper function to find out how many joysticks we have and set them up.
|
||||
*/
|
||||
static BOOL CALLBACK joystick_enum_callback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef)
|
||||
{
|
||||
LPDIRECTINPUTDEVICE _dinput_device1;
|
||||
LPDIRECTINPUTDEVICE2 dinput_device = NULL;
|
||||
HRESULT hr;
|
||||
LPVOID temp;
|
||||
HWND allegro_wnd = win_get_window();
|
||||
|
||||
DIPROPRANGE property_range =
|
||||
{
|
||||
/* the header */
|
||||
{
|
||||
sizeof(DIPROPRANGE), // diph.dwSize
|
||||
sizeof(DIPROPHEADER), // diph.dwHeaderSize
|
||||
0, // diph.dwObj
|
||||
DIPH_DEVICE, // diph.dwHow
|
||||
},
|
||||
|
||||
/* the data */
|
||||
0, // lMin
|
||||
256 // lMax
|
||||
};
|
||||
|
||||
DIPROPDWORD property_deadzone =
|
||||
{
|
||||
/* the header */
|
||||
{
|
||||
sizeof(DIPROPDWORD), // diph.dwSize
|
||||
sizeof(DIPROPHEADER), // diph.dwHeaderSize
|
||||
0, // diph.dwObj
|
||||
DIPH_DEVICE, // diph.dwHow
|
||||
},
|
||||
|
||||
/* the data */
|
||||
2000, // dwData
|
||||
};
|
||||
|
||||
if (dinput_joy_num == MAX_JOYSTICKS-1) {
|
||||
_TRACE(PREFIX_W "The system supports more than %d joysticks\n", MAX_JOYSTICKS);
|
||||
return DIENUM_STOP;
|
||||
}
|
||||
|
||||
/* create the DirectInput joystick device */
|
||||
hr = IDirectInput_CreateDevice(joystick_dinput, &lpddi->guidInstance, &_dinput_device1, NULL);
|
||||
if (FAILED(hr))
|
||||
goto Error;
|
||||
|
||||
/* query the DirectInputDevice2 interface needed for the poll() method */
|
||||
hr = IDirectInputDevice_QueryInterface(_dinput_device1, &IID_IDirectInputDevice2, &temp);
|
||||
IDirectInputDevice_Release(_dinput_device1);
|
||||
if (FAILED(hr))
|
||||
goto Error;
|
||||
|
||||
dinput_device = temp;
|
||||
|
||||
/* set cooperative level */
|
||||
hr = IDirectInputDevice2_SetCooperativeLevel(dinput_device, allegro_wnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
|
||||
if (FAILED(hr))
|
||||
goto Error;
|
||||
|
||||
/* enumerate objects available on the device */
|
||||
memset(&dinput_joystick[dinput_joy_num], 0, sizeof(struct DINPUT_JOYSTICK_INFO));
|
||||
hr = IDirectInputDevice2_EnumObjects(dinput_device, object_enum_callback, &dinput_joystick[dinput_joy_num],
|
||||
DIDFT_PSHBUTTON | DIDFT_AXIS | DIDFT_POV);
|
||||
if (FAILED(hr))
|
||||
goto Error;
|
||||
|
||||
/* set data format */
|
||||
hr = IDirectInputDevice2_SetDataFormat(dinput_device, &c_dfDIJoystick);
|
||||
if (FAILED(hr))
|
||||
goto Error;
|
||||
|
||||
/* set the range of axes */
|
||||
hr = IDirectInputDevice2_SetProperty(dinput_device, DIPROP_RANGE, &property_range.diph);
|
||||
if (FAILED(hr))
|
||||
goto Error;
|
||||
|
||||
/* set the dead zone of axes */
|
||||
hr = IDirectInputDevice2_SetProperty(dinput_device, DIPROP_DEADZONE, &property_deadzone.diph);
|
||||
if (FAILED(hr))
|
||||
goto Error;
|
||||
|
||||
/* register this joystick */
|
||||
dinput_joystick[dinput_joy_num].device = dinput_device;
|
||||
if (win_add_joystick((WINDOWS_JOYSTICK_INFO *)&dinput_joystick[dinput_joy_num]) != 0)
|
||||
return DIENUM_STOP;
|
||||
|
||||
dinput_joy_num++;
|
||||
|
||||
return DIENUM_CONTINUE;
|
||||
|
||||
Error:
|
||||
if (dinput_device)
|
||||
IDirectInputDevice2_Release(dinput_device);
|
||||
|
||||
return DIENUM_CONTINUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* joystick_dinput_init: [primary thread]
|
||||
* Initialises the DirectInput joystick devices.
|
||||
*/
|
||||
static int joystick_dinput_init(void)
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
/* the DirectInput joystick interface is not part of DirectX 3 */
|
||||
if (_dx_ver < 0x0500)
|
||||
return -1;
|
||||
|
||||
/* get the DirectInput interface */
|
||||
hr = CoCreateInstance(&CLSID_DirectInput, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectInput, &joystick_dinput);
|
||||
if (FAILED(hr))
|
||||
return -1;
|
||||
|
||||
hr = IDirectInput_Initialize(joystick_dinput, allegro_inst, DIRECTINPUT_VERSION);
|
||||
if (FAILED(hr)) {
|
||||
IDirectInput_Release(joystick_dinput);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* enumerate the joysticks attached to the system */
|
||||
hr = IDirectInput_EnumDevices(joystick_dinput, DIDEVTYPE_JOYSTICK, joystick_enum_callback, NULL, DIEDFL_ATTACHEDONLY);
|
||||
if (FAILED(hr)) {
|
||||
IDirectInput_Release(joystick_dinput);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* acquire the devices */
|
||||
wnd_call_proc(joystick_dinput_acquire);
|
||||
|
||||
return (dinput_joy_num == 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* joystick_dinput_exit: [primary thread]
|
||||
* Shuts down the DirectInput joystick devices.
|
||||
*/
|
||||
static void joystick_dinput_exit(void)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
/* unacquire the devices */
|
||||
wnd_call_proc(joystick_dinput_unacquire);
|
||||
|
||||
/* destroy the devices */
|
||||
for (i=0; i<dinput_joy_num; i++) {
|
||||
IDirectInputDevice2_Release(dinput_joystick[i].device);
|
||||
|
||||
for (j=0; j<dinput_joystick[i].num_axes; j++) {
|
||||
if (dinput_joystick[i].axis_name[j])
|
||||
_AL_FREE(dinput_joystick[i].axis_name[j]);
|
||||
}
|
||||
|
||||
if (dinput_joystick[i].caps & JOYCAPS_HASPOV)
|
||||
_AL_FREE(dinput_joystick[i].hat_name);
|
||||
|
||||
for (j=0; j<dinput_joystick[i].num_buttons; j++)
|
||||
_AL_FREE(dinput_joystick[i].button_name[j]);
|
||||
}
|
||||
|
||||
/* destroy the DirectInput interface */
|
||||
IDirectInput_Release(joystick_dinput);
|
||||
|
||||
win_remove_all_joysticks();
|
||||
dinput_joy_num = 0;
|
||||
}
|
@ -1,253 +0,0 @@
|
||||
/* ______ ___ ___
|
||||
* /\ _ \ /\_ \ /\_ \
|
||||
* \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
|
||||
* \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
|
||||
* \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
|
||||
* \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
|
||||
* \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
|
||||
* /\____/
|
||||
* \_/__/
|
||||
*
|
||||
* Windows joystick high-level helper functions.
|
||||
*
|
||||
* By Eric Botcazou.
|
||||
*
|
||||
* Based on code by Stefan Schimanski.
|
||||
*
|
||||
* See readme.txt for copyright information.
|
||||
*/
|
||||
|
||||
|
||||
#include "allegro.h"
|
||||
#include "allegro/internal/aintern.h"
|
||||
#include "allegro/platform/aintwin.h"
|
||||
|
||||
#ifndef SCAN_DEPEND
|
||||
#ifdef ALLEGRO_MINGW32
|
||||
#undef MAKEFOURCC
|
||||
#endif
|
||||
|
||||
#include <mmsystem.h>
|
||||
#endif
|
||||
|
||||
#ifndef ALLEGRO_WINDOWS
|
||||
#error something is wrong with the makefile
|
||||
#endif
|
||||
|
||||
|
||||
static char name_x[] = "X";
|
||||
static char name_y[] = "Y";
|
||||
static char name_stick[] = "stick";
|
||||
static char name_throttle[] = "throttle";
|
||||
static char name_rudder[] = "rudder";
|
||||
static char name_slider[] = "slider";
|
||||
static char name_hat[] = "hat";
|
||||
static char *name_b[MAX_JOYSTICK_BUTTONS] = {
|
||||
"B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8",
|
||||
"B9", "B10", "B11", "B12", "B13", "B14", "B15", "B16",
|
||||
"B17", "B18", "B19", "B20", "B21", "B22", "B23", "B24",
|
||||
"B25", "B26", "B27", "B28", "B29", "B30", "B31", "B32"
|
||||
};
|
||||
|
||||
#define JOY_POVFORWARD_WRAP 36000
|
||||
|
||||
|
||||
|
||||
/* win_update_joystick_status:
|
||||
* Updates the specified joystick info structure by translating
|
||||
* Windows joystick status into Allegro joystick status.
|
||||
*/
|
||||
int win_update_joystick_status(int n, WINDOWS_JOYSTICK_INFO *win_joy)
|
||||
{
|
||||
int n_stick, n_axis, n_but, max_stick, win_axis, p;
|
||||
|
||||
if (n >= num_joysticks)
|
||||
return -1;
|
||||
|
||||
/* sticks */
|
||||
n_stick = 0;
|
||||
win_axis = 0;
|
||||
|
||||
/* skip hat at this point, it will be handled later */
|
||||
if (win_joy->caps & JOYCAPS_HASPOV)
|
||||
max_stick = joy[n].num_sticks - 1;
|
||||
else
|
||||
max_stick = joy[n].num_sticks;
|
||||
|
||||
for (n_stick = 0; n_stick < max_stick; n_stick++) {
|
||||
for (n_axis = 0; n_axis < joy[n].stick[n_stick].num_axis; n_axis++) {
|
||||
p = win_joy->axis[win_axis];
|
||||
|
||||
/* set pos of analog stick */
|
||||
if (joy[n].stick[n_stick].flags & JOYFLAG_ANALOGUE) {
|
||||
if (joy[n].stick[n_stick].flags & JOYFLAG_SIGNED)
|
||||
joy[n].stick[n_stick].axis[n_axis].pos = p - 128;
|
||||
else
|
||||
joy[n].stick[n_stick].axis[n_axis].pos = p;
|
||||
}
|
||||
|
||||
/* set pos of digital stick */
|
||||
if (joy[n].stick[n_stick].flags & JOYFLAG_DIGITAL) {
|
||||
if (p < 64)
|
||||
joy[n].stick[n_stick].axis[n_axis].d1 = TRUE;
|
||||
else
|
||||
joy[n].stick[n_stick].axis[n_axis].d1 = FALSE;
|
||||
|
||||
if (p > 192)
|
||||
joy[n].stick[n_stick].axis[n_axis].d2 = TRUE;
|
||||
else
|
||||
joy[n].stick[n_stick].axis[n_axis].d2 = FALSE;
|
||||
}
|
||||
|
||||
win_axis++;
|
||||
}
|
||||
}
|
||||
|
||||
/* hat */
|
||||
if (win_joy->caps & JOYCAPS_HASPOV) {
|
||||
/* emulate analog joystick */
|
||||
joy[n].stick[n_stick].axis[0].pos = 0;
|
||||
joy[n].stick[n_stick].axis[1].pos = 0;
|
||||
|
||||
/* left */
|
||||
if ((win_joy->hat > JOY_POVBACKWARD) && (win_joy->hat < JOY_POVFORWARD_WRAP)) {
|
||||
joy[n].stick[n_stick].axis[0].d1 = TRUE;
|
||||
joy[n].stick[n_stick].axis[0].pos = -128;
|
||||
}
|
||||
else {
|
||||
joy[n].stick[n_stick].axis[0].d1 = FALSE;
|
||||
}
|
||||
|
||||
/* right */
|
||||
if ((win_joy->hat > JOY_POVFORWARD) && (win_joy->hat < JOY_POVBACKWARD)) {
|
||||
joy[n].stick[n_stick].axis[0].d2 = TRUE;
|
||||
joy[n].stick[n_stick].axis[0].pos = +128;
|
||||
}
|
||||
else {
|
||||
joy[n].stick[n_stick].axis[0].d2 = FALSE;
|
||||
}
|
||||
|
||||
/* forward */
|
||||
if (((win_joy->hat > JOY_POVLEFT) && (win_joy->hat <= JOY_POVFORWARD_WRAP)) ||
|
||||
((win_joy->hat >= JOY_POVFORWARD) && (win_joy->hat < JOY_POVRIGHT))) {
|
||||
joy[n].stick[n_stick].axis[1].d1 = TRUE;
|
||||
joy[n].stick[n_stick].axis[1].pos = -128;
|
||||
}
|
||||
else {
|
||||
joy[n].stick[n_stick].axis[1].d1 = FALSE;
|
||||
}
|
||||
|
||||
/* backward */
|
||||
if ((win_joy->hat > JOY_POVRIGHT) && (win_joy->hat < JOY_POVLEFT)) {
|
||||
joy[n].stick[n_stick].axis[1].d2 = TRUE;
|
||||
joy[n].stick[n_stick].axis[1].pos = +128;
|
||||
}
|
||||
else {
|
||||
joy[n].stick[n_stick].axis[1].d2 = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* buttons */
|
||||
for (n_but = 0; n_but < win_joy->num_buttons; n_but++)
|
||||
joy[n].button[n_but].b = win_joy->button[n_but];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* win_add_joystick:
|
||||
* Adds a new joystick (fills in a new joystick info structure).
|
||||
*/
|
||||
int win_add_joystick(WINDOWS_JOYSTICK_INFO *win_joy)
|
||||
{
|
||||
int n_stick, n_but, max_stick, win_axis;
|
||||
|
||||
if (num_joysticks == MAX_JOYSTICKS-1)
|
||||
return -1;
|
||||
|
||||
joy[num_joysticks].flags = JOYFLAG_ANALOGUE | JOYFLAG_DIGITAL;
|
||||
|
||||
/* how many sticks ? */
|
||||
n_stick = 0;
|
||||
|
||||
if (win_joy->num_axes > 0) {
|
||||
win_axis = 0;
|
||||
|
||||
/* main analogue stick */
|
||||
if (win_joy->num_axes > 1) {
|
||||
joy[num_joysticks].stick[n_stick].flags = JOYFLAG_DIGITAL | JOYFLAG_ANALOGUE | JOYFLAG_SIGNED;
|
||||
joy[num_joysticks].stick[n_stick].axis[0].name = (win_joy->axis_name[0] ? win_joy->axis_name[0] : name_x);
|
||||
joy[num_joysticks].stick[n_stick].axis[1].name = (win_joy->axis_name[1] ? win_joy->axis_name[1] : name_y);
|
||||
joy[num_joysticks].stick[n_stick].name = name_stick;
|
||||
|
||||
/* Z-axis: throttle */
|
||||
if (win_joy->caps & JOYCAPS_HASZ) {
|
||||
joy[num_joysticks].stick[n_stick].num_axis = 3;
|
||||
joy[num_joysticks].stick[n_stick].axis[2].name = (win_joy->axis_name[2] ? win_joy->axis_name[2] : name_throttle);
|
||||
win_axis += 3;
|
||||
}
|
||||
else {
|
||||
joy[num_joysticks].stick[n_stick].num_axis = 2;
|
||||
win_axis += 2;
|
||||
}
|
||||
|
||||
n_stick++;
|
||||
}
|
||||
|
||||
/* first 1-axis stick: rudder */
|
||||
if (win_joy->caps & JOYCAPS_HASR) {
|
||||
joy[num_joysticks].stick[n_stick].flags = JOYFLAG_DIGITAL | JOYFLAG_ANALOGUE | JOYFLAG_UNSIGNED;
|
||||
joy[num_joysticks].stick[n_stick].num_axis = 1;
|
||||
joy[num_joysticks].stick[n_stick].axis[0].name = "";
|
||||
joy[num_joysticks].stick[n_stick].name = (win_joy->axis_name[win_axis] ? win_joy->axis_name[win_axis] : name_rudder);
|
||||
win_axis++;
|
||||
n_stick++;
|
||||
}
|
||||
|
||||
max_stick = (win_joy->caps & JOYCAPS_HASPOV ? MAX_JOYSTICK_STICKS-1 : MAX_JOYSTICK_STICKS);
|
||||
|
||||
/* other 1-axis sticks: sliders */
|
||||
while ((win_axis < win_joy->num_axes) && (n_stick < max_stick)) {
|
||||
joy[num_joysticks].stick[n_stick].flags = JOYFLAG_DIGITAL | JOYFLAG_ANALOGUE | JOYFLAG_UNSIGNED;
|
||||
joy[num_joysticks].stick[n_stick].num_axis = 1;
|
||||
joy[num_joysticks].stick[n_stick].axis[0].name = "";
|
||||
joy[num_joysticks].stick[n_stick].name = (win_joy->axis_name[win_axis] ? win_joy->axis_name[win_axis] : name_slider);
|
||||
win_axis++;
|
||||
n_stick++;
|
||||
}
|
||||
|
||||
/* hat */
|
||||
if (win_joy->caps & JOYCAPS_HASPOV) {
|
||||
joy[num_joysticks].stick[n_stick].flags = JOYFLAG_DIGITAL | JOYFLAG_SIGNED;
|
||||
joy[num_joysticks].stick[n_stick].num_axis = 2;
|
||||
joy[num_joysticks].stick[n_stick].axis[0].name = "left/right";
|
||||
joy[num_joysticks].stick[n_stick].axis[1].name = "up/down";
|
||||
joy[num_joysticks].stick[n_stick].name = (win_joy->hat_name ? win_joy->hat_name : name_hat);
|
||||
n_stick++;
|
||||
}
|
||||
}
|
||||
|
||||
joy[num_joysticks].num_sticks = n_stick;
|
||||
|
||||
/* how many buttons ? */
|
||||
joy[num_joysticks].num_buttons = win_joy->num_buttons;
|
||||
|
||||
/* fill in the button names */
|
||||
for (n_but = 0; n_but < joy[num_joysticks].num_buttons; n_but++)
|
||||
joy[num_joysticks].button[n_but].name = (win_joy->button_name[n_but] ? win_joy->button_name[n_but] : name_b[n_but]);
|
||||
|
||||
num_joysticks++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* win_remove_all_joysticks:
|
||||
* Removes all registered joysticks.
|
||||
*/
|
||||
void win_remove_all_joysticks(void)
|
||||
{
|
||||
num_joysticks = 0;
|
||||
}
|
@ -1,242 +0,0 @@
|
||||
/* ______ ___ ___
|
||||
* /\ _ \ /\_ \ /\_ \
|
||||
* \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
|
||||
* \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
|
||||
* \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
|
||||
* \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
|
||||
* \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
|
||||
* /\____/
|
||||
* \_/__/
|
||||
*
|
||||
* Win32 joystick driver.
|
||||
*
|
||||
* By Stefan Schimanski.
|
||||
*
|
||||
* Bugfixes by Jose Antonio Luque.
|
||||
*
|
||||
* Bugfixes and enhanced POV support by Johan Peitz.
|
||||
*
|
||||
* See readme.txt for copyright information.
|
||||
*/
|
||||
|
||||
|
||||
#include "allegro.h"
|
||||
#include "allegro/internal/aintern.h"
|
||||
#include "allegro/platform/aintwin.h"
|
||||
|
||||
#ifndef SCAN_DEPEND
|
||||
#ifdef ALLEGRO_MINGW32
|
||||
#undef MAKEFOURCC
|
||||
#endif
|
||||
|
||||
#include <mmsystem.h>
|
||||
#endif
|
||||
|
||||
#ifndef ALLEGRO_WINDOWS
|
||||
#error something is wrong with the makefile
|
||||
#endif
|
||||
|
||||
#define PREFIX_I "al-wjoy INFO: "
|
||||
#define PREFIX_W "al-wjoy WARNING: "
|
||||
#define PREFIX_E "al-wjoy ERROR: "
|
||||
|
||||
|
||||
static int joystick_win32_init(void);
|
||||
static void joystick_win32_exit(void);
|
||||
static int joystick_win32_poll(void);
|
||||
|
||||
|
||||
JOYSTICK_DRIVER joystick_win32 =
|
||||
{
|
||||
JOY_TYPE_WIN32,
|
||||
empty_string,
|
||||
empty_string,
|
||||
"Win32 joystick",
|
||||
joystick_win32_init,
|
||||
joystick_win32_exit,
|
||||
joystick_win32_poll,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
struct WIN32_JOYSTICK_INFO {
|
||||
WINDOWS_JOYSTICK_INFO_MEMBERS
|
||||
int device;
|
||||
int axis_min[WINDOWS_MAX_AXES];
|
||||
int axis_max[WINDOWS_MAX_AXES];
|
||||
};
|
||||
|
||||
struct WIN32_JOYSTICK_INFO win32_joystick[MAX_JOYSTICKS];
|
||||
static int win32_joy_num = 0;
|
||||
|
||||
|
||||
|
||||
/* joystick_win32_poll:
|
||||
* Polls the Win32 joystick devices.
|
||||
*/
|
||||
static int joystick_win32_poll(void)
|
||||
{
|
||||
int n_joy, n_axis, n_but, p, range;
|
||||
JOYINFOEX js;
|
||||
|
||||
for (n_joy = 0; n_joy < win32_joy_num; n_joy++) {
|
||||
js.dwSize = sizeof(js);
|
||||
js.dwFlags = JOY_RETURNALL;
|
||||
|
||||
if (joyGetPosEx(win32_joystick[n_joy].device, &js) == JOYERR_NOERROR) {
|
||||
|
||||
/* axes */
|
||||
win32_joystick[n_joy].axis[0] = js.dwXpos;
|
||||
win32_joystick[n_joy].axis[1] = js.dwYpos;
|
||||
n_axis = 2;
|
||||
|
||||
if (win32_joystick[n_joy].caps & JOYCAPS_HASZ) {
|
||||
win32_joystick[n_joy].axis[n_axis] = js.dwZpos;
|
||||
n_axis++;
|
||||
}
|
||||
|
||||
if (win32_joystick[n_joy].caps & JOYCAPS_HASR) {
|
||||
win32_joystick[n_joy].axis[n_axis] = js.dwRpos;
|
||||
n_axis++;
|
||||
}
|
||||
|
||||
if (win32_joystick[n_joy].caps & JOYCAPS_HASU) {
|
||||
win32_joystick[n_joy].axis[n_axis] = js.dwUpos;
|
||||
n_axis++;
|
||||
}
|
||||
|
||||
if (win32_joystick[n_joy].caps & JOYCAPS_HASV) {
|
||||
win32_joystick[n_joy].axis[n_axis] = js.dwVpos;
|
||||
n_axis++;
|
||||
}
|
||||
|
||||
/* map Windows axis range to 0-256 Allegro range */
|
||||
for (n_axis = 0; n_axis < win32_joystick[n_joy].num_axes; n_axis++) {
|
||||
p = win32_joystick[n_joy].axis[n_axis] - win32_joystick[n_joy].axis_min[n_axis];
|
||||
range = win32_joystick[n_joy].axis_max[n_axis] - win32_joystick[n_joy].axis_min[n_axis];
|
||||
|
||||
if (range > 0)
|
||||
win32_joystick[n_joy].axis[n_axis] = p * 256 / range;
|
||||
else
|
||||
win32_joystick[n_joy].axis[n_axis] = 0;
|
||||
}
|
||||
|
||||
/* hat */
|
||||
if (win32_joystick[n_joy].caps & JOYCAPS_HASPOV)
|
||||
win32_joystick[n_joy].hat = js.dwPOV;
|
||||
|
||||
/* buttons */
|
||||
for (n_but = 0; n_but < win32_joystick[n_joy].num_buttons; n_but++)
|
||||
win32_joystick[n_joy].button[n_but] = ((js.dwButtons & (1 << n_but)) != 0);
|
||||
}
|
||||
else {
|
||||
for(n_axis = 0; n_axis<win32_joystick[n_joy].num_axes; n_axis++)
|
||||
win32_joystick[n_joy].axis[n_axis] = 0;
|
||||
|
||||
if (win32_joystick[n_joy].caps & JOYCAPS_HASPOV)
|
||||
win32_joystick[n_joy].hat = 0;
|
||||
|
||||
for (n_but = 0; n_but < win32_joystick[n_joy].num_buttons; n_but++)
|
||||
win32_joystick[n_joy].button[n_but] = FALSE;
|
||||
}
|
||||
|
||||
win_update_joystick_status(n_joy, (WINDOWS_JOYSTICK_INFO *)&win32_joystick[n_joy]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* joystick_win32_init:
|
||||
* Initialises the Win32 joystick driver.
|
||||
*/
|
||||
static int joystick_win32_init(void)
|
||||
{
|
||||
JOYCAPS caps;
|
||||
JOYINFOEX js;
|
||||
int n_joyat, n_joy, n_axis;
|
||||
|
||||
win32_joy_num = joyGetNumDevs();
|
||||
|
||||
if (win32_joy_num > MAX_JOYSTICKS)
|
||||
_TRACE(PREFIX_W "The system supports more than %d joysticks\n", MAX_JOYSTICKS);
|
||||
|
||||
/* retrieve joystick infos */
|
||||
n_joy = 0;
|
||||
for (n_joyat = 0; n_joyat < win32_joy_num; n_joyat++) {
|
||||
if (n_joy == MAX_JOYSTICKS)
|
||||
break;
|
||||
|
||||
if (joyGetDevCaps(n_joyat, &caps, sizeof(caps)) == JOYERR_NOERROR) {
|
||||
/* is the joystick physically attached? */
|
||||
js.dwSize = sizeof(js);
|
||||
js.dwFlags = JOY_RETURNALL;
|
||||
if (joyGetPosEx(n_joyat, &js) == JOYERR_UNPLUGGED)
|
||||
continue;
|
||||
|
||||
memset(&win32_joystick[n_joy], 0, sizeof(struct WIN32_JOYSTICK_INFO));
|
||||
|
||||
/* set global properties */
|
||||
win32_joystick[n_joy].device = n_joyat;
|
||||
win32_joystick[n_joy].caps = caps.wCaps;
|
||||
win32_joystick[n_joy].num_buttons = MIN(caps.wNumButtons, MAX_JOYSTICK_BUTTONS);
|
||||
win32_joystick[n_joy].num_axes = MIN(caps.wNumAxes, WINDOWS_MAX_AXES);
|
||||
|
||||
/* fill in ranges of axes */
|
||||
win32_joystick[n_joy].axis_min[0] = caps.wXmin;
|
||||
win32_joystick[n_joy].axis_max[0] = caps.wXmax;
|
||||
win32_joystick[n_joy].axis_min[1] = caps.wYmin;
|
||||
win32_joystick[n_joy].axis_max[1] = caps.wYmax;
|
||||
n_axis = 2;
|
||||
|
||||
if (caps.wCaps & JOYCAPS_HASZ) {
|
||||
win32_joystick[n_joy].axis_min[2] = caps.wZmin;
|
||||
win32_joystick[n_joy].axis_max[2] = caps.wZmax;
|
||||
n_axis++;
|
||||
}
|
||||
|
||||
if (caps.wCaps & JOYCAPS_HASR) {
|
||||
win32_joystick[n_joy].axis_min[n_axis] = caps.wRmin;
|
||||
win32_joystick[n_joy].axis_max[n_axis] = caps.wRmax;
|
||||
n_axis++;
|
||||
}
|
||||
|
||||
if (caps.wCaps & JOYCAPS_HASU) {
|
||||
win32_joystick[n_joy].axis_min[n_axis] = caps.wUmin;
|
||||
win32_joystick[n_joy].axis_max[n_axis] = caps.wUmax;
|
||||
n_axis++;
|
||||
}
|
||||
|
||||
if (caps.wCaps & JOYCAPS_HASV) {
|
||||
win32_joystick[n_joy].axis_min[n_axis] = caps.wVmin;
|
||||
win32_joystick[n_joy].axis_max[n_axis] = caps.wVmax;
|
||||
n_axis++;
|
||||
}
|
||||
|
||||
/* register this joystick */
|
||||
if (win_add_joystick((WINDOWS_JOYSTICK_INFO *)&win32_joystick[n_joy]) != 0)
|
||||
break;
|
||||
|
||||
n_joy++;
|
||||
}
|
||||
}
|
||||
|
||||
win32_joy_num = n_joy;
|
||||
|
||||
return (win32_joy_num == 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* joystick_win32_exit:
|
||||
* Shuts down the Win32 joystick driver.
|
||||
*/
|
||||
static void joystick_win32_exit(void)
|
||||
{
|
||||
win_remove_all_joysticks();
|
||||
win32_joy_num = 0;
|
||||
}
|
@ -95,7 +95,6 @@ SYSTEM_DRIVER system_directx =
|
||||
_get_win_midi_driver_list, /* AL_METHOD(_DRIVER_INFO *, midi_drivers, (void)); */
|
||||
NULL, /* AL_METHOD(_DRIVER_INFO *, keyboard_drivers, (void)); */
|
||||
NULL, /* AL_METHOD(_DRIVER_INFO *, mouse_drivers, (void)); */
|
||||
NULL, /* AL_METHOD(_DRIVER_INFO *, joystick_drivers, (void)); */
|
||||
NULL /* AL_METHOD(_DRIVER_INFO *, timer_drivers, (void)); */
|
||||
};
|
||||
|
||||
@ -359,7 +358,6 @@ static void sys_directx_restore_console_state(void)
|
||||
/* unacquire input devices */
|
||||
wnd_schedule_proc(key_dinput_unacquire);
|
||||
wnd_schedule_proc(mouse_dinput_unacquire);
|
||||
wnd_schedule_proc(joystick_dinput_unacquire);
|
||||
|
||||
/* reset switch mode */
|
||||
_win_reset_switch_mode();
|
||||
|
@ -76,8 +76,6 @@ static UINT msg_suicide = 0;
|
||||
struct WINDOW_MODULES {
|
||||
int keyboard;
|
||||
int mouse;
|
||||
int joystick;
|
||||
int joy_type;
|
||||
int sound;
|
||||
int digi_card;
|
||||
int midi_card;
|
||||
@ -109,9 +107,6 @@ static int init_window_modules(struct WINDOW_MODULES *wm)
|
||||
if (wm->mouse)
|
||||
install_mouse();
|
||||
|
||||
if (wm->joystick)
|
||||
install_joystick(wm->joy_type);
|
||||
|
||||
if (wm->sound)
|
||||
install_sound(wm->digi_card, wm->midi_card, NULL);
|
||||
|
||||
@ -127,7 +122,6 @@ static int init_window_modules(struct WINDOW_MODULES *wm)
|
||||
* Removes the modules that depend upon the main window:
|
||||
* - keyboard (DirectInput),
|
||||
* - mouse (DirectInput),
|
||||
* - joystick (DirectInput),
|
||||
* - sound (DirectSound),
|
||||
* - sound input (DirectSoundCapture).
|
||||
* If WM is not NULL, record which modules are really removed.
|
||||
@ -151,15 +145,6 @@ static void exit_window_modules(struct WINDOW_MODULES *wm)
|
||||
remove_mouse();
|
||||
}
|
||||
|
||||
if (_joystick_installed) {
|
||||
if (wm) {
|
||||
wm->joystick = TRUE;
|
||||
wm->joy_type = _joy_type;
|
||||
}
|
||||
|
||||
remove_joystick();
|
||||
}
|
||||
|
||||
if (_sound_installed) {
|
||||
if (wm) {
|
||||
wm->sound = TRUE;
|
||||
@ -784,5 +769,4 @@ void win_grab_input(void)
|
||||
{
|
||||
wnd_schedule_proc(key_dinput_acquire);
|
||||
wnd_schedule_proc(mouse_dinput_grab);
|
||||
wnd_schedule_proc(joystick_dinput_acquire);
|
||||
}
|
||||
|
@ -49,9 +49,6 @@ static _DRIVER_INFO *_xwin_sysdrv_digi_drivers(void);
|
||||
static _DRIVER_INFO *_xwin_sysdrv_midi_drivers(void);
|
||||
static _DRIVER_INFO *_xwin_sysdrv_keyboard_drivers(void);
|
||||
static _DRIVER_INFO *_xwin_sysdrv_mouse_drivers(void);
|
||||
#ifdef ALLEGRO_HAVE_LINUX_JOYSTICK_H
|
||||
static _DRIVER_INFO *_xwin_sysdrv_joystick_drivers(void);
|
||||
#endif
|
||||
static _DRIVER_INFO *_xwin_sysdrv_timer_drivers(void);
|
||||
|
||||
|
||||
@ -102,11 +99,6 @@ SYSTEM_DRIVER system_xwin =
|
||||
_xwin_sysdrv_midi_drivers,
|
||||
_xwin_sysdrv_keyboard_drivers,
|
||||
_xwin_sysdrv_mouse_drivers,
|
||||
#ifdef ALLEGRO_HAVE_LINUX_JOYSTICK_H
|
||||
_xwin_sysdrv_joystick_drivers,
|
||||
#else
|
||||
NULL, /* joystick_driver_list */
|
||||
#endif
|
||||
_xwin_sysdrv_timer_drivers
|
||||
};
|
||||
|
||||
@ -391,18 +383,6 @@ static _DRIVER_INFO *_xwin_sysdrv_mouse_drivers(void)
|
||||
|
||||
|
||||
|
||||
#ifdef ALLEGRO_HAVE_LINUX_JOYSTICK_H
|
||||
/* _xwin_sysdrv_joystick_drivers:
|
||||
* Get the list of joystick drivers.
|
||||
*/
|
||||
static _DRIVER_INFO *_xwin_sysdrv_joystick_drivers(void)
|
||||
{
|
||||
return _linux_joystick_driver_list;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* _xwin_sysdrv_timer_drivers:
|
||||
* Get the list of timer drivers.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user