#ifndef JOYSTICK_H
#define JOYSTICK_H

#include "osdepend.h"

struct OSDJoystick
{
    int         (*init)(options_type *osd_options);
    void        (*exit)(void);
    const struct JoystickInfo *(*get_joy_list)(void);
    int         (*is_joy_pressed)(int joycode);
    void        (*poll_joysticks)(void);
    void        (*analogjoy_read)(int player, int *analog_x, int *analog_y);
    int         (*standard_analog_read)(int player, int axis);
    void        (*get_device_numbers)(int *joyid);
    void        (*set_device_numbers)(int *joyid);
    const char* (*get_device_name)(int number);

    BOOL        (*Available)(void);
    BOOL        (*OnMessage)(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT* pResult);
};

extern struct OSDJoystick Joystick;
extern struct OSDJoystick DJoystick;

#define JOYCODE(joy, stick, axis_or_button, dir) \
        ((((dir)            & 0x03) << 14) |     \
         (((axis_or_button) & 0x3f) <<  8) |     \
         (((stick)          & 0x1f) <<  3) |     \
         (((joy)            & 0x07) <<  0))

#define GET_JOYCODE_JOY(code)    (((code) >> 0) & 0x07)
#define GET_JOYCODE_STICK(code)  (((code) >> 3) & 0x1f)
#define GET_JOYCODE_AXIS(code)   (((code) >> 8) & 0x3f)
#define GET_JOYCODE_BUTTON(code) GET_JOYCODE_AXIS(code)
#define GET_JOYCODE_DIR(code)    (((code) >>14) & 0x03)

#define JOYCODE_STICK_BTN        0
#define JOYCODE_STICK_AXIS       1
#define JOYCODE_STICK_POV        2

#define JOYCODE_DIR_BTN          0
#define JOYCODE_DIR_NEG          1
#define JOYCODE_DIR_POS          2

#define MOUSE_BUTTON(button)     JOYCODE(1, JOYCODE_STICK_BTN, button, 3)

#endif
