/***************************************************************
                           joystick.h
 ***************************************************************/

module allegro.joystick;

import allegro.internal._export;
import allegro.internal.dversion;


enum {
   JOY_TYPE_AUTODETECT    = -1,
   JOY_TYPE_NONE          = 0,
}

enum {
   MAX_JOYSTICKS          = 8,
   MAX_JOYSTICK_AXIS      = 3,
   MAX_JOYSTICK_STICKS    = 5,
   MAX_JOYSTICK_BUTTONS   = 32,
}


/* information about a single joystick axis */
struct JOYSTICK_AXIS_INFO
{
   int pos;
   int d1, d2;
   const char *name;
}


/* information about one or more axis (a slider or directional control) */
struct JOYSTICK_STICK_INFO
{
   int flags;
   int num_axis;
   JOYSTICK_AXIS_INFO axis[MAX_JOYSTICK_AXIS];
   const char *name;
}


/* information about a joystick button */
struct JOYSTICK_BUTTON_INFO
{
   int b;
   const char *name;
}


/* information about an entire joystick */
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 status flags */
enum {
   JOYFLAG_DIGITAL           = 1,
   JOYFLAG_ANALOGUE          = 2,
   JOYFLAG_CALIB_DIGITAL     = 4,
   JOYFLAG_CALIB_ANALOGUE    = 8,
   JOYFLAG_CALIBRATE         = 16,
   JOYFLAG_SIGNED            = 32,
   JOYFLAG_UNSIGNED          = 64,
}


/* alternative spellings */
alias JOYFLAG_ANALOGUE        JOYFLAG_ANALOG;
alias JOYFLAG_CALIB_ANALOGUE  JOYFLAG_CALIB_ANALOG;


/* global joystick information */
mixin(_export!(`
   extern extern (C) {
      JOYSTICK_INFO joy[MAX_JOYSTICKS];
      int num_joysticks;
   }
`));

extern (C)
struct JOYSTICK_DRIVER         /* driver for reading joystick input */
{
   int  id;
   const char *name;
   const char *desc;
   const char *ascii_name;
   int init();
   void exit();
   int poll();
   int save_data();
   int load_data();
   stringz calibrate_name(int n);
   int calibrate(int n);
}

mixin(_export!(`
   extern extern (C) {
      //JOYSTICK_DRIVER joystick_none;
      JOYSTICK_DRIVER* joystick_driver;
      //_DRIVER_INFO _joystick_driver_list[];
   }
`));


extern (C) {

int install_joystick (int type);
void remove_joystick ();

int poll_joystick ();

int save_joystick_data (in char *filename);
int load_joystick_data (in char *filename);

stringz calibrate_joystick_name (int n);
int calibrate_joystick (int n);

}  // extern (C)
