1// Added to ignore compiler warning when it comes to 3rd party.
    2#pragma GCC diagnostic ignored "-Wpedantic"
    3#pragma GCC diagnostic ignored "-Wundef"
    4#pragma GCC diagnostic ignored "-Wunused"
    5#pragma GCC diagnostic ignored "-Wunused-variable"
    6#pragma GCC diagnostic ignored "-Wunused-parameter"
    7#pragma GCC diagnostic ignored "-Wsign-compare"
    8
    9/*
   10  Simple DirectMedia Layer
   11  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
   12
   13  This software is provided 'as-is', without any express or implied
   14  warranty.  In no event will the authors be held liable for any damages
   15  arising from the use of this software.
   16
   17  Permission is granted to anyone to use this software for any purpose,
   18  including commercial applications, and to alter it and redistribute it
   19  freely, subject to the following restrictions:
   20
   21  1. The origin of this software must not be misrepresented; you must not
   22     claim that you wrote the original software. If you use this software
   23     in a product, an acknowledgment in the product documentation would be
   24     appreciated but is not required.
   25  2. Altered source versions must be plainly marked as such, and must not be
   26     misrepresented as being the original software.
   27  3. This notice may not be removed or altered from any source distribution.
   28*/
   29
   30// (Partial copyright from inline included files dsound.h, dinput.h)
   31/****************************************************************************
   32 *
   33 *  Copyright (C) 1996-2000 Microsoft Corporation.  All Rights Reserved.
   34 *
   35 ****************************************************************************/
   36
   37#if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
   38#define _CRT_SECURE_NO_WARNINGS
   39#define _CRT_NONSTDC_NO_WARNINGS
   40#endif
   41
   42#include "minisdl_audio.h"
   43#ifndef _SDL_H
   44#define _SDL_H
   45
   46#ifndef _SDL_main_h
   47#define _SDL_main_h
   48
   49#ifndef SDL_MAIN_HANDLED
   50#if defined(__WIN32__)
   51
   52#define SDL_MAIN_AVAILABLE
   53
   54#elif defined(__WINRT__)
   55
   56#define SDL_MAIN_NEEDED
   57
   58#elif defined(__IPHONEOS__)
   59
   60#define SDL_MAIN_NEEDED
   61
   62#elif defined(__ANDROID__)
   63
   64#define SDL_MAIN_NEEDED
   65
   66#endif
   67#endif
   68
   69#ifdef __cplusplus
   70#define C_LINKAGE   "C"
   71#else
   72#define C_LINKAGE
   73#endif
   74
   75#if defined(SDL_MAIN_NEEDED) || defined(SDL_MAIN_AVAILABLE)
   76#define main    SDL_main
   77#endif
   78
   79extern C_LINKAGE int SDL_main(int argc, char *argv[]);
   80
   81#ifdef _begin_code_h
   82#error Nested inclusion of begin_code.h
   83#endif
   84#define _begin_code_h
   85
   86#ifndef SDL_DEPRECATED
   87#  if (__GNUC__ >= 4)
   88#    define SDL_DEPRECATED __attribute__((deprecated))
   89#  else
   90#    define SDL_DEPRECATED
   91#  endif
   92#endif
   93
   94#ifndef DECLSPEC
   95# if defined(__WIN32__) || defined(__WINRT__)
   96#  ifdef __BORLANDC__
   97#   ifdef BUILD_SDL
   98#    define DECLSPEC
   99#   else
  100#    define DECLSPEC    __declspec(dllimport)
  101#   endif
  102#  else
  103#   define DECLSPEC __declspec(dllexport)
  104#  endif
  105# else
  106#  if defined(__GNUC__) && __GNUC__ >= 4
  107#   define DECLSPEC __attribute__ ((visibility("default")))
  108#  elif defined(__GNUC__) && __GNUC__ >= 2
  109#   define DECLSPEC __declspec(dllexport)
  110#  else
  111#   define DECLSPEC
  112#  endif
  113# endif
  114#endif
  115
  116#ifndef SDLCALL
  117#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
  118#define SDLCALL __cdecl
  119#else
  120#define SDLCALL
  121#endif
  122#endif
  123
  124#ifdef __SYMBIAN32__
  125#undef DECLSPEC
  126#define DECLSPEC
  127#endif
  128
  129#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
  130#ifdef _MSC_VER
  131#pragma warning(disable: 4103)
  132#endif
  133#ifdef __BORLANDC__
  134#pragma nopackwarning
  135#endif
  136#ifdef _M_X64
  137
  138#pragma pack(push,8)
  139#else
  140#pragma pack(push,4)
  141#endif
  142#endif
  143
  144#ifndef SDL_INLINE
  145#if defined(__GNUC__)
  146#define SDL_INLINE __inline__
  147#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
  148      defined(__DMC__) || defined(__SC__) || \
  149      defined(__WATCOMC__) || defined(__LCC__) || \
  150      defined(__DECC)
  151#define SDL_INLINE __inline
  152#ifndef __inline__
  153#define __inline__ __inline
  154#endif
  155#else
  156#define SDL_INLINE inline
  157#ifndef __inline__
  158#define __inline__ inline
  159#endif
  160#endif
  161#endif
  162
  163#ifndef SDL_FORCE_INLINE
  164#if defined(_MSC_VER)
  165#define SDL_FORCE_INLINE __forceinline
  166#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
  167#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
  168#else
  169#define SDL_FORCE_INLINE static SDL_INLINE
  170#endif
  171#endif
  172
  173#if !defined(__MACH__)
  174#ifndef NULL
  175#ifdef __cplusplus
  176#define NULL 0
  177#else
  178#define NULL ((void *)0)
  179#endif
  180#endif
  181#endif
  182#ifdef __cplusplus
  183extern "C" {
  184#endif
  185
  186extern DECLSPEC void SDLCALL SDL_SetMainReady(void);
  187
  188#ifdef __WIN32__
  189
  190extern DECLSPEC int SDLCALL SDL_RegisterApp(char *name, Uint32 style,
  191                                            void *hInst);
  192extern DECLSPEC void SDLCALL SDL_UnregisterApp(void);
  193
  194#endif
  195
  196#ifdef __WINRT__
  197
  198extern DECLSPEC int SDLCALL SDL_WinRTRunApp(int (*mainFunction)(int, char **), void * xamlBackgroundPanel);
  199
  200#endif
  201
  202#ifdef __cplusplus
  203}
  204#endif
  205#undef _begin_code_h
  206
  207#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__WATCOMC__)  || defined(__BORLANDC__)
  208#ifdef __BORLANDC__
  209#pragma nopackwarning
  210#endif
  211#pragma pack(pop)
  212#endif
  213
  214#endif
  215#ifndef _SDL_assert_h
  216#define _SDL_assert_h
  217
  218#ifdef _begin_code_h
  219#error Nested inclusion of begin_code.h
  220#endif
  221#define _begin_code_h
  222
  223#ifndef SDL_DEPRECATED
  224#  if (__GNUC__ >= 4)
  225#    define SDL_DEPRECATED __attribute__((deprecated))
  226#  else
  227#    define SDL_DEPRECATED
  228#  endif
  229#endif
  230
  231#ifndef DECLSPEC
  232# if defined(__WIN32__) || defined(__WINRT__)
  233#  ifdef __BORLANDC__
  234#   ifdef BUILD_SDL
  235#    define DECLSPEC
  236#   else
  237#    define DECLSPEC    __declspec(dllimport)
  238#   endif
  239#  else
  240#   define DECLSPEC __declspec(dllexport)
  241#  endif
  242# else
  243#  if defined(__GNUC__) && __GNUC__ >= 4
  244#   define DECLSPEC __attribute__ ((visibility("default")))
  245#  elif defined(__GNUC__) && __GNUC__ >= 2
  246#   define DECLSPEC __declspec(dllexport)
  247#  else
  248#   define DECLSPEC
  249#  endif
  250# endif
  251#endif
  252
  253#ifndef SDLCALL
  254#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
  255#define SDLCALL __cdecl
  256#else
  257#define SDLCALL
  258#endif
  259#endif
  260
  261#ifdef __SYMBIAN32__
  262#undef DECLSPEC
  263#define DECLSPEC
  264#endif
  265
  266#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
  267#ifdef _MSC_VER
  268#pragma warning(disable: 4103)
  269#endif
  270#ifdef __BORLANDC__
  271#pragma nopackwarning
  272#endif
  273#ifdef _M_X64
  274
  275#pragma pack(push,8)
  276#else
  277#pragma pack(push,4)
  278#endif
  279#endif
  280
  281#ifndef SDL_INLINE
  282#if defined(__GNUC__)
  283#define SDL_INLINE __inline__
  284#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
  285      defined(__DMC__) || defined(__SC__) || \
  286      defined(__WATCOMC__) || defined(__LCC__) || \
  287      defined(__DECC)
  288#define SDL_INLINE __inline
  289#ifndef __inline__
  290#define __inline__ __inline
  291#endif
  292#else
  293#define SDL_INLINE inline
  294#ifndef __inline__
  295#define __inline__ inline
  296#endif
  297#endif
  298#endif
  299
  300#ifndef SDL_FORCE_INLINE
  301#if defined(_MSC_VER)
  302#define SDL_FORCE_INLINE __forceinline
  303#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
  304#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
  305#else
  306#define SDL_FORCE_INLINE static SDL_INLINE
  307#endif
  308#endif
  309
  310#if !defined(__MACH__)
  311#ifndef NULL
  312#ifdef __cplusplus
  313#define NULL 0
  314#else
  315#define NULL ((void *)0)
  316#endif
  317#endif
  318#endif
  319
  320#ifdef __cplusplus
  321extern "C" {
  322#endif
  323
  324#ifndef SDL_ASSERT_LEVEL
  325#ifdef SDL_DEFAULT_ASSERT_LEVEL
  326#define SDL_ASSERT_LEVEL SDL_DEFAULT_ASSERT_LEVEL
  327#elif defined(_DEBUG) || defined(DEBUG) || \
  328      (defined(__GNUC__) && !defined(__OPTIMIZE__))
  329#define SDL_ASSERT_LEVEL 2
  330#else
  331#define SDL_ASSERT_LEVEL 1
  332#endif
  333#endif
  334
  335#if defined(_MSC_VER)
  336
  337    extern void __cdecl __debugbreak(void);
  338    #define SDL_TriggerBreakpoint() __debugbreak()
  339#elif (defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)))
  340    #define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "int $3\n\t" )
  341#elif defined(HAVE_SIGNAL_H)
  342    #include <signal.h>
  343    #define SDL_TriggerBreakpoint() raise(SIGTRAP)
  344#else
  345
  346    #define SDL_TriggerBreakpoint()
  347#endif
  348
  349#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
  350#   define SDL_FUNCTION __func__
  351#elif ((__GNUC__ >= 2) || defined(_MSC_VER))
  352#   define SDL_FUNCTION __FUNCTION__
  353#else
  354#   define SDL_FUNCTION "???"
  355#endif
  356#define SDL_FILE    __FILE__
  357#define SDL_LINE    __LINE__
  358
  359#ifdef _MSC_VER
  360#define SDL_NULL_WHILE_LOOP_CONDITION (-1 == __LINE__)
  361#else
  362#define SDL_NULL_WHILE_LOOP_CONDITION (0)
  363#endif
  364
  365#define SDL_disabled_assert(condition) \
  366    do { (void) sizeof ((condition)); } while (SDL_NULL_WHILE_LOOP_CONDITION)
  367
  368typedef enum
  369{
  370    SDL_ASSERTION_RETRY,
  371    SDL_ASSERTION_BREAK,
  372    SDL_ASSERTION_ABORT,
  373    SDL_ASSERTION_IGNORE,
  374    SDL_ASSERTION_ALWAYS_IGNORE
  375} SDL_assert_state;
  376
  377typedef struct SDL_assert_data
  378{
  379    int always_ignore;
  380    unsigned int trigger_count;
  381    const char *condition;
  382    const char *filename;
  383    int linenum;
  384    const char *function;
  385    const struct SDL_assert_data *next;
  386} SDL_assert_data;
  387
  388#if (SDL_ASSERT_LEVEL > 0)
  389
  390extern DECLSPEC SDL_assert_state SDLCALL SDL_ReportAssertion(SDL_assert_data *,
  391                                                             const char *,
  392                                                             const char *, int)
  393#if defined(__clang__)
  394#if __has_feature(attribute_analyzer_noreturn)
  395
  396   __attribute__((analyzer_noreturn))
  397#endif
  398#endif
  399;
  400
  401#define SDL_enabled_assert(condition) \
  402    do { \
  403        while ( !(condition) ) { \
  404            static struct SDL_assert_data assert_data = { \
  405                0, 0, #condition, 0, 0, 0, 0 \
  406            }; \
  407            const SDL_assert_state state = SDL_ReportAssertion(&assert_data, \
  408                                                               SDL_FUNCTION, \
  409                                                               SDL_FILE, \
  410                                                               SDL_LINE); \
  411            if (state == SDL_ASSERTION_RETRY) { \
  412                continue; \
  413            } else if (state == SDL_ASSERTION_BREAK) { \
  414                SDL_TriggerBreakpoint(); \
  415            } \
  416            break; \
  417        } \
  418    } while (SDL_NULL_WHILE_LOOP_CONDITION)
  419
  420#endif
  421
  422#if SDL_ASSERT_LEVEL == 0
  423#   define SDL_assert(condition) SDL_disabled_assert(condition)
  424#   define SDL_assert_release(condition) SDL_disabled_assert(condition)
  425#   define SDL_assert_paranoid(condition) SDL_disabled_assert(condition)
  426#elif SDL_ASSERT_LEVEL == 1
  427#   define SDL_assert(condition) SDL_disabled_assert(condition)
  428#   define SDL_assert_release(condition) SDL_enabled_assert(condition)
  429#   define SDL_assert_paranoid(condition) SDL_disabled_assert(condition)
  430#elif SDL_ASSERT_LEVEL == 2
  431#   define SDL_assert(condition) SDL_enabled_assert(condition)
  432#   define SDL_assert_release(condition) SDL_enabled_assert(condition)
  433#   define SDL_assert_paranoid(condition) SDL_disabled_assert(condition)
  434#elif SDL_ASSERT_LEVEL == 3
  435#   define SDL_assert(condition) SDL_enabled_assert(condition)
  436#   define SDL_assert_release(condition) SDL_enabled_assert(condition)
  437#   define SDL_assert_paranoid(condition) SDL_enabled_assert(condition)
  438#else
  439#   error Unknown assertion level.
  440#endif
  441
  442#define SDL_assert_always(condition) SDL_enabled_assert(condition)
  443
  444typedef SDL_assert_state (SDLCALL *SDL_AssertionHandler)(
  445                                 const SDL_assert_data* data, void* userdata);
  446
  447extern DECLSPEC void SDLCALL SDL_SetAssertionHandler(
  448                                            SDL_AssertionHandler handler,
  449                                            void *userdata);
  450
  451extern DECLSPEC SDL_AssertionHandler SDLCALL SDL_GetDefaultAssertionHandler(void);
  452
  453extern DECLSPEC SDL_AssertionHandler SDLCALL SDL_GetAssertionHandler(void **puserdata);
  454
  455extern DECLSPEC const SDL_assert_data * SDLCALL SDL_GetAssertionReport(void);
  456
  457extern DECLSPEC void SDLCALL SDL_ResetAssertionReport(void);
  458
  459#ifdef __cplusplus
  460}
  461#endif
  462#undef _begin_code_h
  463
  464#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__WATCOMC__)  || defined(__BORLANDC__)
  465#ifdef __BORLANDC__
  466#pragma nopackwarning
  467#endif
  468#pragma pack(pop)
  469#endif
  470
  471#endif
  472#ifndef _SDL_clipboard_h
  473#define _SDL_clipboard_h
  474
  475#ifdef _begin_code_h
  476#error Nested inclusion of begin_code.h
  477#endif
  478#define _begin_code_h
  479
  480#ifndef SDL_DEPRECATED
  481#  if (__GNUC__ >= 4)
  482#    define SDL_DEPRECATED __attribute__((deprecated))
  483#  else
  484#    define SDL_DEPRECATED
  485#  endif
  486#endif
  487
  488#ifndef DECLSPEC
  489# if defined(__WIN32__) || defined(__WINRT__)
  490#  ifdef __BORLANDC__
  491#   ifdef BUILD_SDL
  492#    define DECLSPEC
  493#   else
  494#    define DECLSPEC    __declspec(dllimport)
  495#   endif
  496#  else
  497#   define DECLSPEC __declspec(dllexport)
  498#  endif
  499# else
  500#  if defined(__GNUC__) && __GNUC__ >= 4
  501#   define DECLSPEC __attribute__ ((visibility("default")))
  502#  elif defined(__GNUC__) && __GNUC__ >= 2
  503#   define DECLSPEC __declspec(dllexport)
  504#  else
  505#   define DECLSPEC
  506#  endif
  507# endif
  508#endif
  509
  510#ifndef SDLCALL
  511#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
  512#define SDLCALL __cdecl
  513#else
  514#define SDLCALL
  515#endif
  516#endif
  517
  518#ifdef __SYMBIAN32__
  519#undef DECLSPEC
  520#define DECLSPEC
  521#endif
  522
  523#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
  524#ifdef _MSC_VER
  525#pragma warning(disable: 4103)
  526#endif
  527#ifdef __BORLANDC__
  528#pragma nopackwarning
  529#endif
  530#ifdef _M_X64
  531
  532#pragma pack(push,8)
  533#else
  534#pragma pack(push,4)
  535#endif
  536#endif
  537
  538#ifndef SDL_INLINE
  539#if defined(__GNUC__)
  540#define SDL_INLINE __inline__
  541#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
  542      defined(__DMC__) || defined(__SC__) || \
  543      defined(__WATCOMC__) || defined(__LCC__) || \
  544      defined(__DECC)
  545#define SDL_INLINE __inline
  546#ifndef __inline__
  547#define __inline__ __inline
  548#endif
  549#else
  550#define SDL_INLINE inline
  551#ifndef __inline__
  552#define __inline__ inline
  553#endif
  554#endif
  555#endif
  556
  557#ifndef SDL_FORCE_INLINE
  558#if defined(_MSC_VER)
  559#define SDL_FORCE_INLINE __forceinline
  560#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
  561#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
  562#else
  563#define SDL_FORCE_INLINE static SDL_INLINE
  564#endif
  565#endif
  566
  567#if !defined(__MACH__)
  568#ifndef NULL
  569#ifdef __cplusplus
  570#define NULL 0
  571#else
  572#define NULL ((void *)0)
  573#endif
  574#endif
  575#endif
  576
  577#ifdef __cplusplus
  578extern "C" {
  579#endif
  580
  581extern DECLSPEC int SDLCALL SDL_SetClipboardText(const char *text);
  582
  583extern DECLSPEC char * SDLCALL SDL_GetClipboardText(void);
  584
  585extern DECLSPEC SDL_bool SDLCALL SDL_HasClipboardText(void);
  586
  587#ifdef __cplusplus
  588}
  589#endif
  590#undef _begin_code_h
  591
  592#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__WATCOMC__)  || defined(__BORLANDC__)
  593#ifdef __BORLANDC__
  594#pragma nopackwarning
  595#endif
  596#pragma pack(pop)
  597#endif
  598
  599#endif
  600#ifndef _SDL_cpuinfo_h
  601#define _SDL_cpuinfo_h
  602
  603#if defined(_MSC_VER) && (_MSC_VER >= 1500) && (defined(_M_IX86) || defined(_M_X64))
  604#include <intrin.h>
  605#ifndef _WIN64
  606#define __MMX__
  607#define __3dNOW__
  608#endif
  609#define __SSE__
  610#define __SSE2__
  611#elif defined(__MINGW64_VERSION_MAJOR)
  612#include <intrin.h>
  613#else
  614#ifdef __ALTIVEC__
  615#if HAVE_ALTIVEC_H && !defined(__APPLE_ALTIVEC__)
  616#include <altivec.h>
  617#undef pixel
  618#endif
  619#endif
  620#ifdef __MMX__
  621#include <mmintrin.h>
  622#endif
  623#ifdef __3dNOW__
  624#include <mm3dnow.h>
  625#endif
  626#ifdef __SSE__
  627#include <xmmintrin.h>
  628#endif
  629#ifdef __SSE2__
  630#include <emmintrin.h>
  631#endif
  632#endif
  633
  634#ifdef _begin_code_h
  635#error Nested inclusion of begin_code.h
  636#endif
  637#define _begin_code_h
  638
  639#ifndef SDL_DEPRECATED
  640#  if (__GNUC__ >= 4)
  641#    define SDL_DEPRECATED __attribute__((deprecated))
  642#  else
  643#    define SDL_DEPRECATED
  644#  endif
  645#endif
  646
  647#ifndef DECLSPEC
  648# if defined(__WIN32__) || defined(__WINRT__)
  649#  ifdef __BORLANDC__
  650#   ifdef BUILD_SDL
  651#    define DECLSPEC
  652#   else
  653#    define DECLSPEC    __declspec(dllimport)
  654#   endif
  655#  else
  656#   define DECLSPEC __declspec(dllexport)
  657#  endif
  658# else
  659#  if defined(__GNUC__) && __GNUC__ >= 4
  660#   define DECLSPEC __attribute__ ((visibility("default")))
  661#  elif defined(__GNUC__) && __GNUC__ >= 2
  662#   define DECLSPEC __declspec(dllexport)
  663#  else
  664#   define DECLSPEC
  665#  endif
  666# endif
  667#endif
  668
  669#ifndef SDLCALL
  670#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
  671#define SDLCALL __cdecl
  672#else
  673#define SDLCALL
  674#endif
  675#endif
  676
  677#ifdef __SYMBIAN32__
  678#undef DECLSPEC
  679#define DECLSPEC
  680#endif
  681
  682#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
  683#ifdef _MSC_VER
  684#pragma warning(disable: 4103)
  685#endif
  686#ifdef __BORLANDC__
  687#pragma nopackwarning
  688#endif
  689#ifdef _M_X64
  690
  691#pragma pack(push,8)
  692#else
  693#pragma pack(push,4)
  694#endif
  695#endif
  696
  697#ifndef SDL_INLINE
  698#if defined(__GNUC__)
  699#define SDL_INLINE __inline__
  700#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
  701      defined(__DMC__) || defined(__SC__) || \
  702      defined(__WATCOMC__) || defined(__LCC__) || \
  703      defined(__DECC)
  704#define SDL_INLINE __inline
  705#ifndef __inline__
  706#define __inline__ __inline
  707#endif
  708#else
  709#define SDL_INLINE inline
  710#ifndef __inline__
  711#define __inline__ inline
  712#endif
  713#endif
  714#endif
  715
  716#ifndef SDL_FORCE_INLINE
  717#if defined(_MSC_VER)
  718#define SDL_FORCE_INLINE __forceinline
  719#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
  720#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
  721#else
  722#define SDL_FORCE_INLINE static SDL_INLINE
  723#endif
  724#endif
  725
  726#if !defined(__MACH__)
  727#ifndef NULL
  728#ifdef __cplusplus
  729#define NULL 0
  730#else
  731#define NULL ((void *)0)
  732#endif
  733#endif
  734#endif
  735
  736#ifdef __cplusplus
  737extern "C" {
  738#endif
  739
  740#define SDL_CACHELINE_SIZE  128
  741
  742extern DECLSPEC int SDLCALL SDL_GetCPUCount(void);
  743
  744extern DECLSPEC int SDLCALL SDL_GetCPUCacheLineSize(void);
  745
  746extern DECLSPEC SDL_bool SDLCALL SDL_HasRDTSC(void);
  747
  748extern DECLSPEC SDL_bool SDLCALL SDL_HasAltiVec(void);
  749
  750extern DECLSPEC SDL_bool SDLCALL SDL_HasMMX(void);
  751
  752extern DECLSPEC SDL_bool SDLCALL SDL_Has3DNow(void);
  753
  754extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE(void);
  755
  756extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE2(void);
  757
  758extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE3(void);
  759
  760extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE41(void);
  761
  762extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE42(void);
  763
  764extern DECLSPEC SDL_bool SDLCALL SDL_HasAVX(void);
  765
  766extern DECLSPEC int SDLCALL SDL_GetSystemRAM(void);
  767
  768#ifdef __cplusplus
  769}
  770#endif
  771#undef _begin_code_h
  772
  773#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__WATCOMC__)  || defined(__BORLANDC__)
  774#ifdef __BORLANDC__
  775#pragma nopackwarning
  776#endif
  777#pragma pack(pop)
  778#endif
  779
  780#endif
  781#ifndef _SDL_events_h
  782#define _SDL_events_h
  783
  784#ifndef _SDL_video_h
  785#define _SDL_video_h
  786
  787#ifndef _SDL_pixels_h
  788#define _SDL_pixels_h
  789
  790#ifdef _begin_code_h
  791#error Nested inclusion of begin_code.h
  792#endif
  793#define _begin_code_h
  794
  795#ifndef SDL_DEPRECATED
  796#  if (__GNUC__ >= 4)
  797#    define SDL_DEPRECATED __attribute__((deprecated))
  798#  else
  799#    define SDL_DEPRECATED
  800#  endif
  801#endif
  802
  803#ifndef DECLSPEC
  804# if defined(__WIN32__) || defined(__WINRT__)
  805#  ifdef __BORLANDC__
  806#   ifdef BUILD_SDL
  807#    define DECLSPEC
  808#   else
  809#    define DECLSPEC    __declspec(dllimport)
  810#   endif
  811#  else
  812#   define DECLSPEC __declspec(dllexport)
  813#  endif
  814# else
  815#  if defined(__GNUC__) && __GNUC__ >= 4
  816#   define DECLSPEC __attribute__ ((visibility("default")))
  817#  elif defined(__GNUC__) && __GNUC__ >= 2
  818#   define DECLSPEC __declspec(dllexport)
  819#  else
  820#   define DECLSPEC
  821#  endif
  822# endif
  823#endif
  824
  825#ifndef SDLCALL
  826#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
  827#define SDLCALL __cdecl
  828#else
  829#define SDLCALL
  830#endif
  831#endif
  832
  833#ifdef __SYMBIAN32__
  834#undef DECLSPEC
  835#define DECLSPEC
  836#endif
  837
  838#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
  839#ifdef _MSC_VER
  840#pragma warning(disable: 4103)
  841#endif
  842#ifdef __BORLANDC__
  843#pragma nopackwarning
  844#endif
  845#ifdef _M_X64
  846
  847#pragma pack(push,8)
  848#else
  849#pragma pack(push,4)
  850#endif
  851#endif
  852
  853#ifndef SDL_INLINE
  854#if defined(__GNUC__)
  855#define SDL_INLINE __inline__
  856#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
  857      defined(__DMC__) || defined(__SC__) || \
  858      defined(__WATCOMC__) || defined(__LCC__) || \
  859      defined(__DECC)
  860#define SDL_INLINE __inline
  861#ifndef __inline__
  862#define __inline__ __inline
  863#endif
  864#else
  865#define SDL_INLINE inline
  866#ifndef __inline__
  867#define __inline__ inline
  868#endif
  869#endif
  870#endif
  871
  872#ifndef SDL_FORCE_INLINE
  873#if defined(_MSC_VER)
  874#define SDL_FORCE_INLINE __forceinline
  875#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
  876#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
  877#else
  878#define SDL_FORCE_INLINE static SDL_INLINE
  879#endif
  880#endif
  881
  882#if !defined(__MACH__)
  883#ifndef NULL
  884#ifdef __cplusplus
  885#define NULL 0
  886#else
  887#define NULL ((void *)0)
  888#endif
  889#endif
  890#endif
  891
  892#ifdef __cplusplus
  893extern "C" {
  894#endif
  895
  896#define SDL_ALPHA_OPAQUE 255
  897#define SDL_ALPHA_TRANSPARENT 0
  898
  899enum
  900{
  901    SDL_PIXELTYPE_UNKNOWN,
  902    SDL_PIXELTYPE_INDEX1,
  903    SDL_PIXELTYPE_INDEX4,
  904    SDL_PIXELTYPE_INDEX8,
  905    SDL_PIXELTYPE_PACKED8,
  906    SDL_PIXELTYPE_PACKED16,
  907    SDL_PIXELTYPE_PACKED32,
  908    SDL_PIXELTYPE_ARRAYU8,
  909    SDL_PIXELTYPE_ARRAYU16,
  910    SDL_PIXELTYPE_ARRAYU32,
  911    SDL_PIXELTYPE_ARRAYF16,
  912    SDL_PIXELTYPE_ARRAYF32
  913};
  914
  915enum
  916{
  917    SDL_BITMAPORDER_NONE,
  918    SDL_BITMAPORDER_4321,
  919    SDL_BITMAPORDER_1234
  920};
  921
  922enum
  923{
  924    SDL_PACKEDORDER_NONE,
  925    SDL_PACKEDORDER_XRGB,
  926    SDL_PACKEDORDER_RGBX,
  927    SDL_PACKEDORDER_ARGB,
  928    SDL_PACKEDORDER_RGBA,
  929    SDL_PACKEDORDER_XBGR,
  930    SDL_PACKEDORDER_BGRX,
  931    SDL_PACKEDORDER_ABGR,
  932    SDL_PACKEDORDER_BGRA
  933};
  934
  935enum
  936{
  937    SDL_ARRAYORDER_NONE,
  938    SDL_ARRAYORDER_RGB,
  939    SDL_ARRAYORDER_RGBA,
  940    SDL_ARRAYORDER_ARGB,
  941    SDL_ARRAYORDER_BGR,
  942    SDL_ARRAYORDER_BGRA,
  943    SDL_ARRAYORDER_ABGR
  944};
  945
  946enum
  947{
  948    SDL_PACKEDLAYOUT_NONE,
  949    SDL_PACKEDLAYOUT_332,
  950    SDL_PACKEDLAYOUT_4444,
  951    SDL_PACKEDLAYOUT_1555,
  952    SDL_PACKEDLAYOUT_5551,
  953    SDL_PACKEDLAYOUT_565,
  954    SDL_PACKEDLAYOUT_8888,
  955    SDL_PACKEDLAYOUT_2101010,
  956    SDL_PACKEDLAYOUT_1010102
  957};
  958
  959#define SDL_DEFINE_PIXELFOURCC(A, B, C, D) SDL_FOURCC(A, B, C, D)
  960
  961#define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes) \
  962    ((1 << 28) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | \
  963     ((bits) << 8) | ((bytes) << 0))
  964
  965#define SDL_PIXELFLAG(X)    (((X) >> 28) & 0x0F)
  966#define SDL_PIXELTYPE(X)    (((X) >> 24) & 0x0F)
  967#define SDL_PIXELORDER(X)   (((X) >> 20) & 0x0F)
  968#define SDL_PIXELLAYOUT(X)  (((X) >> 16) & 0x0F)
  969#define SDL_BITSPERPIXEL(X) (((X) >> 8) & 0xFF)
  970#define SDL_BYTESPERPIXEL(X) \
  971    (SDL_ISPIXELFORMAT_FOURCC(X) ? \
  972        ((((X) == SDL_PIXELFORMAT_YUY2) || \
  973          ((X) == SDL_PIXELFORMAT_UYVY) || \
  974          ((X) == SDL_PIXELFORMAT_YVYU)) ? 2 : 1) : (((X) >> 0) & 0xFF))
  975
  976#define SDL_ISPIXELFORMAT_INDEXED(format)   \
  977    (!SDL_ISPIXELFORMAT_FOURCC(format) && \
  978     ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX1) || \
  979      (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX4) || \
  980      (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX8)))
  981
  982#define SDL_ISPIXELFORMAT_ALPHA(format)   \
  983    (!SDL_ISPIXELFORMAT_FOURCC(format) && \
  984     ((SDL_PIXELORDER(format) == SDL_PACKEDORDER_ARGB) || \
  985      (SDL_PIXELORDER(format) == SDL_PACKEDORDER_RGBA) || \
  986      (SDL_PIXELORDER(format) == SDL_PACKEDORDER_ABGR) || \
  987      (SDL_PIXELORDER(format) == SDL_PACKEDORDER_BGRA)))
  988
  989#define SDL_ISPIXELFORMAT_FOURCC(format)    \
  990    ((format) && (SDL_PIXELFLAG(format) != 1))
  991
  992enum
  993{
  994    SDL_PIXELFORMAT_UNKNOWN,
  995    SDL_PIXELFORMAT_INDEX1LSB =
  996        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1, SDL_BITMAPORDER_4321, 0,
  997                               1, 0),
  998    SDL_PIXELFORMAT_INDEX1MSB =
  999        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1, SDL_BITMAPORDER_1234, 0,
 1000                               1, 0),
 1001    SDL_PIXELFORMAT_INDEX4LSB =
 1002        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4, SDL_BITMAPORDER_4321, 0,
 1003                               4, 0),
 1004    SDL_PIXELFORMAT_INDEX4MSB =
 1005        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4, SDL_BITMAPORDER_1234, 0,
 1006                               4, 0),
 1007    SDL_PIXELFORMAT_INDEX8 =
 1008        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX8, 0, 0, 8, 1),
 1009    SDL_PIXELFORMAT_RGB332 =
 1010        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED8, SDL_PACKEDORDER_XRGB,
 1011                               SDL_PACKEDLAYOUT_332, 8, 1),
 1012    SDL_PIXELFORMAT_RGB444 =
 1013        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
 1014                               SDL_PACKEDLAYOUT_4444, 12, 2),
 1015    SDL_PIXELFORMAT_RGB555 =
 1016        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
 1017                               SDL_PACKEDLAYOUT_1555, 15, 2),
 1018    SDL_PIXELFORMAT_BGR555 =
 1019        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR,
 1020                               SDL_PACKEDLAYOUT_1555, 15, 2),
 1021    SDL_PIXELFORMAT_ARGB4444 =
 1022        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB,
 1023                               SDL_PACKEDLAYOUT_4444, 16, 2),
 1024    SDL_PIXELFORMAT_RGBA4444 =
 1025        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_RGBA,
 1026                               SDL_PACKEDLAYOUT_4444, 16, 2),
 1027    SDL_PIXELFORMAT_ABGR4444 =
 1028        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ABGR,
 1029                               SDL_PACKEDLAYOUT_4444, 16, 2),
 1030    SDL_PIXELFORMAT_BGRA4444 =
 1031        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_BGRA,
 1032                               SDL_PACKEDLAYOUT_4444, 16, 2),
 1033    SDL_PIXELFORMAT_ARGB1555 =
 1034        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB,
 1035                               SDL_PACKEDLAYOUT_1555, 16, 2),
 1036    SDL_PIXELFORMAT_RGBA5551 =
 1037        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_RGBA,
 1038                               SDL_PACKEDLAYOUT_5551, 16, 2),
 1039    SDL_PIXELFORMAT_ABGR1555 =
 1040        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ABGR,
 1041                               SDL_PACKEDLAYOUT_1555, 16, 2),
 1042    SDL_PIXELFORMAT_BGRA5551 =
 1043        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_BGRA,
 1044                               SDL_PACKEDLAYOUT_5551, 16, 2),
 1045    SDL_PIXELFORMAT_RGB565 =
 1046        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
 1047                               SDL_PACKEDLAYOUT_565, 16, 2),
 1048    SDL_PIXELFORMAT_BGR565 =
 1049        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR,
 1050                               SDL_PACKEDLAYOUT_565, 16, 2),
 1051    SDL_PIXELFORMAT_RGB24 =
 1052        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU8, SDL_ARRAYORDER_RGB, 0,
 1053                               24, 3),
 1054    SDL_PIXELFORMAT_BGR24 =
 1055        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU8, SDL_ARRAYORDER_BGR, 0,
 1056                               24, 3),
 1057    SDL_PIXELFORMAT_RGB888 =
 1058        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XRGB,
 1059                               SDL_PACKEDLAYOUT_8888, 24, 4),
 1060    SDL_PIXELFORMAT_RGBX8888 =
 1061        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_RGBX,
 1062                               SDL_PACKEDLAYOUT_8888, 24, 4),
 1063    SDL_PIXELFORMAT_BGR888 =
 1064        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XBGR,
 1065                               SDL_PACKEDLAYOUT_8888, 24, 4),
 1066    SDL_PIXELFORMAT_BGRX8888 =
 1067        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_BGRX,
 1068                               SDL_PACKEDLAYOUT_8888, 24, 4),
 1069    SDL_PIXELFORMAT_ARGB8888 =
 1070        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ARGB,
 1071                               SDL_PACKEDLAYOUT_8888, 32, 4),
 1072    SDL_PIXELFORMAT_RGBA8888 =
 1073        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_RGBA,
 1074                               SDL_PACKEDLAYOUT_8888, 32, 4),
 1075    SDL_PIXELFORMAT_ABGR8888 =
 1076        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ABGR,
 1077                               SDL_PACKEDLAYOUT_8888, 32, 4),
 1078    SDL_PIXELFORMAT_BGRA8888 =
 1079        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_BGRA,
 1080                               SDL_PACKEDLAYOUT_8888, 32, 4),
 1081    SDL_PIXELFORMAT_ARGB2101010 =
 1082        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ARGB,
 1083                               SDL_PACKEDLAYOUT_2101010, 32, 4),
 1084
 1085    SDL_PIXELFORMAT_YV12 =
 1086        SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2'),
 1087    SDL_PIXELFORMAT_IYUV =
 1088        SDL_DEFINE_PIXELFOURCC('I', 'Y', 'U', 'V'),
 1089    SDL_PIXELFORMAT_YUY2 =
 1090        SDL_DEFINE_PIXELFOURCC('Y', 'U', 'Y', '2'),
 1091    SDL_PIXELFORMAT_UYVY =
 1092        SDL_DEFINE_PIXELFOURCC('U', 'Y', 'V', 'Y'),
 1093    SDL_PIXELFORMAT_YVYU =
 1094        SDL_DEFINE_PIXELFOURCC('Y', 'V', 'Y', 'U')
 1095};
 1096
 1097typedef struct SDL_Color
 1098{
 1099    Uint8 r;
 1100    Uint8 g;
 1101    Uint8 b;
 1102    Uint8 a;
 1103} SDL_Color;
 1104#define SDL_Colour SDL_Color
 1105
 1106typedef struct SDL_Palette
 1107{
 1108    int ncolors;
 1109    SDL_Color *colors;
 1110    Uint32 version;
 1111    int refcount;
 1112} SDL_Palette;
 1113
 1114typedef struct SDL_PixelFormat
 1115{
 1116    Uint32 format;
 1117    SDL_Palette *palette;
 1118    Uint8 BitsPerPixel;
 1119    Uint8 BytesPerPixel;
 1120    Uint8 padding[2];
 1121    Uint32 Rmask;
 1122    Uint32 Gmask;
 1123    Uint32 Bmask;
 1124    Uint32 Amask;
 1125    Uint8 Rloss;
 1126    Uint8 Gloss;
 1127    Uint8 Bloss;
 1128    Uint8 Aloss;
 1129    Uint8 Rshift;
 1130    Uint8 Gshift;
 1131    Uint8 Bshift;
 1132    Uint8 Ashift;
 1133    int refcount;
 1134    struct SDL_PixelFormat *next;
 1135} SDL_PixelFormat;
 1136
 1137extern DECLSPEC const char* SDLCALL SDL_GetPixelFormatName(Uint32 format);
 1138
 1139extern DECLSPEC SDL_bool SDLCALL SDL_PixelFormatEnumToMasks(Uint32 format,
 1140                                                            int *bpp,
 1141                                                            Uint32 * Rmask,
 1142                                                            Uint32 * Gmask,
 1143                                                            Uint32 * Bmask,
 1144                                                            Uint32 * Amask);
 1145
 1146extern DECLSPEC Uint32 SDLCALL SDL_MasksToPixelFormatEnum(int bpp,
 1147                                                          Uint32 Rmask,
 1148                                                          Uint32 Gmask,
 1149                                                          Uint32 Bmask,
 1150                                                          Uint32 Amask);
 1151
 1152extern DECLSPEC SDL_PixelFormat * SDLCALL SDL_AllocFormat(Uint32 pixel_format);
 1153
 1154extern DECLSPEC void SDLCALL SDL_FreeFormat(SDL_PixelFormat *format);
 1155
 1156extern DECLSPEC SDL_Palette *SDLCALL SDL_AllocPalette(int ncolors);
 1157
 1158extern DECLSPEC int SDLCALL SDL_SetPixelFormatPalette(SDL_PixelFormat * format,
 1159                                                      SDL_Palette *palette);
 1160
 1161extern DECLSPEC int SDLCALL SDL_SetPaletteColors(SDL_Palette * palette,
 1162                                                 const SDL_Color * colors,
 1163                                                 int firstcolor, int ncolors);
 1164
 1165extern DECLSPEC void SDLCALL SDL_FreePalette(SDL_Palette * palette);
 1166
 1167extern DECLSPEC Uint32 SDLCALL SDL_MapRGB(const SDL_PixelFormat * format,
 1168                                          Uint8 r, Uint8 g, Uint8 b);
 1169
 1170extern DECLSPEC Uint32 SDLCALL SDL_MapRGBA(const SDL_PixelFormat * format,
 1171                                           Uint8 r, Uint8 g, Uint8 b,
 1172                                           Uint8 a);
 1173
 1174extern DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixel,
 1175                                        const SDL_PixelFormat * format,
 1176                                        Uint8 * r, Uint8 * g, Uint8 * b);
 1177
 1178extern DECLSPEC void SDLCALL SDL_GetRGBA(Uint32 pixel,
 1179                                         const SDL_PixelFormat * format,
 1180                                         Uint8 * r, Uint8 * g, Uint8 * b,
 1181                                         Uint8 * a);
 1182
 1183extern DECLSPEC void SDLCALL SDL_CalculateGammaRamp(float gamma, Uint16 * ramp);
 1184
 1185#ifdef __cplusplus
 1186}
 1187#endif
 1188#undef _begin_code_h
 1189
 1190#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__WATCOMC__)  || defined(__BORLANDC__)
 1191#ifdef __BORLANDC__
 1192#pragma nopackwarning
 1193#endif
 1194#pragma pack(pop)
 1195#endif
 1196
 1197#endif
 1198#ifndef _SDL_rect_h
 1199#define _SDL_rect_h
 1200
 1201#ifdef _begin_code_h
 1202#error Nested inclusion of begin_code.h
 1203#endif
 1204#define _begin_code_h
 1205
 1206#ifndef SDL_DEPRECATED
 1207#  if (__GNUC__ >= 4)
 1208#    define SDL_DEPRECATED __attribute__((deprecated))
 1209#  else
 1210#    define SDL_DEPRECATED
 1211#  endif
 1212#endif
 1213
 1214#ifndef DECLSPEC
 1215# if defined(__WIN32__) || defined(__WINRT__)
 1216#  ifdef __BORLANDC__
 1217#   ifdef BUILD_SDL
 1218#    define DECLSPEC
 1219#   else
 1220#    define DECLSPEC    __declspec(dllimport)
 1221#   endif
 1222#  else
 1223#   define DECLSPEC __declspec(dllexport)
 1224#  endif
 1225# else
 1226#  if defined(__GNUC__) && __GNUC__ >= 4
 1227#   define DECLSPEC __attribute__ ((visibility("default")))
 1228#  elif defined(__GNUC__) && __GNUC__ >= 2
 1229#   define DECLSPEC __declspec(dllexport)
 1230#  else
 1231#   define DECLSPEC
 1232#  endif
 1233# endif
 1234#endif
 1235
 1236#ifndef SDLCALL
 1237#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
 1238#define SDLCALL __cdecl
 1239#else
 1240#define SDLCALL
 1241#endif
 1242#endif
 1243
 1244#ifdef __SYMBIAN32__
 1245#undef DECLSPEC
 1246#define DECLSPEC
 1247#endif
 1248
 1249#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
 1250#ifdef _MSC_VER
 1251#pragma warning(disable: 4103)
 1252#endif
 1253#ifdef __BORLANDC__
 1254#pragma nopackwarning
 1255#endif
 1256#ifdef _M_X64
 1257
 1258#pragma pack(push,8)
 1259#else
 1260#pragma pack(push,4)
 1261#endif
 1262#endif
 1263
 1264#ifndef SDL_INLINE
 1265#if defined(__GNUC__)
 1266#define SDL_INLINE __inline__
 1267#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
 1268      defined(__DMC__) || defined(__SC__) || \
 1269      defined(__WATCOMC__) || defined(__LCC__) || \
 1270      defined(__DECC)
 1271#define SDL_INLINE __inline
 1272#ifndef __inline__
 1273#define __inline__ __inline
 1274#endif
 1275#else
 1276#define SDL_INLINE inline
 1277#ifndef __inline__
 1278#define __inline__ inline
 1279#endif
 1280#endif
 1281#endif
 1282
 1283#ifndef SDL_FORCE_INLINE
 1284#if defined(_MSC_VER)
 1285#define SDL_FORCE_INLINE __forceinline
 1286#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
 1287#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
 1288#else
 1289#define SDL_FORCE_INLINE static SDL_INLINE
 1290#endif
 1291#endif
 1292
 1293#if !defined(__MACH__)
 1294#ifndef NULL
 1295#ifdef __cplusplus
 1296#define NULL 0
 1297#else
 1298#define NULL ((void *)0)
 1299#endif
 1300#endif
 1301#endif
 1302
 1303#ifdef __cplusplus
 1304extern "C" {
 1305#endif
 1306
 1307typedef struct SDL_Point
 1308{
 1309    int x;
 1310    int y;
 1311} SDL_Point;
 1312
 1313typedef struct SDL_Rect
 1314{
 1315    int x, y;
 1316    int w, h;
 1317} SDL_Rect;
 1318
 1319SDL_FORCE_INLINE SDL_bool SDL_RectEmpty(const SDL_Rect *r)
 1320{
 1321    return ((!r) || (r->w <= 0) || (r->h <= 0)) ? SDL_TRUE : SDL_FALSE;
 1322}
 1323
 1324SDL_FORCE_INLINE SDL_bool SDL_RectEquals(const SDL_Rect *a, const SDL_Rect *b)
 1325{
 1326    return (a && b && (a->x == b->x) && (a->y == b->y) &&
 1327            (a->w == b->w) && (a->h == b->h)) ? SDL_TRUE : SDL_FALSE;
 1328}
 1329
 1330extern DECLSPEC SDL_bool SDLCALL SDL_HasIntersection(const SDL_Rect * A,
 1331                                                     const SDL_Rect * B);
 1332
 1333extern DECLSPEC SDL_bool SDLCALL SDL_IntersectRect(const SDL_Rect * A,
 1334                                                   const SDL_Rect * B,
 1335                                                   SDL_Rect * result);
 1336
 1337extern DECLSPEC void SDLCALL SDL_UnionRect(const SDL_Rect * A,
 1338                                           const SDL_Rect * B,
 1339                                           SDL_Rect * result);
 1340
 1341extern DECLSPEC SDL_bool SDLCALL SDL_EnclosePoints(const SDL_Point * points,
 1342                                                   int count,
 1343                                                   const SDL_Rect * clip,
 1344                                                   SDL_Rect * result);
 1345
 1346extern DECLSPEC SDL_bool SDLCALL SDL_IntersectRectAndLine(const SDL_Rect *
 1347                                                          rect, int *X1,
 1348                                                          int *Y1, int *X2,
 1349                                                          int *Y2);
 1350
 1351#ifdef __cplusplus
 1352}
 1353#endif
 1354#undef _begin_code_h
 1355
 1356#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__WATCOMC__)  || defined(__BORLANDC__)
 1357#ifdef __BORLANDC__
 1358#pragma nopackwarning
 1359#endif
 1360#pragma pack(pop)
 1361#endif
 1362
 1363#endif
 1364#ifndef _SDL_surface_h
 1365#define _SDL_surface_h
 1366
 1367#ifndef _SDL_blendmode_h
 1368#define _SDL_blendmode_h
 1369
 1370#ifdef _begin_code_h
 1371#error Nested inclusion of begin_code.h
 1372#endif
 1373#define _begin_code_h
 1374
 1375#ifndef SDL_DEPRECATED
 1376#  if (__GNUC__ >= 4)
 1377#    define SDL_DEPRECATED __attribute__((deprecated))
 1378#  else
 1379#    define SDL_DEPRECATED
 1380#  endif
 1381#endif
 1382
 1383#ifndef DECLSPEC
 1384# if defined(__WIN32__) || defined(__WINRT__)
 1385#  ifdef __BORLANDC__
 1386#   ifdef BUILD_SDL
 1387#    define DECLSPEC
 1388#   else
 1389#    define DECLSPEC    __declspec(dllimport)
 1390#   endif
 1391#  else
 1392#   define DECLSPEC __declspec(dllexport)
 1393#  endif
 1394# else
 1395#  if defined(__GNUC__) && __GNUC__ >= 4
 1396#   define DECLSPEC __attribute__ ((visibility("default")))
 1397#  elif defined(__GNUC__) && __GNUC__ >= 2
 1398#   define DECLSPEC __declspec(dllexport)
 1399#  else
 1400#   define DECLSPEC
 1401#  endif
 1402# endif
 1403#endif
 1404
 1405#ifndef SDLCALL
 1406#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
 1407#define SDLCALL __cdecl
 1408#else
 1409#define SDLCALL
 1410#endif
 1411#endif
 1412
 1413#ifdef __SYMBIAN32__
 1414#undef DECLSPEC
 1415#define DECLSPEC
 1416#endif
 1417
 1418#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
 1419#ifdef _MSC_VER
 1420#pragma warning(disable: 4103)
 1421#endif
 1422#ifdef __BORLANDC__
 1423#pragma nopackwarning
 1424#endif
 1425#ifdef _M_X64
 1426
 1427#pragma pack(push,8)
 1428#else
 1429#pragma pack(push,4)
 1430#endif
 1431#endif
 1432
 1433#ifndef SDL_INLINE
 1434#if defined(__GNUC__)
 1435#define SDL_INLINE __inline__
 1436#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
 1437      defined(__DMC__) || defined(__SC__) || \
 1438      defined(__WATCOMC__) || defined(__LCC__) || \
 1439      defined(__DECC)
 1440#define SDL_INLINE __inline
 1441#ifndef __inline__
 1442#define __inline__ __inline
 1443#endif
 1444#else
 1445#define SDL_INLINE inline
 1446#ifndef __inline__
 1447#define __inline__ inline
 1448#endif
 1449#endif
 1450#endif
 1451
 1452#ifndef SDL_FORCE_INLINE
 1453#if defined(_MSC_VER)
 1454#define SDL_FORCE_INLINE __forceinline
 1455#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
 1456#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
 1457#else
 1458#define SDL_FORCE_INLINE static SDL_INLINE
 1459#endif
 1460#endif
 1461
 1462#if !defined(__MACH__)
 1463#ifndef NULL
 1464#ifdef __cplusplus
 1465#define NULL 0
 1466#else
 1467#define NULL ((void *)0)
 1468#endif
 1469#endif
 1470#endif
 1471
 1472#ifdef __cplusplus
 1473extern "C" {
 1474#endif
 1475
 1476typedef enum
 1477{
 1478    SDL_BLENDMODE_NONE = 0x00000000,
 1479    SDL_BLENDMODE_BLEND = 0x00000001,
 1480    SDL_BLENDMODE_ADD = 0x00000002,
 1481    SDL_BLENDMODE_MOD = 0x00000004
 1482} SDL_BlendMode;
 1483
 1484#ifdef __cplusplus
 1485}
 1486#endif
 1487#undef _begin_code_h
 1488
 1489#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__WATCOMC__)  || defined(__BORLANDC__)
 1490#ifdef __BORLANDC__
 1491#pragma nopackwarning
 1492#endif
 1493#pragma pack(pop)
 1494#endif
 1495
 1496#endif
 1497
 1498#ifdef _begin_code_h
 1499#error Nested inclusion of begin_code.h
 1500#endif
 1501#define _begin_code_h
 1502
 1503#ifndef SDL_DEPRECATED
 1504#  if (__GNUC__ >= 4)
 1505#    define SDL_DEPRECATED __attribute__((deprecated))
 1506#  else
 1507#    define SDL_DEPRECATED
 1508#  endif
 1509#endif
 1510
 1511#ifndef DECLSPEC
 1512# if defined(__WIN32__) || defined(__WINRT__)
 1513#  ifdef __BORLANDC__
 1514#   ifdef BUILD_SDL
 1515#    define DECLSPEC
 1516#   else
 1517#    define DECLSPEC    __declspec(dllimport)
 1518#   endif
 1519#  else
 1520#   define DECLSPEC __declspec(dllexport)
 1521#  endif
 1522# else
 1523#  if defined(__GNUC__) && __GNUC__ >= 4
 1524#   define DECLSPEC __attribute__ ((visibility("default")))
 1525#  elif defined(__GNUC__) && __GNUC__ >= 2
 1526#   define DECLSPEC __declspec(dllexport)
 1527#  else
 1528#   define DECLSPEC
 1529#  endif
 1530# endif
 1531#endif
 1532
 1533#ifndef SDLCALL
 1534#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
 1535#define SDLCALL __cdecl
 1536#else
 1537#define SDLCALL
 1538#endif
 1539#endif
 1540
 1541#ifdef __SYMBIAN32__
 1542#undef DECLSPEC
 1543#define DECLSPEC
 1544#endif
 1545
 1546#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
 1547#ifdef _MSC_VER
 1548#pragma warning(disable: 4103)
 1549#endif
 1550#ifdef __BORLANDC__
 1551#pragma nopackwarning
 1552#endif
 1553#ifdef _M_X64
 1554
 1555#pragma pack(push,8)
 1556#else
 1557#pragma pack(push,4)
 1558#endif
 1559#endif
 1560
 1561#ifndef SDL_INLINE
 1562#if defined(__GNUC__)
 1563#define SDL_INLINE __inline__
 1564#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
 1565      defined(__DMC__) || defined(__SC__) || \
 1566      defined(__WATCOMC__) || defined(__LCC__) || \
 1567      defined(__DECC)
 1568#define SDL_INLINE __inline
 1569#ifndef __inline__
 1570#define __inline__ __inline
 1571#endif
 1572#else
 1573#define SDL_INLINE inline
 1574#ifndef __inline__
 1575#define __inline__ inline
 1576#endif
 1577#endif
 1578#endif
 1579
 1580#ifndef SDL_FORCE_INLINE
 1581#if defined(_MSC_VER)
 1582#define SDL_FORCE_INLINE __forceinline
 1583#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
 1584#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
 1585#else
 1586#define SDL_FORCE_INLINE static SDL_INLINE
 1587#endif
 1588#endif
 1589
 1590#if !defined(__MACH__)
 1591#ifndef NULL
 1592#ifdef __cplusplus
 1593#define NULL 0
 1594#else
 1595#define NULL ((void *)0)
 1596#endif
 1597#endif
 1598#endif
 1599
 1600#ifdef __cplusplus
 1601extern "C" {
 1602#endif
 1603
 1604#define SDL_SWSURFACE       0
 1605#define SDL_PREALLOC        0x00000001
 1606#define SDL_RLEACCEL        0x00000002
 1607#define SDL_DONTFREE        0x00000004
 1608
 1609#define SDL_MUSTLOCK(S) (((S)->flags & SDL_RLEACCEL) != 0)
 1610
 1611typedef struct SDL_Surface
 1612{
 1613    Uint32 flags;
 1614    SDL_PixelFormat *format;
 1615    int w, h;
 1616    int pitch;
 1617    void *pixels;
 1618
 1619    void *userdata;
 1620
 1621    int locked;
 1622    void *lock_data;
 1623
 1624    SDL_Rect clip_rect;
 1625
 1626    struct SDL_BlitMap *map;
 1627
 1628    int refcount;
 1629} SDL_Surface;
 1630
 1631typedef int (*SDL_blit) (struct SDL_Surface * src, SDL_Rect * srcrect,
 1632                         struct SDL_Surface * dst, SDL_Rect * dstrect);
 1633
 1634extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurface
 1635    (Uint32 flags, int width, int height, int depth,
 1636     Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
 1637extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceFrom(void *pixels,
 1638                                                              int width,
 1639                                                              int height,
 1640                                                              int depth,
 1641                                                              int pitch,
 1642                                                              Uint32 Rmask,
 1643                                                              Uint32 Gmask,
 1644                                                              Uint32 Bmask,
 1645                                                              Uint32 Amask);
 1646extern DECLSPEC void SDLCALL SDL_FreeSurface(SDL_Surface * surface);
 1647
 1648extern DECLSPEC int SDLCALL SDL_SetSurfacePalette(SDL_Surface * surface,
 1649                                                  SDL_Palette * palette);
 1650
 1651extern DECLSPEC int SDLCALL SDL_LockSurface(SDL_Surface * surface);
 1652
 1653extern DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface * surface);
 1654
 1655extern DECLSPEC SDL_Surface *SDLCALL SDL_LoadBMP_RW(SDL_RWops * src,
 1656                                                    int freesrc);
 1657
 1658#define SDL_LoadBMP(file)   SDL_LoadBMP_RW(SDL_RWFromFile(file, "rb"), 1)
 1659
 1660extern DECLSPEC int SDLCALL SDL_SaveBMP_RW
 1661    (SDL_Surface * surface, SDL_RWops * dst, int freedst);
 1662
 1663#define SDL_SaveBMP(surface, file) \
 1664        SDL_SaveBMP_RW(surface, SDL_RWFromFile(file, "wb"), 1)
 1665
 1666extern DECLSPEC int SDLCALL SDL_SetSurfaceRLE(SDL_Surface * surface,
 1667                                              int flag);
 1668
 1669extern DECLSPEC int SDLCALL SDL_SetColorKey(SDL_Surface * surface,
 1670                                            int flag, Uint32 key);
 1671
 1672extern DECLSPEC int SDLCALL SDL_GetColorKey(SDL_Surface * surface,
 1673                                            Uint32 * key);
 1674
 1675extern DECLSPEC int SDLCALL SDL_SetSurfaceColorMod(SDL_Surface * surface,
 1676                                                   Uint8 r, Uint8 g, Uint8 b);
 1677
 1678extern DECLSPEC int SDLCALL SDL_GetSurfaceColorMod(SDL_Surface * surface,
 1679                                                   Uint8 * r, Uint8 * g,
 1680                                                   Uint8 * b);
 1681
 1682extern DECLSPEC int SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface * surface,
 1683                                                   Uint8 alpha);
 1684
 1685extern DECLSPEC int SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface * surface,
 1686                                                   Uint8 * alpha);
 1687
 1688extern DECLSPEC int SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface * surface,
 1689                                                    SDL_BlendMode blendMode);
 1690
 1691extern DECLSPEC int SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface * surface,
 1692                                                    SDL_BlendMode *blendMode);
 1693
 1694extern DECLSPEC SDL_bool SDLCALL SDL_SetClipRect(SDL_Surface * surface,
 1695                                                 const SDL_Rect * rect);
 1696
 1697extern DECLSPEC void SDLCALL SDL_GetClipRect(SDL_Surface * surface,
 1698                                             SDL_Rect * rect);
 1699
 1700extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurface
 1701    (SDL_Surface * src, const SDL_PixelFormat * fmt, Uint32 flags);
 1702extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurfaceFormat
 1703    (SDL_Surface * src, Uint32 pixel_format, Uint32 flags);
 1704
 1705extern DECLSPEC int SDLCALL SDL_ConvertPixels(int width, int height,
 1706                                              Uint32 src_format,
 1707                                              const void * src, int src_pitch,
 1708                                              Uint32 dst_format,
 1709                                              void * dst, int dst_pitch);
 1710
 1711extern DECLSPEC int SDLCALL SDL_FillRect
 1712    (SDL_Surface * dst, const SDL_Rect * rect, Uint32 color);
 1713extern DECLSPEC int SDLCALL SDL_FillRects
 1714    (SDL_Surface * dst, const SDL_Rect * rects, int count, Uint32 color);
 1715
 1716#define SDL_BlitSurface SDL_UpperBlit
 1717
 1718extern DECLSPEC int SDLCALL SDL_UpperBlit
 1719    (SDL_Surface * src, const SDL_Rect * srcrect,
 1720     SDL_Surface * dst, SDL_Rect * dstrect);
 1721
 1722extern DECLSPEC int SDLCALL SDL_LowerBlit
 1723    (SDL_Surface * src, SDL_Rect * srcrect,
 1724     SDL_Surface * dst, SDL_Rect * dstrect);
 1725
 1726extern DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface * src,
 1727                                            const SDL_Rect * srcrect,
 1728                                            SDL_Surface * dst,
 1729                                            const SDL_Rect * dstrect);
 1730
 1731#define SDL_BlitScaled SDL_UpperBlitScaled
 1732
 1733extern DECLSPEC int SDLCALL SDL_UpperBlitScaled
 1734    (SDL_Surface * src, const SDL_Rect * srcrect,
 1735    SDL_Surface * dst, SDL_Rect * dstrect);
 1736
 1737extern DECLSPEC int SDLCALL SDL_LowerBlitScaled
 1738    (SDL_Surface * src, SDL_Rect * srcrect,
 1739    SDL_Surface * dst, SDL_Rect * dstrect);
 1740
 1741#ifdef __cplusplus
 1742}
 1743#endif
 1744#undef _begin_code_h
 1745
 1746#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__WATCOMC__)  || defined(__BORLANDC__)
 1747#ifdef __BORLANDC__
 1748#pragma nopackwarning
 1749#endif
 1750#pragma pack(pop)
 1751#endif
 1752
 1753#endif
 1754
 1755#ifdef _begin_code_h
 1756#error Nested inclusion of begin_code.h
 1757#endif
 1758#define _begin_code_h
 1759
 1760#ifndef SDL_DEPRECATED
 1761#  if (__GNUC__ >= 4)
 1762#    define SDL_DEPRECATED __attribute__((deprecated))
 1763#  else
 1764#    define SDL_DEPRECATED
 1765#  endif
 1766#endif
 1767
 1768#ifndef DECLSPEC
 1769# if defined(__WIN32__) || defined(__WINRT__)
 1770#  ifdef __BORLANDC__
 1771#   ifdef BUILD_SDL
 1772#    define DECLSPEC
 1773#   else
 1774#    define DECLSPEC    __declspec(dllimport)
 1775#   endif
 1776#  else
 1777#   define DECLSPEC __declspec(dllexport)
 1778#  endif
 1779# else
 1780#  if defined(__GNUC__) && __GNUC__ >= 4
 1781#   define DECLSPEC __attribute__ ((visibility("default")))
 1782#  elif defined(__GNUC__) && __GNUC__ >= 2
 1783#   define DECLSPEC __declspec(dllexport)
 1784#  else
 1785#   define DECLSPEC
 1786#  endif
 1787# endif
 1788#endif
 1789
 1790#ifndef SDLCALL
 1791#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
 1792#define SDLCALL __cdecl
 1793#else
 1794#define SDLCALL
 1795#endif
 1796#endif
 1797
 1798#ifdef __SYMBIAN32__
 1799#undef DECLSPEC
 1800#define DECLSPEC
 1801#endif
 1802
 1803#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
 1804#ifdef _MSC_VER
 1805#pragma warning(disable: 4103)
 1806#endif
 1807#ifdef __BORLANDC__
 1808#pragma nopackwarning
 1809#endif
 1810#ifdef _M_X64
 1811
 1812#pragma pack(push,8)
 1813#else
 1814#pragma pack(push,4)
 1815#endif
 1816#endif
 1817
 1818#ifndef SDL_INLINE
 1819#if defined(__GNUC__)
 1820#define SDL_INLINE __inline__
 1821#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
 1822      defined(__DMC__) || defined(__SC__) || \
 1823      defined(__WATCOMC__) || defined(__LCC__) || \
 1824      defined(__DECC)
 1825#define SDL_INLINE __inline
 1826#ifndef __inline__
 1827#define __inline__ __inline
 1828#endif
 1829#else
 1830#define SDL_INLINE inline
 1831#ifndef __inline__
 1832#define __inline__ inline
 1833#endif
 1834#endif
 1835#endif
 1836
 1837#ifndef SDL_FORCE_INLINE
 1838#if defined(_MSC_VER)
 1839#define SDL_FORCE_INLINE __forceinline
 1840#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
 1841#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
 1842#else
 1843#define SDL_FORCE_INLINE static SDL_INLINE
 1844#endif
 1845#endif
 1846
 1847#if !defined(__MACH__)
 1848#ifndef NULL
 1849#ifdef __cplusplus
 1850#define NULL 0
 1851#else
 1852#define NULL ((void *)0)
 1853#endif
 1854#endif
 1855#endif
 1856
 1857#ifdef __cplusplus
 1858extern "C" {
 1859#endif
 1860
 1861typedef struct
 1862{
 1863    Uint32 format;
 1864    int w;
 1865    int h;
 1866    int refresh_rate;
 1867    void *driverdata;
 1868} SDL_DisplayMode;
 1869
 1870typedef struct SDL_Window SDL_Window;
 1871
 1872typedef enum
 1873{
 1874    SDL_WINDOW_FULLSCREEN = 0x00000001,
 1875    SDL_WINDOW_OPENGL = 0x00000002,
 1876    SDL_WINDOW_SHOWN = 0x00000004,
 1877    SDL_WINDOW_HIDDEN = 0x00000008,
 1878    SDL_WINDOW_BORDERLESS = 0x00000010,
 1879    SDL_WINDOW_RESIZABLE = 0x00000020,
 1880    SDL_WINDOW_MINIMIZED = 0x00000040,
 1881    SDL_WINDOW_MAXIMIZED = 0x00000080,
 1882    SDL_WINDOW_INPUT_GRABBED = 0x00000100,
 1883    SDL_WINDOW_INPUT_FOCUS = 0x00000200,
 1884    SDL_WINDOW_MOUSE_FOCUS = 0x00000400,
 1885    SDL_WINDOW_FULLSCREEN_DESKTOP = ( SDL_WINDOW_FULLSCREEN | 0x00001000 ),
 1886    SDL_WINDOW_FOREIGN = 0x00000800,
 1887    SDL_WINDOW_ALLOW_HIGHDPI = 0x00002000
 1888} SDL_WindowFlags;
 1889
 1890#define SDL_WINDOWPOS_UNDEFINED_MASK    0x1FFF0000
 1891#define SDL_WINDOWPOS_UNDEFINED_DISPLAY(X)  (SDL_WINDOWPOS_UNDEFINED_MASK|(X))
 1892#define SDL_WINDOWPOS_UNDEFINED         SDL_WINDOWPOS_UNDEFINED_DISPLAY(0)
 1893#define SDL_WINDOWPOS_ISUNDEFINED(X)    \
 1894            (((X)&0xFFFF0000) == SDL_WINDOWPOS_UNDEFINED_MASK)
 1895
 1896#define SDL_WINDOWPOS_CENTERED_MASK    0x2FFF0000
 1897#define SDL_WINDOWPOS_CENTERED_DISPLAY(X)  (SDL_WINDOWPOS_CENTERED_MASK|(X))
 1898#define SDL_WINDOWPOS_CENTERED         SDL_WINDOWPOS_CENTERED_DISPLAY(0)
 1899#define SDL_WINDOWPOS_ISCENTERED(X)    \
 1900            (((X)&0xFFFF0000) == SDL_WINDOWPOS_CENTERED_MASK)
 1901
 1902typedef enum
 1903{
 1904    SDL_WINDOWEVENT_NONE,
 1905    SDL_WINDOWEVENT_SHOWN,
 1906    SDL_WINDOWEVENT_HIDDEN,
 1907    SDL_WINDOWEVENT_EXPOSED,
 1908    SDL_WINDOWEVENT_MOVED,
 1909    SDL_WINDOWEVENT_RESIZED,
 1910    SDL_WINDOWEVENT_SIZE_CHANGED,
 1911    SDL_WINDOWEVENT_MINIMIZED,
 1912    SDL_WINDOWEVENT_MAXIMIZED,
 1913    SDL_WINDOWEVENT_RESTORED,
 1914    SDL_WINDOWEVENT_ENTER,
 1915    SDL_WINDOWEVENT_LEAVE,
 1916    SDL_WINDOWEVENT_FOCUS_GAINED,
 1917    SDL_WINDOWEVENT_FOCUS_LOST,
 1918    SDL_WINDOWEVENT_CLOSE
 1919} SDL_WindowEventID;
 1920
 1921typedef void *SDL_GLContext;
 1922
 1923typedef enum
 1924{
 1925    SDL_GL_RED_SIZE,
 1926    SDL_GL_GREEN_SIZE,
 1927    SDL_GL_BLUE_SIZE,
 1928    SDL_GL_ALPHA_SIZE,
 1929    SDL_GL_BUFFER_SIZE,
 1930    SDL_GL_DOUBLEBUFFER,
 1931    SDL_GL_DEPTH_SIZE,
 1932    SDL_GL_STENCIL_SIZE,
 1933    SDL_GL_ACCUM_RED_SIZE,
 1934    SDL_GL_ACCUM_GREEN_SIZE,
 1935    SDL_GL_ACCUM_BLUE_SIZE,
 1936    SDL_GL_ACCUM_ALPHA_SIZE,
 1937    SDL_GL_STEREO,
 1938    SDL_GL_MULTISAMPLEBUFFERS,
 1939    SDL_GL_MULTISAMPLESAMPLES,
 1940    SDL_GL_ACCELERATED_VISUAL,
 1941    SDL_GL_RETAINED_BACKING,
 1942    SDL_GL_CONTEXT_MAJOR_VERSION,
 1943    SDL_GL_CONTEXT_MINOR_VERSION,
 1944    SDL_GL_CONTEXT_EGL,
 1945    SDL_GL_CONTEXT_FLAGS,
 1946    SDL_GL_CONTEXT_PROFILE_MASK,
 1947    SDL_GL_SHARE_WITH_CURRENT_CONTEXT,
 1948    SDL_GL_FRAMEBUFFER_SRGB_CAPABLE
 1949} SDL_GLattr;
 1950
 1951typedef enum
 1952{
 1953    SDL_GL_CONTEXT_PROFILE_CORE           = 0x0001,
 1954    SDL_GL_CONTEXT_PROFILE_COMPATIBILITY  = 0x0002,
 1955    SDL_GL_CONTEXT_PROFILE_ES             = 0x0004
 1956} SDL_GLprofile;
 1957
 1958typedef enum
 1959{
 1960    SDL_GL_CONTEXT_DEBUG_FLAG              = 0x0001,
 1961    SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG = 0x0002,
 1962    SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG      = 0x0004,
 1963    SDL_GL_CONTEXT_RESET_ISOLATION_FLAG    = 0x0008
 1964} SDL_GLcontextFlag;
 1965
 1966extern DECLSPEC int SDLCALL SDL_GetNumVideoDrivers(void);
 1967
 1968extern DECLSPEC const char *SDLCALL SDL_GetVideoDriver(int index);
 1969
 1970extern DECLSPEC int SDLCALL SDL_VideoInit(const char *driver_name);
 1971
 1972extern DECLSPEC void SDLCALL SDL_VideoQuit(void);
 1973
 1974extern DECLSPEC const char *SDLCALL SDL_GetCurrentVideoDriver(void);
 1975
 1976extern DECLSPEC int SDLCALL SDL_GetNumVideoDisplays(void);
 1977
 1978extern DECLSPEC const char * SDLCALL SDL_GetDisplayName(int displayIndex);
 1979
 1980extern DECLSPEC int SDLCALL SDL_GetDisplayBounds(int displayIndex, SDL_Rect * rect);
 1981
 1982extern DECLSPEC int SDLCALL SDL_GetNumDisplayModes(int displayIndex);
 1983
 1984extern DECLSPEC int SDLCALL SDL_GetDisplayMode(int displayIndex, int modeIndex,
 1985                                               SDL_DisplayMode * mode);
 1986
 1987extern DECLSPEC int SDLCALL SDL_GetDesktopDisplayMode(int displayIndex, SDL_DisplayMode * mode);
 1988
 1989extern DECLSPEC int SDLCALL SDL_GetCurrentDisplayMode(int displayIndex, SDL_DisplayMode * mode);
 1990
 1991extern DECLSPEC SDL_DisplayMode * SDLCALL SDL_GetClosestDisplayMode(int displayIndex, const SDL_DisplayMode * mode, SDL_DisplayMode * closest);
 1992
 1993extern DECLSPEC int SDLCALL SDL_GetWindowDisplayIndex(SDL_Window * window);
 1994
 1995extern DECLSPEC int SDLCALL SDL_SetWindowDisplayMode(SDL_Window * window,
 1996                                                     const SDL_DisplayMode
 1997                                                         * mode);
 1998
 1999extern DECLSPEC int SDLCALL SDL_GetWindowDisplayMode(SDL_Window * window,
 2000                                                     SDL_DisplayMode * mode);
 2001
 2002extern DECLSPEC Uint32 SDLCALL SDL_GetWindowPixelFormat(SDL_Window * window);
 2003
 2004extern DECLSPEC SDL_Window * SDLCALL SDL_CreateWindow(const char *title,
 2005                                                      int x, int y, int w,
 2006                                                      int h, Uint32 flags);
 2007
 2008extern DECLSPEC SDL_Window * SDLCALL SDL_CreateWindowFrom(const void *data);
 2009
 2010extern DECLSPEC Uint32 SDLCALL SDL_GetWindowID(SDL_Window * window);
 2011
 2012extern DECLSPEC SDL_Window * SDLCALL SDL_GetWindowFromID(Uint32 id);
 2013
 2014extern DECLSPEC Uint32 SDLCALL SDL_GetWindowFlags(SDL_Window * window);
 2015
 2016extern DECLSPEC void SDLCALL SDL_SetWindowTitle(SDL_Window * window,
 2017                                                const char *title);
 2018
 2019extern DECLSPEC const char *SDLCALL SDL_GetWindowTitle(SDL_Window * window);
 2020
 2021extern DECLSPEC void SDLCALL SDL_SetWindowIcon(SDL_Window * window,
 2022                                               SDL_Surface * icon);
 2023
 2024extern DECLSPEC void* SDLCALL SDL_SetWindowData(SDL_Window * window,
 2025                                                const char *name,
 2026                                                void *userdata);
 2027
 2028extern DECLSPEC void *SDLCALL SDL_GetWindowData(SDL_Window * window,
 2029                                                const char *name);
 2030
 2031extern DECLSPEC void SDLCALL SDL_SetWindowPosition(SDL_Window * window,
 2032                                                   int x, int y);
 2033
 2034extern DECLSPEC void SDLCALL SDL_GetWindowPosition(SDL_Window * window,
 2035                                                   int *x, int *y);
 2036
 2037extern DECLSPEC void SDLCALL SDL_SetWindowSize(SDL_Window * window, int w,
 2038                                               int h);
 2039
 2040extern DECLSPEC void SDLCALL SDL_GetWindowSize(SDL_Window * window, int *w,
 2041                                               int *h);
 2042
 2043extern DECLSPEC void SDLCALL SDL_SetWindowMinimumSize(SDL_Window * window,
 2044                                                      int min_w, int min_h);
 2045
 2046extern DECLSPEC void SDLCALL SDL_GetWindowMinimumSize(SDL_Window * window,
 2047                                                      int *w, int *h);
 2048
 2049extern DECLSPEC void SDLCALL SDL_SetWindowMaximumSize(SDL_Window * window,
 2050                                                      int max_w, int max_h);
 2051
 2052extern DECLSPEC void SDLCALL SDL_GetWindowMaximumSize(SDL_Window * window,
 2053                                                      int *w, int *h);
 2054
 2055extern DECLSPEC void SDLCALL SDL_SetWindowBordered(SDL_Window * window,
 2056                                                   SDL_bool bordered);
 2057
 2058extern DECLSPEC void SDLCALL SDL_ShowWindow(SDL_Window * window);
 2059
 2060extern DECLSPEC void SDLCALL SDL_HideWindow(SDL_Window * window);
 2061
 2062extern DECLSPEC void SDLCALL SDL_RaiseWindow(SDL_Window * window);
 2063
 2064extern DECLSPEC void SDLCALL SDL_MaximizeWindow(SDL_Window * window);
 2065
 2066extern DECLSPEC void SDLCALL SDL_MinimizeWindow(SDL_Window * window);
 2067
 2068extern DECLSPEC void SDLCALL SDL_RestoreWindow(SDL_Window * window);
 2069
 2070extern DECLSPEC int SDLCALL SDL_SetWindowFullscreen(SDL_Window * window,
 2071                                                    Uint32 flags);
 2072
 2073extern DECLSPEC SDL_Surface * SDLCALL SDL_GetWindowSurface(SDL_Window * window);
 2074
 2075extern DECLSPEC int SDLCALL SDL_UpdateWindowSurface(SDL_Window * window);
 2076
 2077extern DECLSPEC int SDLCALL SDL_UpdateWindowSurfaceRects(SDL_Window * window,
 2078                                                         const SDL_Rect * rects,
 2079                                                         int numrects);
 2080
 2081extern DECLSPEC void SDLCALL SDL_SetWindowGrab(SDL_Window * window,
 2082                                               SDL_bool grabbed);
 2083
 2084extern DECLSPEC SDL_bool SDLCALL SDL_GetWindowGrab(SDL_Window * window);
 2085
 2086extern DECLSPEC int SDLCALL SDL_SetWindowBrightness(SDL_Window * window, float brightness);
 2087
 2088extern DECLSPEC float SDLCALL SDL_GetWindowBrightness(SDL_Window * window);
 2089
 2090extern DECLSPEC int SDLCALL SDL_SetWindowGammaRamp(SDL_Window * window,
 2091                                                   const Uint16 * red,
 2092                                                   const Uint16 * green,
 2093                                                   const Uint16 * blue);
 2094
 2095extern DECLSPEC int SDLCALL SDL_GetWindowGammaRamp(SDL_Window * window,
 2096                                                   Uint16 * red,
 2097                                                   Uint16 * green,
 2098                                                   Uint16 * blue);
 2099
 2100extern DECLSPEC void SDLCALL SDL_DestroyWindow(SDL_Window * window);
 2101
 2102extern DECLSPEC SDL_bool SDLCALL SDL_IsScreenSaverEnabled(void);
 2103
 2104extern DECLSPEC void SDLCALL SDL_EnableScreenSaver(void);
 2105
 2106extern DECLSPEC void SDLCALL SDL_DisableScreenSaver(void);
 2107
 2108extern DECLSPEC int SDLCALL SDL_GL_LoadLibrary(const char *path);
 2109
 2110extern DECLSPEC void *SDLCALL SDL_GL_GetProcAddress(const char *proc);
 2111
 2112extern DECLSPEC void SDLCALL SDL_GL_UnloadLibrary(void);
 2113
 2114extern DECLSPEC SDL_bool SDLCALL SDL_GL_ExtensionSupported(const char
 2115                                                           *extension);
 2116
 2117extern DECLSPEC void SDLCALL SDL_GL_ResetAttributes(void);
 2118
 2119extern DECLSPEC int SDLCALL SDL_GL_SetAttribute(SDL_GLattr attr, int value);
 2120
 2121extern DECLSPEC int SDLCALL SDL_GL_GetAttribute(SDL_GLattr attr, int *value);
 2122
 2123extern DECLSPEC SDL_GLContext SDLCALL SDL_GL_CreateContext(SDL_Window *
 2124                                                           window);
 2125
 2126extern DECLSPEC int SDLCALL SDL_GL_MakeCurrent(SDL_Window * window,
 2127                                               SDL_GLContext context);
 2128
 2129extern DECLSPEC SDL_Window* SDLCALL SDL_GL_GetCurrentWindow(void);
 2130
 2131extern DECLSPEC SDL_GLContext SDLCALL SDL_GL_GetCurrentContext(void);
 2132
 2133extern DECLSPEC void SDLCALL SDL_GL_GetDrawableSize(SDL_Window * window, int *w,
 2134                                                    int *h);
 2135
 2136extern DECLSPEC int SDLCALL SDL_GL_SetSwapInterval(int interval);
 2137
 2138extern DECLSPEC int SDLCALL SDL_GL_GetSwapInterval(void);
 2139
 2140extern DECLSPEC void SDLCALL SDL_GL_SwapWindow(SDL_Window * window);
 2141
 2142extern DECLSPEC void SDLCALL SDL_GL_DeleteContext(SDL_GLContext context);
 2143
 2144#ifdef __cplusplus
 2145}
 2146#endif
 2147#undef _begin_code_h
 2148
 2149#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__WATCOMC__)  || defined(__BORLANDC__)
 2150#ifdef __BORLANDC__
 2151#pragma nopackwarning
 2152#endif
 2153#pragma pack(pop)
 2154#endif
 2155
 2156#endif
 2157#ifndef _SDL_keyboard_h
 2158#define _SDL_keyboard_h
 2159
 2160#ifndef _SDL_keycode_h
 2161#define _SDL_keycode_h
 2162
 2163#ifndef _SDL_scancode_h
 2164#define _SDL_scancode_h
 2165
 2166typedef enum
 2167{
 2168    SDL_SCANCODE_UNKNOWN = 0,
 2169
 2170    SDL_SCANCODE_A = 4,
 2171    SDL_SCANCODE_B = 5,
 2172    SDL_SCANCODE_C = 6,
 2173    SDL_SCANCODE_D = 7,
 2174    SDL_SCANCODE_E = 8,
 2175    SDL_SCANCODE_F = 9,
 2176    SDL_SCANCODE_G = 10,
 2177    SDL_SCANCODE_H = 11,
 2178    SDL_SCANCODE_I = 12,
 2179    SDL_SCANCODE_J = 13,
 2180    SDL_SCANCODE_K = 14,
 2181    SDL_SCANCODE_L = 15,
 2182    SDL_SCANCODE_M = 16,
 2183    SDL_SCANCODE_N = 17,
 2184    SDL_SCANCODE_O = 18,
 2185    SDL_SCANCODE_P = 19,
 2186    SDL_SCANCODE_Q = 20,
 2187    SDL_SCANCODE_R = 21,
 2188    SDL_SCANCODE_S = 22,
 2189    SDL_SCANCODE_T = 23,
 2190    SDL_SCANCODE_U = 24,
 2191    SDL_SCANCODE_V = 25,
 2192    SDL_SCANCODE_W = 26,
 2193    SDL_SCANCODE_X = 27,
 2194    SDL_SCANCODE_Y = 28,
 2195    SDL_SCANCODE_Z = 29,
 2196
 2197    SDL_SCANCODE_1 = 30,
 2198    SDL_SCANCODE_2 = 31,
 2199    SDL_SCANCODE_3 = 32,
 2200    SDL_SCANCODE_4 = 33,
 2201    SDL_SCANCODE_5 = 34,
 2202    SDL_SCANCODE_6 = 35,
 2203    SDL_SCANCODE_7 = 36,
 2204    SDL_SCANCODE_8 = 37,
 2205    SDL_SCANCODE_9 = 38,
 2206    SDL_SCANCODE_0 = 39,
 2207
 2208    SDL_SCANCODE_RETURN = 40,
 2209    SDL_SCANCODE_ESCAPE = 41,
 2210    SDL_SCANCODE_BACKSPACE = 42,
 2211    SDL_SCANCODE_TAB = 43,
 2212    SDL_SCANCODE_SPACE = 44,
 2213
 2214    SDL_SCANCODE_MINUS = 45,
 2215    SDL_SCANCODE_EQUALS = 46,
 2216    SDL_SCANCODE_LEFTBRACKET = 47,
 2217    SDL_SCANCODE_RIGHTBRACKET = 48,
 2218    SDL_SCANCODE_BACKSLASH = 49,
 2219    SDL_SCANCODE_NONUSHASH = 50,
 2220    SDL_SCANCODE_SEMICOLON = 51,
 2221    SDL_SCANCODE_APOSTROPHE = 52,
 2222    SDL_SCANCODE_GRAVE = 53,
 2223    SDL_SCANCODE_COMMA = 54,
 2224    SDL_SCANCODE_PERIOD = 55,
 2225    SDL_SCANCODE_SLASH = 56,
 2226
 2227    SDL_SCANCODE_CAPSLOCK = 57,
 2228
 2229    SDL_SCANCODE_F1 = 58,
 2230    SDL_SCANCODE_F2 = 59,
 2231    SDL_SCANCODE_F3 = 60,
 2232    SDL_SCANCODE_F4 = 61,
 2233    SDL_SCANCODE_F5 = 62,
 2234    SDL_SCANCODE_F6 = 63,
 2235    SDL_SCANCODE_F7 = 64,
 2236    SDL_SCANCODE_F8 = 65,
 2237    SDL_SCANCODE_F9 = 66,
 2238    SDL_SCANCODE_F10 = 67,
 2239    SDL_SCANCODE_F11 = 68,
 2240    SDL_SCANCODE_F12 = 69,
 2241
 2242    SDL_SCANCODE_PRINTSCREEN = 70,
 2243    SDL_SCANCODE_SCROLLLOCK = 71,
 2244    SDL_SCANCODE_PAUSE = 72,
 2245    SDL_SCANCODE_INSERT = 73,
 2246    SDL_SCANCODE_HOME = 74,
 2247    SDL_SCANCODE_PAGEUP = 75,
 2248    SDL_SCANCODE_DELETE = 76,
 2249    SDL_SCANCODE_END = 77,
 2250    SDL_SCANCODE_PAGEDOWN = 78,
 2251    SDL_SCANCODE_RIGHT = 79,
 2252    SDL_SCANCODE_LEFT = 80,
 2253    SDL_SCANCODE_DOWN = 81,
 2254    SDL_SCANCODE_UP = 82,
 2255
 2256    SDL_SCANCODE_NUMLOCKCLEAR = 83,
 2257    SDL_SCANCODE_KP_DIVIDE = 84,
 2258    SDL_SCANCODE_KP_MULTIPLY = 85,
 2259    SDL_SCANCODE_KP_MINUS = 86,
 2260    SDL_SCANCODE_KP_PLUS = 87,
 2261    SDL_SCANCODE_KP_ENTER = 88,
 2262    SDL_SCANCODE_KP_1 = 89,
 2263    SDL_SCANCODE_KP_2 = 90,
 2264    SDL_SCANCODE_KP_3 = 91,
 2265    SDL_SCANCODE_KP_4 = 92,
 2266    SDL_SCANCODE_KP_5 = 93,
 2267    SDL_SCANCODE_KP_6 = 94,
 2268    SDL_SCANCODE_KP_7 = 95,
 2269    SDL_SCANCODE_KP_8 = 96,
 2270    SDL_SCANCODE_KP_9 = 97,
 2271    SDL_SCANCODE_KP_0 = 98,
 2272    SDL_SCANCODE_KP_PERIOD = 99,
 2273
 2274    SDL_SCANCODE_NONUSBACKSLASH = 100,
 2275    SDL_SCANCODE_APPLICATION = 101,
 2276    SDL_SCANCODE_POWER = 102,
 2277    SDL_SCANCODE_KP_EQUALS = 103,
 2278    SDL_SCANCODE_F13 = 104,
 2279    SDL_SCANCODE_F14 = 105,
 2280    SDL_SCANCODE_F15 = 106,
 2281    SDL_SCANCODE_F16 = 107,
 2282    SDL_SCANCODE_F17 = 108,
 2283    SDL_SCANCODE_F18 = 109,
 2284    SDL_SCANCODE_F19 = 110,
 2285    SDL_SCANCODE_F20 = 111,
 2286    SDL_SCANCODE_F21 = 112,
 2287    SDL_SCANCODE_F22 = 113,
 2288    SDL_SCANCODE_F23 = 114,
 2289    SDL_SCANCODE_F24 = 115,
 2290    SDL_SCANCODE_EXECUTE = 116,
 2291    SDL_SCANCODE_HELP = 117,
 2292    SDL_SCANCODE_MENU = 118,
 2293    SDL_SCANCODE_SELECT = 119,
 2294    SDL_SCANCODE_STOP = 120,
 2295    SDL_SCANCODE_AGAIN = 121,
 2296    SDL_SCANCODE_UNDO = 122,
 2297    SDL_SCANCODE_CUT = 123,
 2298    SDL_SCANCODE_COPY = 124,
 2299    SDL_SCANCODE_PASTE = 125,
 2300    SDL_SCANCODE_FIND = 126,
 2301    SDL_SCANCODE_MUTE = 127,
 2302    SDL_SCANCODE_VOLUMEUP = 128,
 2303    SDL_SCANCODE_VOLUMEDOWN = 129,
 2304
 2305    SDL_SCANCODE_KP_COMMA = 133,
 2306    SDL_SCANCODE_KP_EQUALSAS400 = 134,
 2307
 2308    SDL_SCANCODE_INTERNATIONAL1 = 135,
 2309    SDL_SCANCODE_INTERNATIONAL2 = 136,
 2310    SDL_SCANCODE_INTERNATIONAL3 = 137,
 2311    SDL_SCANCODE_INTERNATIONAL4 = 138,
 2312    SDL_SCANCODE_INTERNATIONAL5 = 139,
 2313    SDL_SCANCODE_INTERNATIONAL6 = 140,
 2314    SDL_SCANCODE_INTERNATIONAL7 = 141,
 2315    SDL_SCANCODE_INTERNATIONAL8 = 142,
 2316    SDL_SCANCODE_INTERNATIONAL9 = 143,
 2317    SDL_SCANCODE_LANG1 = 144,
 2318    SDL_SCANCODE_LANG2 = 145,
 2319    SDL_SCANCODE_LANG3 = 146,
 2320    SDL_SCANCODE_LANG4 = 147,
 2321    SDL_SCANCODE_LANG5 = 148,
 2322    SDL_SCANCODE_LANG6 = 149,
 2323    SDL_SCANCODE_LANG7 = 150,
 2324    SDL_SCANCODE_LANG8 = 151,
 2325    SDL_SCANCODE_LANG9 = 152,
 2326
 2327    SDL_SCANCODE_ALTERASE = 153,
 2328    SDL_SCANCODE_SYSREQ = 154,
 2329    SDL_SCANCODE_CANCEL = 155,
 2330    SDL_SCANCODE_CLEAR = 156,
 2331    SDL_SCANCODE_PRIOR = 157,
 2332    SDL_SCANCODE_RETURN2 = 158,
 2333    SDL_SCANCODE_SEPARATOR = 159,
 2334    SDL_SCANCODE_OUT = 160,
 2335    SDL_SCANCODE_OPER = 161,
 2336    SDL_SCANCODE_CLEARAGAIN = 162,
 2337    SDL_SCANCODE_CRSEL = 163,
 2338    SDL_SCANCODE_EXSEL = 164,
 2339
 2340    SDL_SCANCODE_KP_00 = 176,
 2341    SDL_SCANCODE_KP_000 = 177,
 2342    SDL_SCANCODE_THOUSANDSSEPARATOR = 178,
 2343    SDL_SCANCODE_DECIMALSEPARATOR = 179,
 2344    SDL_SCANCODE_CURRENCYUNIT = 180,
 2345    SDL_SCANCODE_CURRENCYSUBUNIT = 181,
 2346    SDL_SCANCODE_KP_LEFTPAREN = 182,
 2347    SDL_SCANCODE_KP_RIGHTPAREN = 183,
 2348    SDL_SCANCODE_KP_LEFTBRACE = 184,
 2349    SDL_SCANCODE_KP_RIGHTBRACE = 185,
 2350    SDL_SCANCODE_KP_TAB = 186,
 2351    SDL_SCANCODE_KP_BACKSPACE = 187,
 2352    SDL_SCANCODE_KP_A = 188,
 2353    SDL_SCANCODE_KP_B = 189,
 2354    SDL_SCANCODE_KP_C = 190,
 2355    SDL_SCANCODE_KP_D = 191,
 2356    SDL_SCANCODE_KP_E = 192,
 2357    SDL_SCANCODE_KP_F = 193,
 2358    SDL_SCANCODE_KP_XOR = 194,
 2359    SDL_SCANCODE_KP_POWER = 195,
 2360    SDL_SCANCODE_KP_PERCENT = 196,
 2361    SDL_SCANCODE_KP_LESS = 197,
 2362    SDL_SCANCODE_KP_GREATER = 198,
 2363    SDL_SCANCODE_KP_AMPERSAND = 199,
 2364    SDL_SCANCODE_KP_DBLAMPERSAND = 200,
 2365    SDL_SCANCODE_KP_VERTICALBAR = 201,
 2366    SDL_SCANCODE_KP_DBLVERTICALBAR = 202,
 2367    SDL_SCANCODE_KP_COLON = 203,
 2368    SDL_SCANCODE_KP_HASH = 204,
 2369    SDL_SCANCODE_KP_SPACE = 205,
 2370    SDL_SCANCODE_KP_AT = 206,
 2371    SDL_SCANCODE_KP_EXCLAM = 207,
 2372    SDL_SCANCODE_KP_MEMSTORE = 208,
 2373    SDL_SCANCODE_KP_MEMRECALL = 209,
 2374    SDL_SCANCODE_KP_MEMCLEAR = 210,
 2375    SDL_SCANCODE_KP_MEMADD = 211,
 2376    SDL_SCANCODE_KP_MEMSUBTRACT = 212,
 2377    SDL_SCANCODE_KP_MEMMULTIPLY = 213,
 2378    SDL_SCANCODE_KP_MEMDIVIDE = 214,
 2379    SDL_SCANCODE_KP_PLUSMINUS = 215,
 2380    SDL_SCANCODE_KP_CLEAR = 216,
 2381    SDL_SCANCODE_KP_CLEARENTRY = 217,
 2382    SDL_SCANCODE_KP_BINARY = 218,
 2383    SDL_SCANCODE_KP_OCTAL = 219,
 2384    SDL_SCANCODE_KP_DECIMAL = 220,
 2385    SDL_SCANCODE_KP_HEXADECIMAL = 221,
 2386
 2387    SDL_SCANCODE_LCTRL = 224,
 2388    SDL_SCANCODE_LSHIFT = 225,
 2389    SDL_SCANCODE_LALT = 226,
 2390    SDL_SCANCODE_LGUI = 227,
 2391    SDL_SCANCODE_RCTRL = 228,
 2392    SDL_SCANCODE_RSHIFT = 229,
 2393    SDL_SCANCODE_RALT = 230,
 2394    SDL_SCANCODE_RGUI = 231,
 2395
 2396    SDL_SCANCODE_MODE = 257,
 2397
 2398    SDL_SCANCODE_AUDIONEXT = 258,
 2399    SDL_SCANCODE_AUDIOPREV = 259,
 2400    SDL_SCANCODE_AUDIOSTOP = 260,
 2401    SDL_SCANCODE_AUDIOPLAY = 261,
 2402    SDL_SCANCODE_AUDIOMUTE = 262,
 2403    SDL_SCANCODE_MEDIASELECT = 263,
 2404    SDL_SCANCODE_WWW = 264,
 2405    SDL_SCANCODE_MAIL = 265,
 2406    SDL_SCANCODE_CALCULATOR = 266,
 2407    SDL_SCANCODE_COMPUTER = 267,
 2408    SDL_SCANCODE_AC_SEARCH = 268,
 2409    SDL_SCANCODE_AC_HOME = 269,
 2410    SDL_SCANCODE_AC_BACK = 270,
 2411    SDL_SCANCODE_AC_FORWARD = 271,
 2412    SDL_SCANCODE_AC_STOP = 272,
 2413    SDL_SCANCODE_AC_REFRESH = 273,
 2414    SDL_SCANCODE_AC_BOOKMARKS = 274,
 2415
 2416    SDL_SCANCODE_BRIGHTNESSDOWN = 275,
 2417    SDL_SCANCODE_BRIGHTNESSUP = 276,
 2418    SDL_SCANCODE_DISPLAYSWITCH = 277,
 2419    SDL_SCANCODE_KBDILLUMTOGGLE = 278,
 2420    SDL_SCANCODE_KBDILLUMDOWN = 279,
 2421    SDL_SCANCODE_KBDILLUMUP = 280,
 2422    SDL_SCANCODE_EJECT = 281,
 2423    SDL_SCANCODE_SLEEP = 282,
 2424
 2425    SDL_SCANCODE_APP1 = 283,
 2426    SDL_SCANCODE_APP2 = 284,
 2427
 2428    SDL_NUM_SCANCODES = 512
 2429} SDL_Scancode;
 2430
 2431#endif
 2432
 2433typedef Sint32 SDL_Keycode;
 2434
 2435#define SDLK_SCANCODE_MASK (1<<30)
 2436#define SDL_SCANCODE_TO_KEYCODE(X)  (X | SDLK_SCANCODE_MASK)
 2437
 2438enum
 2439{
 2440    SDLK_UNKNOWN = 0,
 2441
 2442    SDLK_RETURN = '\r',
 2443    SDLK_ESCAPE = '\033',
 2444    SDLK_BACKSPACE = '\b',
 2445    SDLK_TAB = '\t',
 2446    SDLK_SPACE = ' ',
 2447    SDLK_EXCLAIM = '!',
 2448    SDLK_QUOTEDBL = '"',
 2449    SDLK_HASH = '#',
 2450    SDLK_PERCENT = '%',
 2451    SDLK_DOLLAR = '$',
 2452    SDLK_AMPERSAND = '&',
 2453    SDLK_QUOTE = '\'',
 2454    SDLK_LEFTPAREN = '(',
 2455    SDLK_RIGHTPAREN = ')',
 2456    SDLK_ASTERISK = '*',
 2457    SDLK_PLUS = '+',
 2458    SDLK_COMMA = ',',
 2459    SDLK_MINUS = '-',
 2460    SDLK_PERIOD = '.',
 2461    SDLK_SLASH = '/',
 2462    SDLK_0 = '0',
 2463    SDLK_1 = '1',
 2464    SDLK_2 = '2',
 2465    SDLK_3 = '3',
 2466    SDLK_4 = '4',
 2467    SDLK_5 = '5',
 2468    SDLK_6 = '6',
 2469    SDLK_7 = '7',
 2470    SDLK_8 = '8',
 2471    SDLK_9 = '9',
 2472    SDLK_COLON = ':',
 2473    SDLK_SEMICOLON = ';',
 2474    SDLK_LESS = '<',
 2475    SDLK_EQUALS = '=',
 2476    SDLK_GREATER = '>',
 2477    SDLK_QUESTION = '?',
 2478    SDLK_AT = '@',
 2479
 2480    SDLK_LEFTBRACKET = '[',
 2481    SDLK_BACKSLASH = '\\',
 2482    SDLK_RIGHTBRACKET = ']',
 2483    SDLK_CARET = '^',
 2484    SDLK_UNDERSCORE = '_',
 2485    SDLK_BACKQUOTE = '`',
 2486    SDLK_a = 'a',
 2487    SDLK_b = 'b',
 2488    SDLK_c = 'c',
 2489    SDLK_d = 'd',
 2490    SDLK_e = 'e',
 2491    SDLK_f = 'f',
 2492    SDLK_g = 'g',
 2493    SDLK_h = 'h',
 2494    SDLK_i = 'i',
 2495    SDLK_j = 'j',
 2496    SDLK_k = 'k',
 2497    SDLK_l = 'l',
 2498    SDLK_m = 'm',
 2499    SDLK_n = 'n',
 2500    SDLK_o = 'o',
 2501    SDLK_p = 'p',
 2502    SDLK_q = 'q',
 2503    SDLK_r = 'r',
 2504    SDLK_s = 's',
 2505    SDLK_t = 't',
 2506    SDLK_u = 'u',
 2507    SDLK_v = 'v',
 2508    SDLK_w = 'w',
 2509    SDLK_x = 'x',
 2510    SDLK_y = 'y',
 2511    SDLK_z = 'z',
 2512
 2513    SDLK_CAPSLOCK = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CAPSLOCK),
 2514
 2515    SDLK_F1 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F1),
 2516    SDLK_F2 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F2),
 2517    SDLK_F3 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F3),
 2518    SDLK_F4 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F4),
 2519    SDLK_F5 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F5),
 2520    SDLK_F6 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F6),
 2521    SDLK_F7 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F7),
 2522    SDLK_F8 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F8),
 2523    SDLK_F9 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F9),
 2524    SDLK_F10 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F10),
 2525    SDLK_F11 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F11),
 2526    SDLK_F12 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F12),
 2527
 2528    SDLK_PRINTSCREEN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PRINTSCREEN),
 2529    SDLK_SCROLLLOCK = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SCROLLLOCK),
 2530    SDLK_PAUSE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PAUSE),
 2531    SDLK_INSERT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INSERT),
 2532    SDLK_HOME = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_HOME),
 2533    SDLK_PAGEUP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PAGEUP),
 2534    SDLK_DELETE = '\177',
 2535    SDLK_END = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_END),
 2536    SDLK_PAGEDOWN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PAGEDOWN),
 2537    SDLK_RIGHT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RIGHT),
 2538    SDLK_LEFT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LEFT),
 2539    SDLK_DOWN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_DOWN),
 2540    SDLK_UP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_UP),
 2541
 2542    SDLK_NUMLOCKCLEAR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_NUMLOCKCLEAR),
 2543    SDLK_KP_DIVIDE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DIVIDE),
 2544    SDLK_KP_MULTIPLY = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MULTIPLY),
 2545    SDLK_KP_MINUS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MINUS),
 2546    SDLK_KP_PLUS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PLUS),
 2547    SDLK_KP_ENTER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_ENTER),
 2548    SDLK_KP_1 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_1),
 2549    SDLK_KP_2 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_2),
 2550    SDLK_KP_3 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_3),
 2551    SDLK_KP_4 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_4),
 2552    SDLK_KP_5 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_5),
 2553    SDLK_KP_6 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_6),
 2554    SDLK_KP_7 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_7),
 2555    SDLK_KP_8 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_8),
 2556    SDLK_KP_9 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_9),
 2557    SDLK_KP_0 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_0),
 2558    SDLK_KP_PERIOD = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PERIOD),
 2559
 2560    SDLK_APPLICATION = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_APPLICATION),
 2561    SDLK_POWER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_POWER),
 2562    SDLK_KP_EQUALS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_EQUALS),
 2563    SDLK_F13 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F13),
 2564    SDLK_F14 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F14),
 2565    SDLK_F15 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F15),
 2566    SDLK_F16 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F16),
 2567    SDLK_F17 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F17),
 2568    SDLK_F18 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F18),
 2569    SDLK_F19 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F19),
 2570    SDLK_F20 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F20),
 2571    SDLK_F21 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F21),
 2572    SDLK_F22 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F22),
 2573    SDLK_F23 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F23),
 2574    SDLK_F24 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F24),
 2575    SDLK_EXECUTE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_EXECUTE),
 2576    SDLK_HELP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_HELP),
 2577    SDLK_MENU = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MENU),
 2578    SDLK_SELECT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SELECT),
 2579    SDLK_STOP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_STOP),
 2580    SDLK_AGAIN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AGAIN),
 2581    SDLK_UNDO = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_UNDO),
 2582    SDLK_CUT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CUT),
 2583    SDLK_COPY = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_COPY),
 2584    SDLK_PASTE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PASTE),
 2585    SDLK_FIND = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_FIND),
 2586    SDLK_MUTE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MUTE),
 2587    SDLK_VOLUMEUP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_VOLUMEUP),
 2588    SDLK_VOLUMEDOWN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_VOLUMEDOWN),
 2589    SDLK_KP_COMMA = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_COMMA),
 2590    SDLK_KP_EQUALSAS400 =
 2591        SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_EQUALSAS400),
 2592
 2593    SDLK_ALTERASE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_ALTERASE),
 2594    SDLK_SYSREQ = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SYSREQ),
 2595    SDLK_CANCEL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CANCEL),
 2596    SDLK_CLEAR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CLEAR),
 2597    SDLK_PRIOR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PRIOR),
 2598    SDLK_RETURN2 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RETURN2),
 2599    SDLK_SEPARATOR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SEPARATOR),
 2600    SDLK_OUT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_OUT),
 2601    SDLK_OPER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_OPER),
 2602    SDLK_CLEARAGAIN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CLEARAGAIN),
 2603    SDLK_CRSEL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CRSEL),
 2604    SDLK_EXSEL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_EXSEL),
 2605
 2606    SDLK_KP_00 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_00),
 2607    SDLK_KP_000 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_000),
 2608    SDLK_THOUSANDSSEPARATOR =
 2609        SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_THOUSANDSSEPARATOR),
 2610    SDLK_DECIMALSEPARATOR =
 2611        SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_DECIMALSEPARATOR),
 2612    SDLK_CURRENCYUNIT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CURRENCYUNIT),
 2613    SDLK_CURRENCYSUBUNIT =
 2614        SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CURRENCYSUBUNIT),
 2615    SDLK_KP_LEFTPAREN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_LEFTPAREN),
 2616    SDLK_KP_RIGHTPAREN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_RIGHTPAREN),
 2617    SDLK_KP_LEFTBRACE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_LEFTBRACE),
 2618    SDLK_KP_RIGHTBRACE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_RIGHTBRACE),
 2619    SDLK_KP_TAB = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_TAB),
 2620    SDLK_KP_BACKSPACE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_BACKSPACE),
 2621    SDLK_KP_A = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_A),
 2622    SDLK_KP_B = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_B),
 2623    SDLK_KP_C = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_C),
 2624    SDLK_KP_D = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_D),
 2625    SDLK_KP_E = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_E),
 2626    SDLK_KP_F = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_F),
 2627    SDLK_KP_XOR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_XOR),
 2628    SDLK_KP_POWER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_POWER),
 2629    SDLK_KP_PERCENT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PERCENT),
 2630    SDLK_KP_LESS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_LESS),
 2631    SDLK_KP_GREATER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_GREATER),
 2632    SDLK_KP_AMPERSAND = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_AMPERSAND),
 2633    SDLK_KP_DBLAMPERSAND =
 2634        SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DBLAMPERSAND),
 2635    SDLK_KP_VERTICALBAR =
 2636        SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_VERTICALBAR),
 2637    SDLK_KP_DBLVERTICALBAR =
 2638        SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DBLVERTICALBAR),
 2639    SDLK_KP_COLON = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_COLON),
 2640    SDLK_KP_HASH = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_HASH),
 2641    SDLK_KP_SPACE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_SPACE),
 2642    SDLK_KP_AT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_AT),
 2643    SDLK_KP_EXCLAM = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_EXCLAM),
 2644    SDLK_KP_MEMSTORE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMSTORE),
 2645    SDLK_KP_MEMRECALL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMRECALL),
 2646    SDLK_KP_MEMCLEAR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMCLEAR),
 2647    SDLK_KP_MEMADD = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMADD),
 2648    SDLK_KP_MEMSUBTRACT =
 2649        SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMSUBTRACT),
 2650    SDLK_KP_MEMMULTIPLY =
 2651        SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMMULTIPLY),
 2652    SDLK_KP_MEMDIVIDE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMDIVIDE),
 2653    SDLK_KP_PLUSMINUS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PLUSMINUS),
 2654    SDLK_KP_CLEAR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_CLEAR),
 2655    SDLK_KP_CLEARENTRY = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_CLEARENTRY),
 2656    SDLK_KP_BINARY = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_BINARY),
 2657    SDLK_KP_OCTAL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_OCTAL),
 2658    SDLK_KP_DECIMAL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DECIMAL),
 2659    SDLK_KP_HEXADECIMAL =
 2660        SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_HEXADECIMAL),
 2661
 2662    SDLK_LCTRL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LCTRL),
 2663    SDLK_LSHIFT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LSHIFT),
 2664    SDLK_LALT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LALT),
 2665    SDLK_LGUI = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LGUI),
 2666    SDLK_RCTRL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RCTRL),
 2667    SDLK_RSHIFT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RSHIFT),
 2668    SDLK_RALT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RALT),
 2669    SDLK_RGUI = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RGUI),
 2670
 2671    SDLK_MODE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MODE),
 2672
 2673    SDLK_AUDIONEXT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIONEXT),
 2674    SDLK_AUDIOPREV = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIOPREV),
 2675    SDLK_AUDIOSTOP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIOSTOP),
 2676    SDLK_AUDIOPLAY = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIOPLAY),
 2677    SDLK_AUDIOMUTE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIOMUTE),
 2678    SDLK_MEDIASELECT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIASELECT),
 2679    SDLK_WWW = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_WWW),
 2680    SDLK_MAIL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MAIL),
 2681    SDLK_CALCULATOR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CALCULATOR),
 2682    SDLK_COMPUTER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_COMPUTER),
 2683    SDLK_AC_SEARCH = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_SEARCH),
 2684    SDLK_AC_HOME = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_HOME),
 2685    SDLK_AC_BACK = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_BACK),
 2686    SDLK_AC_FORWARD = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_FORWARD),
 2687    SDLK_AC_STOP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_STOP),
 2688    SDLK_AC_REFRESH = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_REFRESH),
 2689    SDLK_AC_BOOKMARKS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_BOOKMARKS),
 2690
 2691    SDLK_BRIGHTNESSDOWN =
 2692        SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_BRIGHTNESSDOWN),
 2693    SDLK_BRIGHTNESSUP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_BRIGHTNESSUP),
 2694    SDLK_DISPLAYSWITCH = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_DISPLAYSWITCH),
 2695    SDLK_KBDILLUMTOGGLE =
 2696        SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KBDILLUMTOGGLE),
 2697    SDLK_KBDILLUMDOWN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KBDILLUMDOWN),
 2698    SDLK_KBDILLUMUP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KBDILLUMUP),
 2699    SDLK_EJECT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_EJECT),
 2700    SDLK_SLEEP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SLEEP)
 2701};
 2702
 2703typedef enum
 2704{
 2705    KMOD_NONE = 0x0000,
 2706    KMOD_LSHIFT = 0x0001,
 2707    KMOD_RSHIFT = 0x0002,
 2708    KMOD_LCTRL = 0x0040,
 2709    KMOD_RCTRL = 0x0080,
 2710    KMOD_LALT = 0x0100,
 2711    KMOD_RALT = 0x0200,
 2712    KMOD_LGUI = 0x0400,
 2713    KMOD_RGUI = 0x0800,
 2714    KMOD_NUM = 0x1000,
 2715    KMOD_CAPS = 0x2000,
 2716    KMOD_MODE = 0x4000,
 2717    KMOD_RESERVED = 0x8000
 2718} SDL_Keymod;
 2719
 2720#define KMOD_CTRL   (KMOD_LCTRL|KMOD_RCTRL)
 2721#define KMOD_SHIFT  (KMOD_LSHIFT|KMOD_RSHIFT)
 2722#define KMOD_ALT    (KMOD_LALT|KMOD_RALT)
 2723#define KMOD_GUI    (KMOD_LGUI|KMOD_RGUI)
 2724
 2725#endif
 2726
 2727#ifdef _begin_code_h
 2728#error Nested inclusion of begin_code.h
 2729#endif
 2730#define _begin_code_h
 2731
 2732#ifndef SDL_DEPRECATED
 2733#  if (__GNUC__ >= 4)
 2734#    define SDL_DEPRECATED __attribute__((deprecated))
 2735#  else
 2736#    define SDL_DEPRECATED
 2737#  endif
 2738#endif
 2739
 2740#ifndef DECLSPEC
 2741# if defined(__WIN32__) || defined(__WINRT__)
 2742#  ifdef __BORLANDC__
 2743#   ifdef BUILD_SDL
 2744#    define DECLSPEC
 2745#   else
 2746#    define DECLSPEC    __declspec(dllimport)
 2747#   endif
 2748#  else
 2749#   define DECLSPEC __declspec(dllexport)
 2750#  endif
 2751# else
 2752#  if defined(__GNUC__) && __GNUC__ >= 4
 2753#   define DECLSPEC __attribute__ ((visibility("default")))
 2754#  elif defined(__GNUC__) && __GNUC__ >= 2
 2755#   define DECLSPEC __declspec(dllexport)
 2756#  else
 2757#   define DECLSPEC
 2758#  endif
 2759# endif
 2760#endif
 2761
 2762#ifndef SDLCALL
 2763#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
 2764#define SDLCALL __cdecl
 2765#else
 2766#define SDLCALL
 2767#endif
 2768#endif
 2769
 2770#ifdef __SYMBIAN32__
 2771#undef DECLSPEC
 2772#define DECLSPEC
 2773#endif
 2774
 2775#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
 2776#ifdef _MSC_VER
 2777#pragma warning(disable: 4103)
 2778#endif
 2779#ifdef __BORLANDC__
 2780#pragma nopackwarning
 2781#endif
 2782#ifdef _M_X64
 2783
 2784#pragma pack(push,8)
 2785#else
 2786#pragma pack(push,4)
 2787#endif
 2788#endif
 2789
 2790#ifndef SDL_INLINE
 2791#if defined(__GNUC__)
 2792#define SDL_INLINE __inline__
 2793#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
 2794      defined(__DMC__) || defined(__SC__) || \
 2795      defined(__WATCOMC__) || defined(__LCC__) || \
 2796      defined(__DECC)
 2797#define SDL_INLINE __inline
 2798#ifndef __inline__
 2799#define __inline__ __inline
 2800#endif
 2801#else
 2802#define SDL_INLINE inline
 2803#ifndef __inline__
 2804#define __inline__ inline
 2805#endif
 2806#endif
 2807#endif
 2808
 2809#ifndef SDL_FORCE_INLINE
 2810#if defined(_MSC_VER)
 2811#define SDL_FORCE_INLINE __forceinline
 2812#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
 2813#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
 2814#else
 2815#define SDL_FORCE_INLINE static SDL_INLINE
 2816#endif
 2817#endif
 2818
 2819#if !defined(__MACH__)
 2820#ifndef NULL
 2821#ifdef __cplusplus
 2822#define NULL 0
 2823#else
 2824#define NULL ((void *)0)
 2825#endif
 2826#endif
 2827#endif
 2828
 2829#ifdef __cplusplus
 2830extern "C" {
 2831#endif
 2832
 2833typedef struct SDL_Keysym
 2834{
 2835    SDL_Scancode scancode;
 2836    SDL_Keycode sym;
 2837    Uint16 mod;
 2838    Uint32 unused;
 2839} SDL_Keysym;
 2840
 2841extern DECLSPEC SDL_Window * SDLCALL SDL_GetKeyboardFocus(void);
 2842
 2843extern DECLSPEC const Uint8 *SDLCALL SDL_GetKeyboardState(int *numkeys);
 2844
 2845extern DECLSPEC SDL_Keymod SDLCALL SDL_GetModState(void);
 2846
 2847extern DECLSPEC void SDLCALL SDL_SetModState(SDL_Keymod modstate);
 2848
 2849extern DECLSPEC SDL_Keycode SDLCALL SDL_GetKeyFromScancode(SDL_Scancode scancode);
 2850
 2851extern DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromKey(SDL_Keycode key);
 2852
 2853extern DECLSPEC const char *SDLCALL SDL_GetScancodeName(SDL_Scancode scancode);
 2854
 2855extern DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromName(const char *name);
 2856
 2857extern DECLSPEC const char *SDLCALL SDL_GetKeyName(SDL_Keycode key);
 2858
 2859extern DECLSPEC SDL_Keycode SDLCALL SDL_GetKeyFromName(const char *name);
 2860
 2861extern DECLSPEC void SDLCALL SDL_StartTextInput(void);
 2862
 2863extern DECLSPEC SDL_bool SDLCALL SDL_IsTextInputActive(void);
 2864
 2865extern DECLSPEC void SDLCALL SDL_StopTextInput(void);
 2866
 2867extern DECLSPEC void SDLCALL SDL_SetTextInputRect(SDL_Rect *rect);
 2868
 2869extern DECLSPEC SDL_bool SDLCALL SDL_HasScreenKeyboardSupport(void);
 2870
 2871extern DECLSPEC SDL_bool SDLCALL SDL_IsScreenKeyboardShown(SDL_Window *window);
 2872
 2873#ifdef __cplusplus
 2874}
 2875#endif
 2876#undef _begin_code_h
 2877
 2878#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__WATCOMC__)  || defined(__BORLANDC__)
 2879#ifdef __BORLANDC__
 2880#pragma nopackwarning
 2881#endif
 2882#pragma pack(pop)
 2883#endif
 2884
 2885#endif
 2886#ifndef _SDL_mouse_h
 2887#define _SDL_mouse_h
 2888
 2889#ifdef _begin_code_h
 2890#error Nested inclusion of begin_code.h
 2891#endif
 2892#define _begin_code_h
 2893
 2894#ifndef SDL_DEPRECATED
 2895#  if (__GNUC__ >= 4)
 2896#    define SDL_DEPRECATED __attribute__((deprecated))
 2897#  else
 2898#    define SDL_DEPRECATED
 2899#  endif
 2900#endif
 2901
 2902#ifndef DECLSPEC
 2903# if defined(__WIN32__) || defined(__WINRT__)
 2904#  ifdef __BORLANDC__
 2905#   ifdef BUILD_SDL
 2906#    define DECLSPEC
 2907#   else
 2908#    define DECLSPEC    __declspec(dllimport)
 2909#   endif
 2910#  else
 2911#   define DECLSPEC __declspec(dllexport)
 2912#  endif
 2913# else
 2914#  if defined(__GNUC__) && __GNUC__ >= 4
 2915#   define DECLSPEC __attribute__ ((visibility("default")))
 2916#  elif defined(__GNUC__) && __GNUC__ >= 2
 2917#   define DECLSPEC __declspec(dllexport)
 2918#  else
 2919#   define DECLSPEC
 2920#  endif
 2921# endif
 2922#endif
 2923
 2924#ifndef SDLCALL
 2925#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
 2926#define SDLCALL __cdecl
 2927#else
 2928#define SDLCALL
 2929#endif
 2930#endif
 2931
 2932#ifdef __SYMBIAN32__
 2933#undef DECLSPEC
 2934#define DECLSPEC
 2935#endif
 2936
 2937#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
 2938#ifdef _MSC_VER
 2939#pragma warning(disable: 4103)
 2940#endif
 2941#ifdef __BORLANDC__
 2942#pragma nopackwarning
 2943#endif
 2944#ifdef _M_X64
 2945
 2946#pragma pack(push,8)
 2947#else
 2948#pragma pack(push,4)
 2949#endif
 2950#endif
 2951
 2952#ifndef SDL_INLINE
 2953#if defined(__GNUC__)
 2954#define SDL_INLINE __inline__
 2955#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
 2956      defined(__DMC__) || defined(__SC__) || \
 2957      defined(__WATCOMC__) || defined(__LCC__) || \
 2958      defined(__DECC)
 2959#define SDL_INLINE __inline
 2960#ifndef __inline__
 2961#define __inline__ __inline
 2962#endif
 2963#else
 2964#define SDL_INLINE inline
 2965#ifndef __inline__
 2966#define __inline__ inline
 2967#endif
 2968#endif
 2969#endif
 2970
 2971#ifndef SDL_FORCE_INLINE
 2972#if defined(_MSC_VER)
 2973#define SDL_FORCE_INLINE __forceinline
 2974#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
 2975#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
 2976#else
 2977#define SDL_FORCE_INLINE static SDL_INLINE
 2978#endif
 2979#endif
 2980
 2981#if !defined(__MACH__)
 2982#ifndef NULL
 2983#ifdef __cplusplus
 2984#define NULL 0
 2985#else
 2986#define NULL ((void *)0)
 2987#endif
 2988#endif
 2989#endif
 2990
 2991#ifdef __cplusplus
 2992extern "C" {
 2993#endif
 2994
 2995typedef struct SDL_Cursor SDL_Cursor;
 2996
 2997typedef enum
 2998{
 2999    SDL_SYSTEM_CURSOR_ARROW,
 3000    SDL_SYSTEM_CURSOR_IBEAM,
 3001    SDL_SYSTEM_CURSOR_WAIT,
 3002    SDL_SYSTEM_CURSOR_CROSSHAIR,
 3003    SDL_SYSTEM_CURSOR_WAITARROW,
 3004    SDL_SYSTEM_CURSOR_SIZENWSE,
 3005    SDL_SYSTEM_CURSOR_SIZENESW,
 3006    SDL_SYSTEM_CURSOR_SIZEWE,
 3007    SDL_SYSTEM_CURSOR_SIZENS,
 3008    SDL_SYSTEM_CURSOR_SIZEALL,
 3009    SDL_SYSTEM_CURSOR_NO,
 3010    SDL_SYSTEM_CURSOR_HAND,
 3011    SDL_NUM_SYSTEM_CURSORS
 3012} SDL_SystemCursor;
 3013
 3014extern DECLSPEC SDL_Window * SDLCALL SDL_GetMouseFocus(void);
 3015
 3016extern DECLSPEC Uint32 SDLCALL SDL_GetMouseState(int *x, int *y);
 3017
 3018extern DECLSPEC Uint32 SDLCALL SDL_GetRelativeMouseState(int *x, int *y);
 3019
 3020extern DECLSPEC void SDLCALL SDL_WarpMouseInWindow(SDL_Window * window,
 3021                                                   int x, int y);
 3022
 3023extern DECLSPEC int SDLCALL SDL_SetRelativeMouseMode(SDL_bool enabled);
 3024
 3025extern DECLSPEC SDL_bool SDLCALL SDL_GetRelativeMouseMode(void);
 3026
 3027extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateCursor(const Uint8 * data,
 3028                                                     const Uint8 * mask,
 3029                                                     int w, int h, int hot_x,
 3030                                                     int hot_y);
 3031
 3032extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateColorCursor(SDL_Surface *surface,
 3033                                                          int hot_x,
 3034                                                          int hot_y);
 3035
 3036extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateSystemCursor(SDL_SystemCursor id);
 3037
 3038extern DECLSPEC void SDLCALL SDL_SetCursor(SDL_Cursor * cursor);
 3039
 3040extern DECLSPEC SDL_Cursor *SDLCALL SDL_GetCursor(void);
 3041
 3042extern DECLSPEC SDL_Cursor *SDLCALL SDL_GetDefaultCursor(void);
 3043
 3044extern DECLSPEC void SDLCALL SDL_FreeCursor(SDL_Cursor * cursor);
 3045
 3046extern DECLSPEC int SDLCALL SDL_ShowCursor(int toggle);
 3047
 3048#define SDL_BUTTON(X)       (1 << ((X)-1))
 3049#define SDL_BUTTON_LEFT     1
 3050#define SDL_BUTTON_MIDDLE   2
 3051#define SDL_BUTTON_RIGHT    3
 3052#define SDL_BUTTON_X1       4
 3053#define SDL_BUTTON_X2       5
 3054#define SDL_BUTTON_LMASK    SDL_BUTTON(SDL_BUTTON_LEFT)
 3055#define SDL_BUTTON_MMASK    SDL_BUTTON(SDL_BUTTON_MIDDLE)
 3056#define SDL_BUTTON_RMASK    SDL_BUTTON(SDL_BUTTON_RIGHT)
 3057#define SDL_BUTTON_X1MASK   SDL_BUTTON(SDL_BUTTON_X1)
 3058#define SDL_BUTTON_X2MASK   SDL_BUTTON(SDL_BUTTON_X2)
 3059
 3060#ifdef __cplusplus
 3061}
 3062#endif
 3063#undef _begin_code_h
 3064
 3065#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__WATCOMC__)  || defined(__BORLANDC__)
 3066#ifdef __BORLANDC__
 3067#pragma nopackwarning
 3068#endif
 3069#pragma pack(pop)
 3070#endif
 3071
 3072#endif
 3073#ifndef _SDL_joystick_h
 3074#define _SDL_joystick_h
 3075
 3076#ifdef _begin_code_h
 3077#error Nested inclusion of begin_code.h
 3078#endif
 3079#define _begin_code_h
 3080
 3081#ifndef SDL_DEPRECATED
 3082#  if (__GNUC__ >= 4)
 3083#    define SDL_DEPRECATED __attribute__((deprecated))
 3084#  else
 3085#    define SDL_DEPRECATED
 3086#  endif
 3087#endif
 3088
 3089#ifndef DECLSPEC
 3090# if defined(__WIN32__) || defined(__WINRT__)
 3091#  ifdef __BORLANDC__
 3092#   ifdef BUILD_SDL
 3093#    define DECLSPEC
 3094#   else
 3095#    define DECLSPEC    __declspec(dllimport)
 3096#   endif
 3097#  else
 3098#   define DECLSPEC __declspec(dllexport)
 3099#  endif
 3100# else
 3101#  if defined(__GNUC__) && __GNUC__ >= 4
 3102#   define DECLSPEC __attribute__ ((visibility("default")))
 3103#  elif defined(__GNUC__) && __GNUC__ >= 2
 3104#   define DECLSPEC __declspec(dllexport)
 3105#  else
 3106#   define DECLSPEC
 3107#  endif
 3108# endif
 3109#endif
 3110
 3111#ifndef SDLCALL
 3112#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
 3113#define SDLCALL __cdecl
 3114#else
 3115#define SDLCALL
 3116#endif
 3117#endif
 3118
 3119#ifdef __SYMBIAN32__
 3120#undef DECLSPEC
 3121#define DECLSPEC
 3122#endif
 3123
 3124#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
 3125#ifdef _MSC_VER
 3126#pragma warning(disable: 4103)
 3127#endif
 3128#ifdef __BORLANDC__
 3129#pragma nopackwarning
 3130#endif
 3131#ifdef _M_X64
 3132
 3133#pragma pack(push,8)
 3134#else
 3135#pragma pack(push,4)
 3136#endif
 3137#endif
 3138
 3139#ifndef SDL_INLINE
 3140#if defined(__GNUC__)
 3141#define SDL_INLINE __inline__
 3142#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
 3143      defined(__DMC__) || defined(__SC__) || \
 3144      defined(__WATCOMC__) || defined(__LCC__) || \
 3145      defined(__DECC)
 3146#define SDL_INLINE __inline
 3147#ifndef __inline__
 3148#define __inline__ __inline
 3149#endif
 3150#else
 3151#define SDL_INLINE inline
 3152#ifndef __inline__
 3153#define __inline__ inline
 3154#endif
 3155#endif
 3156#endif
 3157
 3158#ifndef SDL_FORCE_INLINE
 3159#if defined(_MSC_VER)
 3160#define SDL_FORCE_INLINE __forceinline
 3161#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
 3162#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
 3163#else
 3164#define SDL_FORCE_INLINE static SDL_INLINE
 3165#endif
 3166#endif
 3167
 3168#if !defined(__MACH__)
 3169#ifndef NULL
 3170#ifdef __cplusplus
 3171#define NULL 0
 3172#else
 3173#define NULL ((void *)0)
 3174#endif
 3175#endif
 3176#endif
 3177
 3178#ifdef __cplusplus
 3179extern "C" {
 3180#endif
 3181
 3182struct _SDL_Joystick;
 3183typedef struct _SDL_Joystick SDL_Joystick;
 3184
 3185typedef struct {
 3186    Uint8 data[16];
 3187} SDL_JoystickGUID;
 3188
 3189typedef Sint32 SDL_JoystickID;
 3190
 3191extern DECLSPEC int SDLCALL SDL_NumJoysticks(void);
 3192
 3193extern DECLSPEC const char *SDLCALL SDL_JoystickNameForIndex(int device_index);
 3194
 3195extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickOpen(int device_index);
 3196
 3197extern DECLSPEC const char *SDLCALL SDL_JoystickName(SDL_Joystick * joystick);
 3198
 3199extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetDeviceGUID(int device_index);
 3200
 3201extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUID(SDL_Joystick * joystick);
 3202
 3203extern DECLSPEC void SDLCALL SDL_JoystickGetGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID);
 3204
 3205extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUIDFromString(const char *pchGUID);
 3206
 3207extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAttached(SDL_Joystick * joystick);
 3208
 3209extern DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickInstanceID(SDL_Joystick * joystick);
 3210
 3211extern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick * joystick);
 3212
 3213extern DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick * joystick);
 3214
 3215extern DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick * joystick);
 3216
 3217extern DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick * joystick);
 3218
 3219extern DECLSPEC void SDLCALL SDL_JoystickUpdate(void);
 3220
 3221extern DECLSPEC int SDLCALL SDL_JoystickEventState(int state);
 3222
 3223extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick * joystick,
 3224                                                   int axis);
 3225
 3226#define SDL_HAT_CENTERED    0x00
 3227#define SDL_HAT_UP      0x01
 3228#define SDL_HAT_RIGHT       0x02
 3229#define SDL_HAT_DOWN        0x04
 3230#define SDL_HAT_LEFT        0x08
 3231#define SDL_HAT_RIGHTUP     (SDL_HAT_RIGHT|SDL_HAT_UP)
 3232#define SDL_HAT_RIGHTDOWN   (SDL_HAT_RIGHT|SDL_HAT_DOWN)
 3233#define SDL_HAT_LEFTUP      (SDL_HAT_LEFT|SDL_HAT_UP)
 3234#define SDL_HAT_LEFTDOWN    (SDL_HAT_LEFT|SDL_HAT_DOWN)
 3235
 3236extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick * joystick,
 3237                                                 int hat);
 3238
 3239extern DECLSPEC int SDLCALL SDL_JoystickGetBall(SDL_Joystick * joystick,
 3240                                                int ball, int *dx, int *dy);
 3241
 3242extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick * joystick,
 3243                                                    int button);
 3244
 3245extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick * joystick);
 3246
 3247#ifdef __cplusplus
 3248}
 3249#endif
 3250#undef _begin_code_h
 3251
 3252#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__WATCOMC__)  || defined(__BORLANDC__)
 3253#ifdef __BORLANDC__
 3254#pragma nopackwarning
 3255#endif
 3256#pragma pack(pop)
 3257#endif
 3258
 3259#endif
 3260#ifndef _SDL_gamecontroller_h
 3261#define _SDL_gamecontroller_h
 3262
 3263#ifdef _begin_code_h
 3264#error Nested inclusion of begin_code.h
 3265#endif
 3266#define _begin_code_h
 3267
 3268#ifndef SDL_DEPRECATED
 3269#  if (__GNUC__ >= 4)
 3270#    define SDL_DEPRECATED __attribute__((deprecated))
 3271#  else
 3272#    define SDL_DEPRECATED
 3273#  endif
 3274#endif
 3275
 3276#ifndef DECLSPEC
 3277# if defined(__WIN32__) || defined(__WINRT__)
 3278#  ifdef __BORLANDC__
 3279#   ifdef BUILD_SDL
 3280#    define DECLSPEC
 3281#   else
 3282#    define DECLSPEC    __declspec(dllimport)
 3283#   endif
 3284#  else
 3285#   define DECLSPEC __declspec(dllexport)
 3286#  endif
 3287# else
 3288#  if defined(__GNUC__) && __GNUC__ >= 4
 3289#   define DECLSPEC __attribute__ ((visibility("default")))
 3290#  elif defined(__GNUC__) && __GNUC__ >= 2
 3291#   define DECLSPEC __declspec(dllexport)
 3292#  else
 3293#   define DECLSPEC
 3294#  endif
 3295# endif
 3296#endif
 3297
 3298#ifndef SDLCALL
 3299#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
 3300#define SDLCALL __cdecl
 3301#else
 3302#define SDLCALL
 3303#endif
 3304#endif
 3305
 3306#ifdef __SYMBIAN32__
 3307#undef DECLSPEC
 3308#define DECLSPEC
 3309#endif
 3310
 3311#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
 3312#ifdef _MSC_VER
 3313#pragma warning(disable: 4103)
 3314#endif
 3315#ifdef __BORLANDC__
 3316#pragma nopackwarning
 3317#endif
 3318#ifdef _M_X64
 3319
 3320#pragma pack(push,8)
 3321#else
 3322#pragma pack(push,4)
 3323#endif
 3324#endif
 3325
 3326#ifndef SDL_INLINE
 3327#if defined(__GNUC__)
 3328#define SDL_INLINE __inline__
 3329#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
 3330      defined(__DMC__) || defined(__SC__) || \
 3331      defined(__WATCOMC__) || defined(__LCC__) || \
 3332      defined(__DECC)
 3333#define SDL_INLINE __inline
 3334#ifndef __inline__
 3335#define __inline__ __inline
 3336#endif
 3337#else
 3338#define SDL_INLINE inline
 3339#ifndef __inline__
 3340#define __inline__ inline
 3341#endif
 3342#endif
 3343#endif
 3344
 3345#ifndef SDL_FORCE_INLINE
 3346#if defined(_MSC_VER)
 3347#define SDL_FORCE_INLINE __forceinline
 3348#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
 3349#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
 3350#else
 3351#define SDL_FORCE_INLINE static SDL_INLINE
 3352#endif
 3353#endif
 3354
 3355#if !defined(__MACH__)
 3356#ifndef NULL
 3357#ifdef __cplusplus
 3358#define NULL 0
 3359#else
 3360#define NULL ((void *)0)
 3361#endif
 3362#endif
 3363#endif
 3364
 3365#ifdef __cplusplus
 3366extern "C" {
 3367#endif
 3368
 3369struct _SDL_GameController;
 3370typedef struct _SDL_GameController SDL_GameController;
 3371
 3372typedef enum
 3373{
 3374    SDL_CONTROLLER_BINDTYPE_NONE = 0,
 3375    SDL_CONTROLLER_BINDTYPE_BUTTON,
 3376    SDL_CONTROLLER_BINDTYPE_AXIS,
 3377    SDL_CONTROLLER_BINDTYPE_HAT
 3378} SDL_GameControllerBindType;
 3379
 3380typedef struct SDL_GameControllerButtonBind
 3381{
 3382    SDL_GameControllerBindType bindType;
 3383    union
 3384    {
 3385        int button;
 3386        int axis;
 3387        struct {
 3388            int hat;
 3389            int hat_mask;
 3390        } hat;
 3391    } value;
 3392
 3393} SDL_GameControllerButtonBind;
 3394
 3395extern DECLSPEC int SDLCALL SDL_GameControllerAddMappingsFromRW( SDL_RWops * rw, int freerw );
 3396
 3397#define SDL_GameControllerAddMappingsFromFile(file)   SDL_GameControllerAddMappingsFromRW(SDL_RWFromFile(file, "rb"), 1)
 3398
 3399extern DECLSPEC int SDLCALL SDL_GameControllerAddMapping( const char* mappingString );
 3400
 3401extern DECLSPEC char * SDLCALL SDL_GameControllerMappingForGUID( SDL_JoystickGUID guid );
 3402
 3403extern DECLSPEC char * SDLCALL SDL_GameControllerMapping( SDL_GameController * gamecontroller );
 3404
 3405extern DECLSPEC SDL_bool SDLCALL SDL_IsGameController(int joystick_index);
 3406
 3407extern DECLSPEC const char *SDLCALL SDL_GameControllerNameForIndex(int joystick_index);
 3408
 3409extern DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerOpen(int joystick_index);
 3410
 3411extern DECLSPEC const char *SDLCALL SDL_GameControllerName(SDL_GameController *gamecontroller);
 3412
 3413extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerGetAttached(SDL_GameController *gamecontroller);
 3414
 3415extern DECLSPEC SDL_Joystick *SDLCALL SDL_GameControllerGetJoystick(SDL_GameController *gamecontroller);
 3416
 3417extern DECLSPEC int SDLCALL SDL_GameControllerEventState(int state);
 3418
 3419extern DECLSPEC void SDLCALL SDL_GameControllerUpdate(void);
 3420
 3421typedef enum
 3422{
 3423    SDL_CONTROLLER_AXIS_INVALID = -1,
 3424    SDL_CONTROLLER_AXIS_LEFTX,
 3425    SDL_CONTROLLER_AXIS_LEFTY,
 3426    SDL_CONTROLLER_AXIS_RIGHTX,
 3427    SDL_CONTROLLER_AXIS_RIGHTY,
 3428    SDL_CONTROLLER_AXIS_TRIGGERLEFT,
 3429    SDL_CONTROLLER_AXIS_TRIGGERRIGHT,
 3430    SDL_CONTROLLER_AXIS_MAX
 3431} SDL_GameControllerAxis;
 3432
 3433extern DECLSPEC SDL_GameControllerAxis SDLCALL SDL_GameControllerGetAxisFromString(const char *pchString);
 3434
 3435extern DECLSPEC const char* SDLCALL SDL_GameControllerGetStringForAxis(SDL_GameControllerAxis axis);
 3436
 3437extern DECLSPEC SDL_GameControllerButtonBind SDLCALL
 3438SDL_GameControllerGetBindForAxis(SDL_GameController *gamecontroller,
 3439                                 SDL_GameControllerAxis axis);
 3440
 3441extern DECLSPEC Sint16 SDLCALL
 3442SDL_GameControllerGetAxis(SDL_GameController *gamecontroller,
 3443                          SDL_GameControllerAxis axis);
 3444
 3445typedef enum
 3446{
 3447    SDL_CONTROLLER_BUTTON_INVALID = -1,
 3448    SDL_CONTROLLER_BUTTON_A,
 3449    SDL_CONTROLLER_BUTTON_B,
 3450    SDL_CONTROLLER_BUTTON_X,
 3451    SDL_CONTROLLER_BUTTON_Y,
 3452    SDL_CONTROLLER_BUTTON_BACK,
 3453    SDL_CONTROLLER_BUTTON_GUIDE,
 3454    SDL_CONTROLLER_BUTTON_START,
 3455    SDL_CONTROLLER_BUTTON_LEFTSTICK,
 3456    SDL_CONTROLLER_BUTTON_RIGHTSTICK,
 3457    SDL_CONTROLLER_BUTTON_LEFTSHOULDER,
 3458    SDL_CONTROLLER_BUTTON_RIGHTSHOULDER,
 3459    SDL_CONTROLLER_BUTTON_DPAD_UP,
 3460    SDL_CONTROLLER_BUTTON_DPAD_DOWN,
 3461    SDL_CONTROLLER_BUTTON_DPAD_LEFT,
 3462    SDL_CONTROLLER_BUTTON_DPAD_RIGHT,
 3463    SDL_CONTROLLER_BUTTON_MAX
 3464} SDL_GameControllerButton;
 3465
 3466extern DECLSPEC SDL_GameControllerButton SDLCALL SDL_GameControllerGetButtonFromString(const char *pchString);
 3467
 3468extern DECLSPEC const char* SDLCALL SDL_GameControllerGetStringForButton(SDL_GameControllerButton button);
 3469
 3470extern DECLSPEC SDL_GameControllerButtonBind SDLCALL
 3471SDL_GameControllerGetBindForButton(SDL_GameController *gamecontroller,
 3472                                   SDL_GameControllerButton button);
 3473
 3474extern DECLSPEC Uint8 SDLCALL SDL_GameControllerGetButton(SDL_GameController *gamecontroller,
 3475                                                          SDL_GameControllerButton button);
 3476
 3477extern DECLSPEC void SDLCALL SDL_GameControllerClose(SDL_GameController *gamecontroller);
 3478
 3479#ifdef __cplusplus
 3480}
 3481#endif
 3482#undef _begin_code_h
 3483
 3484#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__WATCOMC__)  || defined(__BORLANDC__)
 3485#ifdef __BORLANDC__
 3486#pragma nopackwarning
 3487#endif
 3488#pragma pack(pop)
 3489#endif
 3490
 3491#endif
 3492#ifndef _SDL_quit_h
 3493#define _SDL_quit_h
 3494
 3495#define SDL_QuitRequested() \
 3496        (SDL_PumpEvents(), (SDL_PeepEvents(NULL,0,SDL_PEEKEVENT,SDL_QUIT,SDL_QUIT) > 0))
 3497
 3498#endif
 3499#ifndef _SDL_gesture_h
 3500#define _SDL_gesture_h
 3501
 3502#ifndef _SDL_touch_h
 3503#define _SDL_touch_h
 3504
 3505#ifdef _begin_code_h
 3506#error Nested inclusion of begin_code.h
 3507#endif
 3508#define _begin_code_h
 3509
 3510#ifndef SDL_DEPRECATED
 3511#  if (__GNUC__ >= 4)
 3512#    define SDL_DEPRECATED __attribute__((deprecated))
 3513#  else
 3514#    define SDL_DEPRECATED
 3515#  endif
 3516#endif
 3517
 3518#ifndef DECLSPEC
 3519# if defined(__WIN32__) || defined(__WINRT__)
 3520#  ifdef __BORLANDC__
 3521#   ifdef BUILD_SDL
 3522#    define DECLSPEC
 3523#   else
 3524#    define DECLSPEC    __declspec(dllimport)
 3525#   endif
 3526#  else
 3527#   define DECLSPEC __declspec(dllexport)
 3528#  endif
 3529# else
 3530#  if defined(__GNUC__) && __GNUC__ >= 4
 3531#   define DECLSPEC __attribute__ ((visibility("default")))
 3532#  elif defined(__GNUC__) && __GNUC__ >= 2
 3533#   define DECLSPEC __declspec(dllexport)
 3534#  else
 3535#   define DECLSPEC
 3536#  endif
 3537# endif
 3538#endif
 3539
 3540#ifndef SDLCALL
 3541#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
 3542#define SDLCALL __cdecl
 3543#else
 3544#define SDLCALL
 3545#endif
 3546#endif
 3547
 3548#ifdef __SYMBIAN32__
 3549#undef DECLSPEC
 3550#define DECLSPEC
 3551#endif
 3552
 3553#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
 3554#ifdef _MSC_VER
 3555#pragma warning(disable: 4103)
 3556#endif
 3557#ifdef __BORLANDC__
 3558#pragma nopackwarning
 3559#endif
 3560#ifdef _M_X64
 3561
 3562#pragma pack(push,8)
 3563#else
 3564#pragma pack(push,4)
 3565#endif
 3566#endif
 3567
 3568#ifndef SDL_INLINE
 3569#if defined(__GNUC__)
 3570#define SDL_INLINE __inline__
 3571#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
 3572      defined(__DMC__) || defined(__SC__) || \
 3573      defined(__WATCOMC__) || defined(__LCC__) || \
 3574      defined(__DECC)
 3575#define SDL_INLINE __inline
 3576#ifndef __inline__
 3577#define __inline__ __inline
 3578#endif
 3579#else
 3580#define SDL_INLINE inline
 3581#ifndef __inline__
 3582#define __inline__ inline
 3583#endif
 3584#endif
 3585#endif
 3586
 3587#ifndef SDL_FORCE_INLINE
 3588#if defined(_MSC_VER)
 3589#define SDL_FORCE_INLINE __forceinline
 3590#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
 3591#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
 3592#else
 3593#define SDL_FORCE_INLINE static SDL_INLINE
 3594#endif
 3595#endif
 3596
 3597#if !defined(__MACH__)
 3598#ifndef NULL
 3599#ifdef __cplusplus
 3600#define NULL 0
 3601#else
 3602#define NULL ((void *)0)
 3603#endif
 3604#endif
 3605#endif
 3606
 3607#ifdef __cplusplus
 3608extern "C" {
 3609#endif
 3610
 3611typedef Sint64 SDL_TouchID;
 3612typedef Sint64 SDL_FingerID;
 3613
 3614typedef struct SDL_Finger
 3615{
 3616    SDL_FingerID id;
 3617    float x;
 3618    float y;
 3619    float pressure;
 3620} SDL_Finger;
 3621
 3622#define SDL_TOUCH_MOUSEID ((Uint32)-1)
 3623
 3624extern DECLSPEC int SDLCALL SDL_GetNumTouchDevices(void);
 3625
 3626extern DECLSPEC SDL_TouchID SDLCALL SDL_GetTouchDevice(int index);
 3627
 3628extern DECLSPEC int SDLCALL SDL_GetNumTouchFingers(SDL_TouchID touchID);
 3629
 3630extern DECLSPEC SDL_Finger * SDLCALL SDL_GetTouchFinger(SDL_TouchID touchID, int index);
 3631
 3632#ifdef __cplusplus
 3633}
 3634#endif
 3635#undef _begin_code_h
 3636
 3637#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__WATCOMC__)  || defined(__BORLANDC__)
 3638#ifdef __BORLANDC__
 3639#pragma nopackwarning
 3640#endif
 3641#pragma pack(pop)
 3642#endif
 3643
 3644#endif
 3645
 3646#ifdef _begin_code_h
 3647#error Nested inclusion of begin_code.h
 3648#endif
 3649#define _begin_code_h
 3650
 3651#ifndef SDL_DEPRECATED
 3652#  if (__GNUC__ >= 4)
 3653#    define SDL_DEPRECATED __attribute__((deprecated))
 3654#  else
 3655#    define SDL_DEPRECATED
 3656#  endif
 3657#endif
 3658
 3659#ifndef DECLSPEC
 3660# if defined(__WIN32__) || defined(__WINRT__)
 3661#  ifdef __BORLANDC__
 3662#   ifdef BUILD_SDL
 3663#    define DECLSPEC
 3664#   else
 3665#    define DECLSPEC    __declspec(dllimport)
 3666#   endif
 3667#  else
 3668#   define DECLSPEC __declspec(dllexport)
 3669#  endif
 3670# else
 3671#  if defined(__GNUC__) && __GNUC__ >= 4
 3672#   define DECLSPEC __attribute__ ((visibility("default")))
 3673#  elif defined(__GNUC__) && __GNUC__ >= 2
 3674#   define DECLSPEC __declspec(dllexport)
 3675#  else
 3676#   define DECLSPEC
 3677#  endif
 3678# endif
 3679#endif
 3680
 3681#ifndef SDLCALL
 3682#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
 3683#define SDLCALL __cdecl
 3684#else
 3685#define SDLCALL
 3686#endif
 3687#endif
 3688
 3689#ifdef __SYMBIAN32__
 3690#undef DECLSPEC
 3691#define DECLSPEC
 3692#endif
 3693
 3694#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
 3695#ifdef _MSC_VER
 3696#pragma warning(disable: 4103)
 3697#endif
 3698#ifdef __BORLANDC__
 3699#pragma nopackwarning
 3700#endif
 3701#ifdef _M_X64
 3702
 3703#pragma pack(push,8)
 3704#else
 3705#pragma pack(push,4)
 3706#endif
 3707#endif
 3708
 3709#ifndef SDL_INLINE
 3710#if defined(__GNUC__)
 3711#define SDL_INLINE __inline__
 3712#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
 3713      defined(__DMC__) || defined(__SC__) || \
 3714      defined(__WATCOMC__) || defined(__LCC__) || \
 3715      defined(__DECC)
 3716#define SDL_INLINE __inline
 3717#ifndef __inline__
 3718#define __inline__ __inline
 3719#endif
 3720#else
 3721#define SDL_INLINE inline
 3722#ifndef __inline__
 3723#define __inline__ inline
 3724#endif
 3725#endif
 3726#endif
 3727
 3728#ifndef SDL_FORCE_INLINE
 3729#if defined(_MSC_VER)
 3730#define SDL_FORCE_INLINE __forceinline
 3731#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
 3732#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
 3733#else
 3734#define SDL_FORCE_INLINE static SDL_INLINE
 3735#endif
 3736#endif
 3737
 3738#if !defined(__MACH__)
 3739#ifndef NULL
 3740#ifdef __cplusplus
 3741#define NULL 0
 3742#else
 3743#define NULL ((void *)0)
 3744#endif
 3745#endif
 3746#endif
 3747
 3748#ifdef __cplusplus
 3749extern "C" {
 3750#endif
 3751
 3752typedef Sint64 SDL_GestureID;
 3753
 3754extern DECLSPEC int SDLCALL SDL_RecordGesture(SDL_TouchID touchId);
 3755
 3756extern DECLSPEC int SDLCALL SDL_SaveAllDollarTemplates(SDL_RWops *dst);
 3757
 3758extern DECLSPEC int SDLCALL SDL_SaveDollarTemplate(SDL_GestureID gestureId,SDL_RWops *dst);
 3759
 3760extern DECLSPEC int SDLCALL SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src);
 3761
 3762#ifdef __cplusplus
 3763}
 3764#endif
 3765#undef _begin_code_h
 3766
 3767#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__WATCOMC__)  || defined(__BORLANDC__)
 3768#ifdef __BORLANDC__
 3769#pragma nopackwarning
 3770#endif
 3771#pragma pack(pop)
 3772#endif
 3773
 3774#endif
 3775
 3776#ifdef _begin_code_h
 3777#error Nested inclusion of begin_code.h
 3778#endif
 3779#define _begin_code_h
 3780
 3781#ifndef SDL_DEPRECATED
 3782#  if (__GNUC__ >= 4)
 3783#    define SDL_DEPRECATED __attribute__((deprecated))
 3784#  else
 3785#    define SDL_DEPRECATED
 3786#  endif
 3787#endif
 3788
 3789#ifndef DECLSPEC
 3790# if defined(__WIN32__) || defined(__WINRT__)
 3791#  ifdef __BORLANDC__
 3792#   ifdef BUILD_SDL
 3793#    define DECLSPEC
 3794#   else
 3795#    define DECLSPEC    __declspec(dllimport)
 3796#   endif
 3797#  else
 3798#   define DECLSPEC __declspec(dllexport)
 3799#  endif
 3800# else
 3801#  if defined(__GNUC__) && __GNUC__ >= 4
 3802#   define DECLSPEC __attribute__ ((visibility("default")))
 3803#  elif defined(__GNUC__) && __GNUC__ >= 2
 3804#   define DECLSPEC __declspec(dllexport)
 3805#  else
 3806#   define DECLSPEC
 3807#  endif
 3808# endif
 3809#endif
 3810
 3811#ifndef SDLCALL
 3812#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
 3813#define SDLCALL __cdecl
 3814#else
 3815#define SDLCALL
 3816#endif
 3817#endif
 3818
 3819#ifdef __SYMBIAN32__
 3820#undef DECLSPEC
 3821#define DECLSPEC
 3822#endif
 3823
 3824#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
 3825#ifdef _MSC_VER
 3826#pragma warning(disable: 4103)
 3827#endif
 3828#ifdef __BORLANDC__
 3829#pragma nopackwarning
 3830#endif
 3831#ifdef _M_X64
 3832
 3833#pragma pack(push,8)
 3834#else
 3835#pragma pack(push,4)
 3836#endif
 3837#endif
 3838
 3839#ifndef SDL_INLINE
 3840#if defined(__GNUC__)
 3841#define SDL_INLINE __inline__
 3842#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
 3843      defined(__DMC__) || defined(__SC__) || \
 3844      defined(__WATCOMC__) || defined(__LCC__) || \
 3845      defined(__DECC)
 3846#define SDL_INLINE __inline
 3847#ifndef __inline__
 3848#define __inline__ __inline
 3849#endif
 3850#else
 3851#define SDL_INLINE inline
 3852#ifndef __inline__
 3853#define __inline__ inline
 3854#endif
 3855#endif
 3856#endif
 3857
 3858#ifndef SDL_FORCE_INLINE
 3859#if defined(_MSC_VER)
 3860#define SDL_FORCE_INLINE __forceinline
 3861#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
 3862#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
 3863#else
 3864#define SDL_FORCE_INLINE static SDL_INLINE
 3865#endif
 3866#endif
 3867
 3868#if !defined(__MACH__)
 3869#ifndef NULL
 3870#ifdef __cplusplus
 3871#define NULL 0
 3872#else
 3873#define NULL ((void *)0)
 3874#endif
 3875#endif
 3876#endif
 3877
 3878#ifdef __cplusplus
 3879extern "C" {
 3880#endif
 3881
 3882#define SDL_RELEASED    0
 3883#define SDL_PRESSED 1
 3884
 3885typedef enum
 3886{
 3887    SDL_FIRSTEVENT     = 0,
 3888
 3889    SDL_QUIT           = 0x100,
 3890
 3891    SDL_APP_TERMINATING,
 3892    SDL_APP_LOWMEMORY,
 3893    SDL_APP_WILLENTERBACKGROUND,
 3894    SDL_APP_DIDENTERBACKGROUND,
 3895    SDL_APP_WILLENTERFOREGROUND,
 3896    SDL_APP_DIDENTERFOREGROUND,
 3897
 3898    SDL_WINDOWEVENT    = 0x200,
 3899    SDL_SYSWMEVENT,
 3900
 3901    SDL_KEYDOWN        = 0x300,
 3902    SDL_KEYUP,
 3903    SDL_TEXTEDITING,
 3904    SDL_TEXTINPUT,
 3905
 3906    SDL_MOUSEMOTION    = 0x400,
 3907    SDL_MOUSEBUTTONDOWN,
 3908    SDL_MOUSEBUTTONUP,
 3909    SDL_MOUSEWHEEL,
 3910
 3911    SDL_JOYAXISMOTION  = 0x600,
 3912    SDL_JOYBALLMOTION,
 3913    SDL_JOYHATMOTION,
 3914    SDL_JOYBUTTONDOWN,
 3915    SDL_JOYBUTTONUP,
 3916    SDL_JOYDEVICEADDED,
 3917    SDL_JOYDEVICEREMOVED,
 3918
 3919    SDL_CONTROLLERAXISMOTION  = 0x650,
 3920    SDL_CONTROLLERBUTTONDOWN,
 3921    SDL_CONTROLLERBUTTONUP,
 3922    SDL_CONTROLLERDEVICEADDED,
 3923    SDL_CONTROLLERDEVICEREMOVED,
 3924    SDL_CONTROLLERDEVICEREMAPPED,
 3925
 3926    SDL_FINGERDOWN      = 0x700,
 3927    SDL_FINGERUP,
 3928    SDL_FINGERMOTION,
 3929
 3930    SDL_DOLLARGESTURE   = 0x800,
 3931    SDL_DOLLARRECORD,
 3932    SDL_MULTIGESTURE,
 3933
 3934    SDL_CLIPBOARDUPDATE = 0x900,
 3935
 3936    SDL_DROPFILE        = 0x1000,
 3937
 3938    SDL_RENDER_TARGETS_RESET = 0x2000,
 3939
 3940    SDL_USEREVENT    = 0x8000,
 3941
 3942    SDL_LASTEVENT    = 0xFFFF
 3943} SDL_EventType;
 3944
 3945typedef struct SDL_CommonEvent
 3946{
 3947    Uint32 type;
 3948    Uint32 timestamp;
 3949} SDL_CommonEvent;
 3950
 3951typedef struct SDL_WindowEvent
 3952{
 3953    Uint32 type;
 3954    Uint32 timestamp;
 3955    Uint32 windowID;
 3956    Uint8 event;
 3957    Uint8 padding1;
 3958    Uint8 padding2;
 3959    Uint8 padding3;
 3960    Sint32 data1;
 3961    Sint32 data2;
 3962} SDL_WindowEvent;
 3963
 3964typedef struct SDL_KeyboardEvent
 3965{
 3966    Uint32 type;
 3967    Uint32 timestamp;
 3968    Uint32 windowID;
 3969    Uint8 state;
 3970    Uint8 repeat;
 3971    Uint8 padding2;
 3972    Uint8 padding3;
 3973    SDL_Keysym keysym;
 3974} SDL_KeyboardEvent;
 3975
 3976#define SDL_TEXTEDITINGEVENT_TEXT_SIZE (32)
 3977
 3978typedef struct SDL_TextEditingEvent
 3979{
 3980    Uint32 type;
 3981    Uint32 timestamp;
 3982    Uint32 windowID;
 3983    char text[SDL_TEXTEDITINGEVENT_TEXT_SIZE];
 3984    Sint32 start;
 3985    Sint32 length;
 3986} SDL_TextEditingEvent;
 3987
 3988#define SDL_TEXTINPUTEVENT_TEXT_SIZE (32)
 3989
 3990typedef struct SDL_TextInputEvent
 3991{
 3992    Uint32 type;
 3993    Uint32 timestamp;
 3994    Uint32 windowID;
 3995    char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
 3996} SDL_TextInputEvent;
 3997
 3998typedef struct SDL_MouseMotionEvent
 3999{
 4000    Uint32 type;
 4001    Uint32 timestamp;
 4002    Uint32 windowID;
 4003    Uint32 which;
 4004    Uint32 state;
 4005    Sint32 x;
 4006    Sint32 y;
 4007    Sint32 xrel;
 4008    Sint32 yrel;
 4009} SDL_MouseMotionEvent;
 4010
 4011typedef struct SDL_MouseButtonEvent
 4012{
 4013    Uint32 type;
 4014    Uint32 timestamp;
 4015    Uint32 windowID;
 4016    Uint32 which;
 4017    Uint8 button;
 4018    Uint8 state;
 4019    Uint8 clicks;
 4020    Uint8 padding1;
 4021    Sint32 x;
 4022    Sint32 y;
 4023} SDL_MouseButtonEvent;
 4024
 4025typedef struct SDL_MouseWheelEvent
 4026{
 4027    Uint32 type;
 4028    Uint32 timestamp;
 4029    Uint32 windowID;
 4030    Uint32 which;
 4031    Sint32 x;
 4032    Sint32 y;
 4033} SDL_MouseWheelEvent;
 4034
 4035typedef struct SDL_JoyAxisEvent
 4036{
 4037    Uint32 type;
 4038    Uint32 timestamp;
 4039    SDL_JoystickID which;
 4040    Uint8 axis;
 4041    Uint8 padding1;
 4042    Uint8 padding2;
 4043    Uint8 padding3;
 4044    Sint16 value;
 4045    Uint16 padding4;
 4046} SDL_JoyAxisEvent;
 4047
 4048typedef struct SDL_JoyBallEvent
 4049{
 4050    Uint32 type;
 4051    Uint32 timestamp;
 4052    SDL_JoystickID which;
 4053    Uint8 ball;
 4054    Uint8 padding1;
 4055    Uint8 padding2;
 4056    Uint8 padding3;
 4057    Sint16 xrel;
 4058    Sint16 yrel;
 4059} SDL_JoyBallEvent;
 4060
 4061typedef struct SDL_JoyHatEvent
 4062{
 4063    Uint32 type;
 4064    Uint32 timestamp;
 4065    SDL_JoystickID which;
 4066    Uint8 hat;
 4067    Uint8 value;
 4068    Uint8 padding1;
 4069    Uint8 padding2;
 4070} SDL_JoyHatEvent;
 4071
 4072typedef struct SDL_JoyButtonEvent
 4073{
 4074    Uint32 type;
 4075    Uint32 timestamp;
 4076    SDL_JoystickID which;
 4077    Uint8 button;
 4078    Uint8 state;
 4079    Uint8 padding1;
 4080    Uint8 padding2;
 4081} SDL_JoyButtonEvent;
 4082
 4083typedef struct SDL_JoyDeviceEvent
 4084{
 4085    Uint32 type;
 4086    Uint32 timestamp;
 4087    Sint32 which;
 4088} SDL_JoyDeviceEvent;
 4089
 4090typedef struct SDL_ControllerAxisEvent
 4091{
 4092    Uint32 type;
 4093    Uint32 timestamp;
 4094    SDL_JoystickID which;
 4095    Uint8 axis;
 4096    Uint8 padding1;
 4097    Uint8 padding2;
 4098    Uint8 padding3;
 4099    Sint16 value;
 4100    Uint16 padding4;
 4101} SDL_ControllerAxisEvent;
 4102
 4103typedef struct SDL_ControllerButtonEvent
 4104{
 4105    Uint32 type;
 4106    Uint32 timestamp;
 4107    SDL_JoystickID which;
 4108    Uint8 button;
 4109    Uint8 state;
 4110    Uint8 padding1;
 4111    Uint8 padding2;
 4112} SDL_ControllerButtonEvent;
 4113
 4114typedef struct SDL_ControllerDeviceEvent
 4115{
 4116    Uint32 type;
 4117    Uint32 timestamp;
 4118    Sint32 which;
 4119} SDL_ControllerDeviceEvent;
 4120
 4121typedef struct SDL_TouchFingerEvent
 4122{
 4123    Uint32 type;
 4124    Uint32 timestamp;
 4125    SDL_TouchID touchId;
 4126    SDL_FingerID fingerId;
 4127    float x;
 4128    float y;
 4129    float dx;
 4130    float dy;
 4131    float pressure;
 4132} SDL_TouchFingerEvent;
 4133
 4134typedef struct SDL_MultiGestureEvent
 4135{
 4136    Uint32 type;
 4137    Uint32 timestamp;
 4138    SDL_TouchID touchId;
 4139    float dTheta;
 4140    float dDist;
 4141    float x;
 4142    float y;
 4143    Uint16 numFingers;
 4144    Uint16 padding;
 4145} SDL_MultiGestureEvent;
 4146
 4147typedef struct SDL_DollarGestureEvent
 4148{
 4149    Uint32 type;
 4150    Uint32 timestamp;
 4151    SDL_TouchID touchId;
 4152    SDL_GestureID gestureId;
 4153    Uint32 numFingers;
 4154    float error;
 4155    float x;
 4156    float y;
 4157} SDL_DollarGestureEvent;
 4158
 4159typedef struct SDL_DropEvent
 4160{
 4161    Uint32 type;
 4162    Uint32 timestamp;
 4163    char *file;
 4164} SDL_DropEvent;
 4165
 4166typedef struct SDL_QuitEvent
 4167{
 4168    Uint32 type;
 4169    Uint32 timestamp;
 4170} SDL_QuitEvent;
 4171
 4172typedef struct SDL_OSEvent
 4173{
 4174    Uint32 type;
 4175    Uint32 timestamp;
 4176} SDL_OSEvent;
 4177
 4178typedef struct SDL_UserEvent
 4179{
 4180    Uint32 type;
 4181    Uint32 timestamp;
 4182    Uint32 windowID;
 4183    Sint32 code;
 4184    void *data1;
 4185    void *data2;
 4186} SDL_UserEvent;
 4187
 4188struct SDL_SysWMmsg;
 4189typedef struct SDL_SysWMmsg SDL_SysWMmsg;
 4190
 4191typedef struct SDL_SysWMEvent
 4192{
 4193    Uint32 type;
 4194    Uint32 timestamp;
 4195    SDL_SysWMmsg *msg;
 4196} SDL_SysWMEvent;
 4197
 4198typedef union SDL_Event
 4199{
 4200    Uint32 type;
 4201    SDL_CommonEvent common;
 4202    SDL_WindowEvent window;
 4203    SDL_KeyboardEvent key;
 4204    SDL_TextEditingEvent edit;
 4205    SDL_TextInputEvent text;
 4206    SDL_MouseMotionEvent motion;
 4207    SDL_MouseButtonEvent button;
 4208    SDL_MouseWheelEvent wheel;
 4209    SDL_JoyAxisEvent jaxis;
 4210    SDL_JoyBallEvent jball;
 4211    SDL_JoyHatEvent jhat;
 4212    SDL_JoyButtonEvent jbutton;
 4213    SDL_JoyDeviceEvent jdevice;
 4214    SDL_ControllerAxisEvent caxis;
 4215    SDL_ControllerButtonEvent cbutton;
 4216    SDL_ControllerDeviceEvent cdevice;
 4217    SDL_QuitEvent quit;
 4218    SDL_UserEvent user;
 4219    SDL_SysWMEvent syswm;
 4220    SDL_TouchFingerEvent tfinger;
 4221    SDL_MultiGestureEvent mgesture;
 4222    SDL_DollarGestureEvent dgesture;
 4223    SDL_DropEvent drop;
 4224
 4225    Uint8 padding[56];
 4226} SDL_Event;
 4227
 4228extern DECLSPEC void SDLCALL SDL_PumpEvents(void);
 4229
 4230typedef enum
 4231{
 4232    SDL_ADDEVENT,
 4233    SDL_PEEKEVENT,
 4234    SDL_GETEVENT
 4235} SDL_eventaction;
 4236
 4237extern DECLSPEC int SDLCALL SDL_PeepEvents(SDL_Event * events, int numevents,
 4238                                           SDL_eventaction action,
 4239                                           Uint32 minType, Uint32 maxType);
 4240
 4241extern DECLSPEC SDL_bool SDLCALL SDL_HasEvent(Uint32 type);
 4242extern DECLSPEC SDL_bool SDLCALL SDL_HasEvents(Uint32 minType, Uint32 maxType);
 4243
 4244extern DECLSPEC void SDLCALL SDL_FlushEvent(Uint32 type);
 4245extern DECLSPEC void SDLCALL SDL_FlushEvents(Uint32 minType, Uint32 maxType);
 4246
 4247extern DECLSPEC int SDLCALL SDL_PollEvent(SDL_Event * event);
 4248
 4249extern DECLSPEC int SDLCALL SDL_WaitEvent(SDL_Event * event);
 4250
 4251extern DECLSPEC int SDLCALL SDL_WaitEventTimeout(SDL_Event * event,
 4252                                                 int timeout);
 4253
 4254extern DECLSPEC int SDLCALL SDL_PushEvent(SDL_Event * event);
 4255
 4256typedef int (SDLCALL * SDL_EventFilter) (void *userdata, SDL_Event * event);
 4257
 4258extern DECLSPEC void SDLCALL SDL_SetEventFilter(SDL_EventFilter filter,
 4259                                                void *userdata);
 4260
 4261extern DECLSPEC SDL_bool SDLCALL SDL_GetEventFilter(SDL_EventFilter * filter,
 4262                                                    void **userdata);
 4263
 4264extern DECLSPEC void SDLCALL SDL_AddEventWatch(SDL_EventFilter filter,
 4265                                               void *userdata);
 4266
 4267extern DECLSPEC void SDLCALL SDL_DelEventWatch(SDL_EventFilter filter,
 4268                                               void *userdata);
 4269
 4270extern DECLSPEC void SDLCALL SDL_FilterEvents(SDL_EventFilter filter,
 4271                                              void *userdata);
 4272
 4273#define SDL_QUERY   -1
 4274#define SDL_IGNORE   0
 4275#define SDL_DISABLE  0
 4276#define SDL_ENABLE   1
 4277
 4278extern DECLSPEC Uint8 SDLCALL SDL_EventState(Uint32 type, int state);
 4279
 4280#define SDL_GetEventState(type) SDL_EventState(type, SDL_QUERY)
 4281
 4282extern DECLSPEC Uint32 SDLCALL SDL_RegisterEvents(int numevents);
 4283
 4284#ifdef __cplusplus
 4285}
 4286#endif
 4287#undef _begin_code_h
 4288
 4289#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__WATCOMC__)  || defined(__BORLANDC__)
 4290#ifdef __BORLANDC__
 4291#pragma nopackwarning
 4292#endif
 4293#pragma pack(pop)
 4294#endif
 4295
 4296#endif
 4297#include "SDL_filesystem.h"
 4298#include "SDL_haptic.h"
 4299#ifndef _SDL_hints_h
 4300#define _SDL_hints_h
 4301
 4302#ifdef _begin_code_h
 4303#error Nested inclusion of begin_code.h
 4304#endif
 4305#define _begin_code_h
 4306
 4307#ifndef SDL_DEPRECATED
 4308#  if (__GNUC__ >= 4)
 4309#    define SDL_DEPRECATED __attribute__((deprecated))
 4310#  else
 4311#    define SDL_DEPRECATED
 4312#  endif
 4313#endif
 4314
 4315#ifndef DECLSPEC
 4316# if defined(__WIN32__) || defined(__WINRT__)
 4317#  ifdef __BORLANDC__
 4318#   ifdef BUILD_SDL
 4319#    define DECLSPEC
 4320#   else
 4321#    define DECLSPEC    __declspec(dllimport)
 4322#   endif
 4323#  else
 4324#   define DECLSPEC __declspec(dllexport)
 4325#  endif
 4326# else
 4327#  if defined(__GNUC__) && __GNUC__ >= 4
 4328#   define DECLSPEC __attribute__ ((visibility("default")))
 4329#  elif defined(__GNUC__) && __GNUC__ >= 2
 4330#   define DECLSPEC __declspec(dllexport)
 4331#  else
 4332#   define DECLSPEC
 4333#  endif
 4334# endif
 4335#endif
 4336
 4337#ifndef SDLCALL
 4338#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
 4339#define SDLCALL __cdecl
 4340#else
 4341#define SDLCALL
 4342#endif
 4343#endif
 4344
 4345#ifdef __SYMBIAN32__
 4346#undef DECLSPEC
 4347#define DECLSPEC
 4348#endif
 4349
 4350#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
 4351#ifdef _MSC_VER
 4352#pragma warning(disable: 4103)
 4353#endif
 4354#ifdef __BORLANDC__
 4355#pragma nopackwarning
 4356#endif
 4357#ifdef _M_X64
 4358
 4359#pragma pack(push,8)
 4360#else
 4361#pragma pack(push,4)
 4362#endif
 4363#endif
 4364
 4365#ifndef SDL_INLINE
 4366#if defined(__GNUC__)
 4367#define SDL_INLINE __inline__
 4368#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
 4369      defined(__DMC__) || defined(__SC__) || \
 4370      defined(__WATCOMC__) || defined(__LCC__) || \
 4371      defined(__DECC)
 4372#define SDL_INLINE __inline
 4373#ifndef __inline__
 4374#define __inline__ __inline
 4375#endif
 4376#else
 4377#define SDL_INLINE inline
 4378#ifndef __inline__
 4379#define __inline__ inline
 4380#endif
 4381#endif
 4382#endif
 4383
 4384#ifndef SDL_FORCE_INLINE
 4385#if defined(_MSC_VER)
 4386#define SDL_FORCE_INLINE __forceinline
 4387#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
 4388#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
 4389#else
 4390#define SDL_FORCE_INLINE static SDL_INLINE
 4391#endif
 4392#endif
 4393
 4394#if !defined(__MACH__)
 4395#ifndef NULL
 4396#ifdef __cplusplus
 4397#define NULL 0
 4398#else
 4399#define NULL ((void *)0)
 4400#endif
 4401#endif
 4402#endif
 4403
 4404#ifdef __cplusplus
 4405extern "C" {
 4406#endif
 4407
 4408#define SDL_HINT_FRAMEBUFFER_ACCELERATION   "SDL_FRAMEBUFFER_ACCELERATION"
 4409
 4410#define SDL_HINT_RENDER_DRIVER              "SDL_RENDER_DRIVER"
 4411
 4412#define SDL_HINT_RENDER_OPENGL_SHADERS      "SDL_RENDER_OPENGL_SHADERS"
 4413
 4414#define SDL_HINT_RENDER_DIRECT3D_THREADSAFE "SDL_RENDER_DIRECT3D_THREADSAFE"
 4415
 4416#define SDL_HINT_RENDER_DIRECT3D11_DEBUG    "SDL_HINT_RENDER_DIRECT3D11_DEBUG"
 4417
 4418#define SDL_HINT_RENDER_SCALE_QUALITY       "SDL_RENDER_SCALE_QUALITY"
 4419
 4420#define SDL_HINT_RENDER_VSYNC               "SDL_RENDER_VSYNC"
 4421
 4422#define SDL_HINT_VIDEO_ALLOW_SCREENSAVER    "SDL_VIDEO_ALLOW_SCREENSAVER"
 4423
 4424#define SDL_HINT_VIDEO_X11_XVIDMODE         "SDL_VIDEO_X11_XVIDMODE"
 4425
 4426#define SDL_HINT_VIDEO_X11_XINERAMA         "SDL_VIDEO_X11_XINERAMA"
 4427
 4428#define SDL_HINT_VIDEO_X11_XRANDR           "SDL_VIDEO_X11_XRANDR"
 4429
 4430#define SDL_HINT_GRAB_KEYBOARD              "SDL_GRAB_KEYBOARD"
 4431
 4432#define SDL_HINT_MOUSE_RELATIVE_MODE_WARP    "SDL_MOUSE_RELATIVE_MODE_WARP"
 4433
 4434#define SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS   "SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS"
 4435
 4436#define SDL_HINT_IDLE_TIMER_DISABLED "SDL_IOS_IDLE_TIMER_DISABLED"
 4437
 4438#define SDL_HINT_ORIENTATIONS "SDL_IOS_ORIENTATIONS"
 4439
 4440#define SDL_HINT_ACCELEROMETER_AS_JOYSTICK "SDL_ACCELEROMETER_AS_JOYSTICK"
 4441
 4442#define SDL_HINT_XINPUT_ENABLED "SDL_XINPUT_ENABLED"
 4443
 4444#define SDL_HINT_GAMECONTROLLERCONFIG "SDL_GAMECONTROLLERCONFIG"
 4445
 4446#define SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS "SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS"
 4447
 4448#define SDL_HINT_ALLOW_TOPMOST "SDL_ALLOW_TOPMOST"
 4449
 4450#define SDL_HINT_TIMER_RESOLUTION "SDL_TIMER_RESOLUTION"
 4451
 4452#define SDL_HINT_VIDEO_HIGHDPI_DISABLED "SDL_VIDEO_HIGHDPI_DISABLED"
 4453
 4454#define SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK "SDL_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK"
 4455
 4456#define SDL_HINT_VIDEO_WIN_D3DCOMPILER              "SDL_VIDEO_WIN_D3DCOMPILER"
 4457
 4458#define SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT    "SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT"
 4459
 4460#define SDL_HINT_WINRT_PRIVACY_POLICY_URL "SDL_HINT_WINRT_PRIVACY_POLICY_URL"
 4461
 4462#define SDL_HINT_WINRT_PRIVACY_POLICY_LABEL "SDL_HINT_WINRT_PRIVACY_POLICY_LABEL"
 4463
 4464#define SDL_HINT_WINRT_HANDLE_BACK_BUTTON "SDL_HINT_WINRT_HANDLE_BACK_BUTTON"
 4465
 4466#define SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES    "SDL_VIDEO_MAC_FULLSCREEN_SPACES"
 4467
 4468typedef enum
 4469{
 4470    SDL_HINT_DEFAULT,
 4471    SDL_HINT_NORMAL,
 4472    SDL_HINT_OVERRIDE
 4473} SDL_HintPriority;
 4474
 4475extern DECLSPEC SDL_bool SDLCALL SDL_SetHintWithPriority(const char *name,
 4476                                                         const char *value,
 4477                                                         SDL_HintPriority priority);
 4478
 4479extern DECLSPEC SDL_bool SDLCALL SDL_SetHint(const char *name,
 4480                                             const char *value);
 4481
 4482extern DECLSPEC const char * SDLCALL SDL_GetHint(const char *name);
 4483
 4484typedef void (*SDL_HintCallback)(void *userdata, const char *name, const char *oldValue, const char *newValue);
 4485extern DECLSPEC void SDLCALL SDL_AddHintCallback(const char *name,
 4486                                                 SDL_HintCallback callback,
 4487                                                 void *userdata);
 4488
 4489extern DECLSPEC void SDLCALL SDL_DelHintCallback(const char *name,
 4490                                                 SDL_HintCallback callback,
 4491                                                 void *userdata);
 4492
 4493extern DECLSPEC void SDLCALL SDL_ClearHints(void);
 4494
 4495#ifdef __cplusplus
 4496}
 4497#endif
 4498#undef _begin_code_h
 4499
 4500#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__WATCOMC__)  || defined(__BORLANDC__)
 4501#ifdef __BORLANDC__
 4502#pragma nopackwarning
 4503#endif
 4504#pragma pack(pop)
 4505#endif
 4506
 4507#endif
 4508#ifndef _SDL_loadso_h
 4509#define _SDL_loadso_h
 4510
 4511#ifdef _begin_code_h
 4512#error Nested inclusion of begin_code.h
 4513#endif
 4514#define _begin_code_h
 4515
 4516#ifndef SDL_DEPRECATED
 4517#  if (__GNUC__ >= 4)
 4518#    define SDL_DEPRECATED __attribute__((deprecated))
 4519#  else
 4520#    define SDL_DEPRECATED
 4521#  endif
 4522#endif
 4523
 4524#ifndef DECLSPEC
 4525# if defined(__WIN32__) || defined(__WINRT__)
 4526#  ifdef __BORLANDC__
 4527#   ifdef BUILD_SDL
 4528#    define DECLSPEC
 4529#   else
 4530#    define DECLSPEC    __declspec(dllimport)
 4531#   endif
 4532#  else
 4533#   define DECLSPEC __declspec(dllexport)
 4534#  endif
 4535# else
 4536#  if defined(__GNUC__) && __GNUC__ >= 4
 4537#   define DECLSPEC __attribute__ ((visibility("default")))
 4538#  elif defined(__GNUC__) && __GNUC__ >= 2
 4539#   define DECLSPEC __declspec(dllexport)
 4540#  else
 4541#   define DECLSPEC
 4542#  endif
 4543# endif
 4544#endif
 4545
 4546#ifndef SDLCALL
 4547#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
 4548#define SDLCALL __cdecl
 4549#else
 4550#define SDLCALL
 4551#endif
 4552#endif
 4553
 4554#ifdef __SYMBIAN32__
 4555#undef DECLSPEC
 4556#define DECLSPEC
 4557#endif
 4558
 4559#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
 4560#ifdef _MSC_VER
 4561#pragma warning(disable: 4103)
 4562#endif
 4563#ifdef __BORLANDC__
 4564#pragma nopackwarning
 4565#endif
 4566#ifdef _M_X64
 4567
 4568#pragma pack(push,8)
 4569#else
 4570#pragma pack(push,4)
 4571#endif
 4572#endif
 4573
 4574#ifndef SDL_INLINE
 4575#if defined(__GNUC__)
 4576#define SDL_INLINE __inline__
 4577#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
 4578      defined(__DMC__) || defined(__SC__) || \
 4579      defined(__WATCOMC__) || defined(__LCC__) || \
 4580      defined(__DECC)
 4581#define SDL_INLINE __inline
 4582#ifndef __inline__
 4583#define __inline__ __inline
 4584#endif
 4585#else
 4586#define SDL_INLINE inline
 4587#ifndef __inline__
 4588#define __inline__ inline
 4589#endif
 4590#endif
 4591#endif
 4592
 4593#ifndef SDL_FORCE_INLINE
 4594#if defined(_MSC_VER)
 4595#define SDL_FORCE_INLINE __forceinline
 4596#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
 4597#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
 4598#else
 4599#define SDL_FORCE_INLINE static SDL_INLINE
 4600#endif
 4601#endif
 4602
 4603#if !defined(__MACH__)
 4604#ifndef NULL
 4605#ifdef __cplusplus
 4606#define NULL 0
 4607#else
 4608#define NULL ((void *)0)
 4609#endif
 4610#endif
 4611#endif
 4612
 4613#ifdef __cplusplus
 4614extern "C" {
 4615#endif
 4616
 4617extern DECLSPEC void *SDLCALL SDL_LoadObject(const char *sofile);
 4618
 4619extern DECLSPEC void *SDLCALL SDL_LoadFunction(void *handle,
 4620                                               const char *name);
 4621
 4622extern DECLSPEC void SDLCALL SDL_UnloadObject(void *handle);
 4623
 4624#ifdef __cplusplus
 4625}
 4626#endif
 4627#undef _begin_code_h
 4628
 4629#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__WATCOMC__)  || defined(__BORLANDC__)
 4630#ifdef __BORLANDC__
 4631#pragma nopackwarning
 4632#endif
 4633#pragma pack(pop)
 4634#endif
 4635
 4636#endif
 4637#include "SDL_log.h"
 4638#ifndef _SDL_messagebox_h
 4639#define _SDL_messagebox_h
 4640
 4641#ifdef _begin_code_h
 4642#error Nested inclusion of begin_code.h
 4643#endif
 4644#define _begin_code_h
 4645
 4646#ifndef SDL_DEPRECATED
 4647#  if (__GNUC__ >= 4)
 4648#    define SDL_DEPRECATED __attribute__((deprecated))
 4649#  else
 4650#    define SDL_DEPRECATED
 4651#  endif
 4652#endif
 4653
 4654#ifndef DECLSPEC
 4655# if defined(__WIN32__) || defined(__WINRT__)
 4656#  ifdef __BORLANDC__
 4657#   ifdef BUILD_SDL
 4658#    define DECLSPEC
 4659#   else
 4660#    define DECLSPEC    __declspec(dllimport)
 4661#   endif
 4662#  else
 4663#   define DECLSPEC __declspec(dllexport)
 4664#  endif
 4665# else
 4666#  if defined(__GNUC__) && __GNUC__ >= 4
 4667#   define DECLSPEC __attribute__ ((visibility("default")))
 4668#  elif defined(__GNUC__) && __GNUC__ >= 2
 4669#   define DECLSPEC __declspec(dllexport)
 4670#  else
 4671#   define DECLSPEC
 4672#  endif
 4673# endif
 4674#endif
 4675
 4676#ifndef SDLCALL
 4677#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
 4678#define SDLCALL __cdecl
 4679#else
 4680#define SDLCALL
 4681#endif
 4682#endif
 4683
 4684#ifdef __SYMBIAN32__
 4685#undef DECLSPEC
 4686#define DECLSPEC
 4687#endif
 4688
 4689#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
 4690#ifdef _MSC_VER
 4691#pragma warning(disable: 4103)
 4692#endif
 4693#ifdef __BORLANDC__
 4694#pragma nopackwarning
 4695#endif
 4696#ifdef _M_X64
 4697
 4698#pragma pack(push,8)
 4699#else
 4700#pragma pack(push,4)
 4701#endif
 4702#endif
 4703
 4704#ifndef SDL_INLINE
 4705#if defined(__GNUC__)
 4706#define SDL_INLINE __inline__
 4707#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
 4708      defined(__DMC__) || defined(__SC__) || \
 4709      defined(__WATCOMC__) || defined(__LCC__) || \
 4710      defined(__DECC)
 4711#define SDL_INLINE __inline
 4712#ifndef __inline__
 4713#define __inline__ __inline
 4714#endif
 4715#else
 4716#define SDL_INLINE inline
 4717#ifndef __inline__
 4718#define __inline__ inline
 4719#endif
 4720#endif
 4721#endif
 4722
 4723#ifndef SDL_FORCE_INLINE
 4724#if defined(_MSC_VER)
 4725#define SDL_FORCE_INLINE __forceinline
 4726#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
 4727#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
 4728#else
 4729#define SDL_FORCE_INLINE static SDL_INLINE
 4730#endif
 4731#endif
 4732
 4733#if !defined(__MACH__)
 4734#ifndef NULL
 4735#ifdef __cplusplus
 4736#define NULL 0
 4737#else
 4738#define NULL ((void *)0)
 4739#endif
 4740#endif
 4741#endif
 4742
 4743#ifdef __cplusplus
 4744extern "C" {
 4745#endif
 4746
 4747typedef enum
 4748{
 4749    SDL_MESSAGEBOX_ERROR        = 0x00000010,
 4750    SDL_MESSAGEBOX_WARNING      = 0x00000020,
 4751    SDL_MESSAGEBOX_INFORMATION  = 0x00000040
 4752} SDL_MessageBoxFlags;
 4753
 4754typedef enum
 4755{
 4756    SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT = 0x00000001,
 4757    SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT = 0x00000002
 4758} SDL_MessageBoxButtonFlags;
 4759
 4760typedef struct
 4761{
 4762    Uint32 flags;
 4763    int buttonid;
 4764    const char * text;
 4765} SDL_MessageBoxButtonData;
 4766
 4767typedef struct
 4768{
 4769    Uint8 r, g, b;
 4770} SDL_MessageBoxColor;
 4771
 4772typedef enum
 4773{
 4774    SDL_MESSAGEBOX_COLOR_BACKGROUND,
 4775    SDL_MESSAGEBOX_COLOR_TEXT,
 4776    SDL_MESSAGEBOX_COLOR_BUTTON_BORDER,
 4777    SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND,
 4778    SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED,
 4779    SDL_MESSAGEBOX_COLOR_MAX
 4780} SDL_MessageBoxColorType;
 4781
 4782typedef struct
 4783{
 4784    SDL_MessageBoxColor colors[SDL_MESSAGEBOX_COLOR_MAX];
 4785} SDL_MessageBoxColorScheme;
 4786
 4787typedef struct
 4788{
 4789    Uint32 flags;
 4790    SDL_Window *window;
 4791    const char *title;
 4792    const char *message;
 4793
 4794    int numbuttons;
 4795    const SDL_MessageBoxButtonData *buttons;
 4796
 4797    const SDL_MessageBoxColorScheme *colorScheme;
 4798} SDL_MessageBoxData;
 4799
 4800extern DECLSPEC int SDLCALL SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid);
 4801
 4802extern DECLSPEC int SDLCALL SDL_ShowSimpleMessageBox(Uint32 flags, const char *title, const char *message, SDL_Window *window);
 4803
 4804#ifdef __cplusplus
 4805}
 4806#endif
 4807#undef _begin_code_h
 4808
 4809#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__WATCOMC__)  || defined(__BORLANDC__)
 4810#ifdef __BORLANDC__
 4811#pragma nopackwarning
 4812#endif
 4813#pragma pack(pop)
 4814#endif
 4815
 4816#endif
 4817#include "SDL_power.h"
 4818#ifndef _SDL_render_h
 4819#define _SDL_render_h
 4820
 4821#ifdef _begin_code_h
 4822#error Nested inclusion of begin_code.h
 4823#endif
 4824#define _begin_code_h
 4825
 4826#ifndef SDL_DEPRECATED
 4827#  if (__GNUC__ >= 4)
 4828#    define SDL_DEPRECATED __attribute__((deprecated))
 4829#  else
 4830#    define SDL_DEPRECATED
 4831#  endif
 4832#endif
 4833
 4834#ifndef DECLSPEC
 4835# if defined(__WIN32__) || defined(__WINRT__)
 4836#  ifdef __BORLANDC__
 4837#   ifdef BUILD_SDL
 4838#    define DECLSPEC
 4839#   else
 4840#    define DECLSPEC    __declspec(dllimport)
 4841#   endif
 4842#  else
 4843#   define DECLSPEC __declspec(dllexport)
 4844#  endif
 4845# else
 4846#  if defined(__GNUC__) && __GNUC__ >= 4
 4847#   define DECLSPEC __attribute__ ((visibility("default")))
 4848#  elif defined(__GNUC__) && __GNUC__ >= 2
 4849#   define DECLSPEC __declspec(dllexport)
 4850#  else
 4851#   define DECLSPEC
 4852#  endif
 4853# endif
 4854#endif
 4855
 4856#ifndef SDLCALL
 4857#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
 4858#define SDLCALL __cdecl
 4859#else
 4860#define SDLCALL
 4861#endif
 4862#endif
 4863
 4864#ifdef __SYMBIAN32__
 4865#undef DECLSPEC
 4866#define DECLSPEC
 4867#endif
 4868
 4869#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
 4870#ifdef _MSC_VER
 4871#pragma warning(disable: 4103)
 4872#endif
 4873#ifdef __BORLANDC__
 4874#pragma nopackwarning
 4875#endif
 4876#ifdef _M_X64
 4877
 4878#pragma pack(push,8)
 4879#else
 4880#pragma pack(push,4)
 4881#endif
 4882#endif
 4883
 4884#ifndef SDL_INLINE
 4885#if defined(__GNUC__)
 4886#define SDL_INLINE __inline__
 4887#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
 4888      defined(__DMC__) || defined(__SC__) || \
 4889      defined(__WATCOMC__) || defined(__LCC__) || \
 4890      defined(__DECC)
 4891#define SDL_INLINE __inline
 4892#ifndef __inline__
 4893#define __inline__ __inline
 4894#endif
 4895#else
 4896#define SDL_INLINE inline
 4897#ifndef __inline__
 4898#define __inline__ inline
 4899#endif
 4900#endif
 4901#endif
 4902
 4903#ifndef SDL_FORCE_INLINE
 4904#if defined(_MSC_VER)
 4905#define SDL_FORCE_INLINE __forceinline
 4906#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
 4907#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
 4908#else
 4909#define SDL_FORCE_INLINE static SDL_INLINE
 4910#endif
 4911#endif
 4912
 4913#if !defined(__MACH__)
 4914#ifndef NULL
 4915#ifdef __cplusplus
 4916#define NULL 0
 4917#else
 4918#define NULL ((void *)0)
 4919#endif
 4920#endif
 4921#endif
 4922
 4923#ifdef __cplusplus
 4924extern "C" {
 4925#endif
 4926
 4927typedef enum
 4928{
 4929    SDL_RENDERER_SOFTWARE = 0x00000001,
 4930    SDL_RENDERER_ACCELERATED = 0x00000002,
 4931    SDL_RENDERER_PRESENTVSYNC = 0x00000004,
 4932    SDL_RENDERER_TARGETTEXTURE = 0x00000008
 4933} SDL_RendererFlags;
 4934
 4935typedef struct SDL_RendererInfo
 4936{
 4937    const char *name;
 4938    Uint32 flags;
 4939    Uint32 num_texture_formats;
 4940    Uint32 texture_formats[16];
 4941    int max_texture_width;
 4942    int max_texture_height;
 4943} SDL_RendererInfo;
 4944
 4945typedef enum
 4946{
 4947    SDL_TEXTUREACCESS_STATIC,
 4948    SDL_TEXTUREACCESS_STREAMING,
 4949    SDL_TEXTUREACCESS_TARGET
 4950} SDL_TextureAccess;
 4951
 4952typedef enum
 4953{
 4954    SDL_TEXTUREMODULATE_NONE = 0x00000000,
 4955    SDL_TEXTUREMODULATE_COLOR = 0x00000001,
 4956    SDL_TEXTUREMODULATE_ALPHA = 0x00000002
 4957} SDL_TextureModulate;
 4958
 4959typedef enum
 4960{
 4961    SDL_FLIP_NONE = 0x00000000,
 4962    SDL_FLIP_HORIZONTAL = 0x00000001,
 4963    SDL_FLIP_VERTICAL = 0x00000002
 4964} SDL_RendererFlip;
 4965
 4966struct SDL_Renderer;
 4967typedef struct SDL_Renderer SDL_Renderer;
 4968
 4969struct SDL_Texture;
 4970typedef struct SDL_Texture SDL_Texture;
 4971
 4972extern DECLSPEC int SDLCALL SDL_GetNumRenderDrivers(void);
 4973
 4974extern DECLSPEC int SDLCALL SDL_GetRenderDriverInfo(int index,
 4975                                                    SDL_RendererInfo * info);
 4976
 4977extern DECLSPEC int SDLCALL SDL_CreateWindowAndRenderer(
 4978                                int width, int height, Uint32 window_flags,
 4979                                SDL_Window **window, SDL_Renderer **renderer);
 4980
 4981extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRenderer(SDL_Window * window,
 4982                                               int index, Uint32 flags);
 4983
 4984extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateSoftwareRenderer(SDL_Surface * surface);
 4985
 4986extern DECLSPEC SDL_Renderer * SDLCALL SDL_GetRenderer(SDL_Window * window);
 4987
 4988extern DECLSPEC int SDLCALL SDL_GetRendererInfo(SDL_Renderer * renderer,
 4989                                                SDL_RendererInfo * info);
 4990
 4991extern DECLSPEC int SDLCALL SDL_GetRendererOutputSize(SDL_Renderer * renderer,
 4992                                                      int *w, int *h);
 4993
 4994extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTexture(SDL_Renderer * renderer,
 4995                                                        Uint32 format,
 4996                                                        int access, int w,
 4997                                                        int h);
 4998
 4999extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface);
 5000
 5001extern DECLSPEC int SDLCALL SDL_QueryTexture(SDL_Texture * texture,
 5002                                             Uint32 * format, int *access,
 5003                                             int *w, int *h);
 5004
 5005extern DECLSPEC int SDLCALL SDL_SetTextureColorMod(SDL_Texture * texture,
 5006                                                   Uint8 r, Uint8 g, Uint8 b);
 5007
 5008extern DECLSPEC int SDLCALL SDL_GetTextureColorMod(SDL_Texture * texture,
 5009                                                   Uint8 * r, Uint8 * g,
 5010                                                   Uint8 * b);
 5011
 5012extern DECLSPEC int SDLCALL SDL_SetTextureAlphaMod(SDL_Texture * texture,
 5013                                                   Uint8 alpha);
 5014
 5015extern DECLSPEC int SDLCALL SDL_GetTextureAlphaMod(SDL_Texture * texture,
 5016                                                   Uint8 * alpha);
 5017
 5018extern DECLSPEC int SDLCALL SDL_SetTextureBlendMode(SDL_Texture * texture,
 5019                                                    SDL_BlendMode blendMode);
 5020
 5021extern DECLSPEC int SDLCALL SDL_GetTextureBlendMode(SDL_Texture * texture,
 5022                                                    SDL_BlendMode *blendMode);
 5023
 5024extern DECLSPEC int SDLCALL SDL_UpdateTexture(SDL_Texture * texture,
 5025                                              const SDL_Rect * rect,
 5026                                              const void *pixels, int pitch);
 5027
 5028extern DECLSPEC int SDLCALL SDL_UpdateYUVTexture(SDL_Texture * texture,
 5029                                                 const SDL_Rect * rect,
 5030                                                 const Uint8 *Yplane, int Ypitch,
 5031                                                 const Uint8 *Uplane, int Upitch,
 5032                                                 const Uint8 *Vplane, int Vpitch);
 5033
 5034extern DECLSPEC int SDLCALL SDL_LockTexture(SDL_Texture * texture,
 5035                                            const SDL_Rect * rect,
 5036                                            void **pixels, int *pitch);
 5037
 5038extern DECLSPEC void SDLCALL SDL_UnlockTexture(SDL_Texture * texture);
 5039
 5040extern DECLSPEC SDL_bool SDLCALL SDL_RenderTargetSupported(SDL_Renderer *renderer);
 5041
 5042extern DECLSPEC int SDLCALL SDL_SetRenderTarget(SDL_Renderer *renderer,
 5043                                                SDL_Texture *texture);
 5044
 5045extern DECLSPEC SDL_Texture * SDLCALL SDL_GetRenderTarget(SDL_Renderer *renderer);
 5046
 5047extern DECLSPEC int SDLCALL SDL_RenderSetLogicalSize(SDL_Renderer * renderer, int w, int h);
 5048
 5049extern DECLSPEC void SDLCALL SDL_RenderGetLogicalSize(SDL_Renderer * renderer, int *w, int *h);
 5050
 5051extern DECLSPEC int SDLCALL SDL_RenderSetViewport(SDL_Renderer * renderer,
 5052                                                  const SDL_Rect * rect);
 5053
 5054extern DECLSPEC void SDLCALL SDL_RenderGetViewport(SDL_Renderer * renderer,
 5055                                                   SDL_Rect * rect);
 5056
 5057extern DECLSPEC int SDLCALL SDL_RenderSetClipRect(SDL_Renderer * renderer,
 5058                                                  const SDL_Rect * rect);
 5059
 5060extern DECLSPEC void SDLCALL SDL_RenderGetClipRect(SDL_Renderer * renderer,
 5061                                                   SDL_Rect * rect);
 5062
 5063extern DECLSPEC int SDLCALL SDL_RenderSetScale(SDL_Renderer * renderer,
 5064                                               float scaleX, float scaleY);
 5065
 5066extern DECLSPEC void SDLCALL SDL_RenderGetScale(SDL_Renderer * renderer,
 5067                                               float *scaleX, float *scaleY);
 5068
 5069extern DECLSPEC int SDLCALL SDL_SetRenderDrawColor(SDL_Renderer * renderer,
 5070                                           Uint8 r, Uint8 g, Uint8 b,
 5071                                           Uint8 a);
 5072
 5073extern DECLSPEC int SDLCALL SDL_GetRenderDrawColor(SDL_Renderer * renderer,
 5074                                           Uint8 * r, Uint8 * g, Uint8 * b,
 5075                                           Uint8 * a);
 5076
 5077extern DECLSPEC int SDLCALL SDL_SetRenderDrawBlendMode(SDL_Renderer * renderer,
 5078                                                       SDL_BlendMode blendMode);
 5079
 5080extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(SDL_Renderer * renderer,
 5081                                                       SDL_BlendMode *blendMode);
 5082
 5083extern DECLSPEC int SDLCALL SDL_RenderClear(SDL_Renderer * renderer);
 5084
 5085extern DECLSPEC int SDLCALL SDL_RenderDrawPoint(SDL_Renderer * renderer,
 5086                                                int x, int y);
 5087
 5088extern DECLSPEC int SDLCALL SDL_RenderDrawPoints(SDL_Renderer * renderer,
 5089                                                 const SDL_Point * points,
 5090                                                 int count);
 5091
 5092extern DECLSPEC int SDLCALL SDL_RenderDrawLine(SDL_Renderer * renderer,
 5093                                               int x1, int y1, int x2, int y2);
 5094
 5095extern DECLSPEC int SDLCALL SDL_RenderDrawLines(SDL_Renderer * renderer,
 5096                                                const SDL_Point * points,
 5097                                                int count);
 5098
 5099extern DECLSPEC int SDLCALL SDL_RenderDrawRect(SDL_Renderer * renderer,
 5100                                               const SDL_Rect * rect);
 5101
 5102extern DECLSPEC int SDLCALL SDL_RenderDrawRects(SDL_Renderer * renderer,
 5103                                                const SDL_Rect * rects,
 5104                                                int count);
 5105
 5106extern DECLSPEC int SDLCALL SDL_RenderFillRect(SDL_Renderer * renderer,
 5107                                               const SDL_Rect * rect);
 5108
 5109extern DECLSPEC int SDLCALL SDL_RenderFillRects(SDL_Renderer * renderer,
 5110                                                const SDL_Rect * rects,
 5111                                                int count);
 5112
 5113extern DECLSPEC int SDLCALL SDL_RenderCopy(SDL_Renderer * renderer,
 5114                                           SDL_Texture * texture,
 5115                                           const SDL_Rect * srcrect,
 5116                                           const SDL_Rect * dstrect);
 5117
 5118extern DECLSPEC int SDLCALL SDL_RenderCopyEx(SDL_Renderer * renderer,
 5119                                           SDL_Texture * texture,
 5120                                           const SDL_Rect * srcrect,
 5121                                           const SDL_Rect * dstrect,
 5122                                           const double angle,
 5123                                           const SDL_Point *center,
 5124                                           const SDL_RendererFlip flip);
 5125
 5126extern DECLSPEC int SDLCALL SDL_RenderReadPixels(SDL_Renderer * renderer,
 5127                                                 const SDL_Rect * rect,
 5128                                                 Uint32 format,
 5129                                                 void *pixels, int pitch);
 5130
 5131extern DECLSPEC void SDLCALL SDL_RenderPresent(SDL_Renderer * renderer);
 5132
 5133extern DECLSPEC void SDLCALL SDL_DestroyTexture(SDL_Texture * texture);
 5134
 5135extern DECLSPEC void SDLCALL SDL_DestroyRenderer(SDL_Renderer * renderer);
 5136
 5137extern DECLSPEC int SDLCALL SDL_GL_BindTexture(SDL_Texture *texture, float *texw, float *texh);
 5138
 5139extern DECLSPEC int SDLCALL SDL_GL_UnbindTexture(SDL_Texture *texture);
 5140
 5141#ifdef __cplusplus
 5142}
 5143#endif
 5144#undef _begin_code_h
 5145
 5146#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__WATCOMC__)  || defined(__BORLANDC__)
 5147#ifdef __BORLANDC__
 5148#pragma nopackwarning
 5149#endif
 5150#pragma pack(pop)
 5151#endif
 5152
 5153#endif
 5154#ifndef _SDL_system_h
 5155#define _SDL_system_h
 5156
 5157#ifdef _begin_code_h
 5158#error Nested inclusion of begin_code.h
 5159#endif
 5160#define _begin_code_h
 5161
 5162#ifndef SDL_DEPRECATED
 5163#  if (__GNUC__ >= 4)
 5164#    define SDL_DEPRECATED __attribute__((deprecated))
 5165#  else
 5166#    define SDL_DEPRECATED
 5167#  endif
 5168#endif
 5169
 5170#ifndef DECLSPEC
 5171# if defined(__WIN32__) || defined(__WINRT__)
 5172#  ifdef __BORLANDC__
 5173#   ifdef BUILD_SDL
 5174#    define DECLSPEC
 5175#   else
 5176#    define DECLSPEC    __declspec(dllimport)
 5177#   endif
 5178#  else
 5179#   define DECLSPEC __declspec(dllexport)
 5180#  endif
 5181# else
 5182#  if defined(__GNUC__) && __GNUC__ >= 4
 5183#   define DECLSPEC __attribute__ ((visibility("default")))
 5184#  elif defined(__GNUC__) && __GNUC__ >= 2
 5185#   define DECLSPEC __declspec(dllexport)
 5186#  else
 5187#   define DECLSPEC
 5188#  endif
 5189# endif
 5190#endif
 5191
 5192#ifndef SDLCALL
 5193#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
 5194#define SDLCALL __cdecl
 5195#else
 5196#define SDLCALL
 5197#endif
 5198#endif
 5199
 5200#ifdef __SYMBIAN32__
 5201#undef DECLSPEC
 5202#define DECLSPEC
 5203#endif
 5204
 5205#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
 5206#ifdef _MSC_VER
 5207#pragma warning(disable: 4103)
 5208#endif
 5209#ifdef __BORLANDC__
 5210#pragma nopackwarning
 5211#endif
 5212#ifdef _M_X64
 5213
 5214#pragma pack(push,8)
 5215#else
 5216#pragma pack(push,4)
 5217#endif
 5218#endif
 5219
 5220#ifndef SDL_INLINE
 5221#if defined(__GNUC__)
 5222#define SDL_INLINE __inline__
 5223#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
 5224      defined(__DMC__) || defined(__SC__) || \
 5225      defined(__WATCOMC__) || defined(__LCC__) || \
 5226      defined(__DECC)
 5227#define SDL_INLINE __inline
 5228#ifndef __inline__
 5229#define __inline__ __inline
 5230#endif
 5231#else
 5232#define SDL_INLINE inline
 5233#ifndef __inline__
 5234#define __inline__ inline
 5235#endif
 5236#endif
 5237#endif
 5238
 5239#ifndef SDL_FORCE_INLINE
 5240#if defined(_MSC_VER)
 5241#define SDL_FORCE_INLINE __forceinline
 5242#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
 5243#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
 5244#else
 5245#define SDL_FORCE_INLINE static SDL_INLINE
 5246#endif
 5247#endif
 5248
 5249#if !defined(__MACH__)
 5250#ifndef NULL
 5251#ifdef __cplusplus
 5252#define NULL 0
 5253#else
 5254#define NULL ((void *)0)
 5255#endif
 5256#endif
 5257#endif
 5258
 5259#ifdef __cplusplus
 5260extern "C" {
 5261#endif
 5262
 5263#ifdef __WIN32__
 5264
 5265extern DECLSPEC int SDLCALL SDL_Direct3D9GetAdapterIndex( int displayIndex );
 5266
 5267typedef struct IDirect3DDevice9 IDirect3DDevice9;
 5268extern DECLSPEC IDirect3DDevice9* SDLCALL SDL_RenderGetD3D9Device(SDL_Renderer * renderer);
 5269
 5270extern DECLSPEC void SDLCALL SDL_DXGIGetOutputInfo( int displayIndex, int *adapterIndex, int *outputIndex );
 5271
 5272#endif
 5273
 5274#if defined(__IPHONEOS__) && __IPHONEOS__
 5275
 5276extern DECLSPEC int SDLCALL SDL_iPhoneSetAnimationCallback(SDL_Window * window, int interval, void (*callback)(void*), void *callbackParam);
 5277extern DECLSPEC void SDLCALL SDL_iPhoneSetEventPump(SDL_bool enabled);
 5278
 5279#endif
 5280
 5281#if defined(__ANDROID__) && __ANDROID__
 5282
 5283extern DECLSPEC void * SDLCALL SDL_AndroidGetJNIEnv();
 5284
 5285extern DECLSPEC void * SDLCALL SDL_AndroidGetActivity();
 5286
 5287#define SDL_ANDROID_EXTERNAL_STORAGE_READ   0x01
 5288#define SDL_ANDROID_EXTERNAL_STORAGE_WRITE  0x02
 5289
 5290extern DECLSPEC const char * SDLCALL SDL_AndroidGetInternalStoragePath();
 5291
 5292extern DECLSPEC int SDLCALL SDL_AndroidGetExternalStorageState();
 5293
 5294extern DECLSPEC const char * SDLCALL SDL_AndroidGetExternalStoragePath();
 5295
 5296#endif
 5297
 5298#if defined(__WINRT__) && __WINRT__
 5299
 5300typedef enum
 5301{
 5302
 5303    SDL_WINRT_PATH_INSTALLED_LOCATION,
 5304
 5305    SDL_WINRT_PATH_LOCAL_FOLDER,
 5306
 5307    SDL_WINRT_PATH_ROAMING_FOLDER,
 5308
 5309    SDL_WINRT_PATH_TEMP_FOLDER
 5310} SDL_WinRT_Path;
 5311
 5312extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType);
 5313
 5314extern DECLSPEC const char * SDLCALL SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType);
 5315
 5316#endif
 5317
 5318#ifdef __cplusplus
 5319}
 5320#endif
 5321#undef _begin_code_h
 5322
 5323#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__WATCOMC__)  || defined(__BORLANDC__)
 5324#ifdef __BORLANDC__
 5325#pragma nopackwarning
 5326#endif
 5327#pragma pack(pop)
 5328#endif
 5329
 5330#endif
 5331#ifndef _SDL_timer_h
 5332#define _SDL_timer_h
 5333
 5334#ifdef _begin_code_h
 5335#error Nested inclusion of begin_code.h
 5336#endif
 5337#define _begin_code_h
 5338
 5339#ifndef SDL_DEPRECATED
 5340#  if (__GNUC__ >= 4)
 5341#    define SDL_DEPRECATED __attribute__((deprecated))
 5342#  else
 5343#    define SDL_DEPRECATED
 5344#  endif
 5345#endif
 5346
 5347#ifndef DECLSPEC
 5348# if defined(__WIN32__) || defined(__WINRT__)
 5349#  ifdef __BORLANDC__
 5350#   ifdef BUILD_SDL
 5351#    define DECLSPEC
 5352#   else
 5353#    define DECLSPEC    __declspec(dllimport)
 5354#   endif
 5355#  else
 5356#   define DECLSPEC __declspec(dllexport)
 5357#  endif
 5358# else
 5359#  if defined(__GNUC__) && __GNUC__ >= 4
 5360#   define DECLSPEC __attribute__ ((visibility("default")))
 5361#  elif defined(__GNUC__) && __GNUC__ >= 2
 5362#   define DECLSPEC __declspec(dllexport)
 5363#  else
 5364#   define DECLSPEC
 5365#  endif
 5366# endif
 5367#endif
 5368
 5369#ifndef SDLCALL
 5370#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
 5371#define SDLCALL __cdecl
 5372#else
 5373#define SDLCALL
 5374#endif
 5375#endif
 5376
 5377#ifdef __SYMBIAN32__
 5378#undef DECLSPEC
 5379#define DECLSPEC
 5380#endif
 5381
 5382#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
 5383#ifdef _MSC_VER
 5384#pragma warning(disable: 4103)
 5385#endif
 5386#ifdef __BORLANDC__
 5387#pragma nopackwarning
 5388#endif
 5389#ifdef _M_X64
 5390
 5391#pragma pack(push,8)
 5392#else
 5393#pragma pack(push,4)
 5394#endif
 5395#endif
 5396
 5397#ifndef SDL_INLINE
 5398#if defined(__GNUC__)
 5399#define SDL_INLINE __inline__
 5400#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
 5401      defined(__DMC__) || defined(__SC__) || \
 5402      defined(__WATCOMC__) || defined(__LCC__) || \
 5403      defined(__DECC)
 5404#define SDL_INLINE __inline
 5405#ifndef __inline__
 5406#define __inline__ __inline
 5407#endif
 5408#else
 5409#define SDL_INLINE inline
 5410#ifndef __inline__
 5411#define __inline__ inline
 5412#endif
 5413#endif
 5414#endif
 5415
 5416#ifndef SDL_FORCE_INLINE
 5417#if defined(_MSC_VER)
 5418#define SDL_FORCE_INLINE __forceinline
 5419#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
 5420#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
 5421#else
 5422#define SDL_FORCE_INLINE static SDL_INLINE
 5423#endif
 5424#endif
 5425
 5426#if !defined(__MACH__)
 5427#ifndef NULL
 5428#ifdef __cplusplus
 5429#define NULL 0
 5430#else
 5431#define NULL ((void *)0)
 5432#endif
 5433#endif
 5434#endif
 5435
 5436#ifdef __cplusplus
 5437extern "C" {
 5438#endif
 5439
 5440extern DECLSPEC Uint32 SDLCALL SDL_GetTicks(void);
 5441
 5442#define SDL_TICKS_PASSED(A, B)  ((Sint32)((B) - (A)) <= 0)
 5443
 5444extern DECLSPEC Uint64 SDLCALL SDL_GetPerformanceCounter(void);
 5445
 5446extern DECLSPEC Uint64 SDLCALL SDL_GetPerformanceFrequency(void);
 5447
 5448extern DECLSPEC void SDLCALL SDL_Delay(Uint32 ms);
 5449
 5450typedef Uint32 (SDLCALL * SDL_TimerCallback) (Uint32 interval, void *param);
 5451
 5452typedef int SDL_TimerID;
 5453
 5454extern DECLSPEC SDL_TimerID SDLCALL SDL_AddTimer(Uint32 interval,
 5455                                                 SDL_TimerCallback callback,
 5456                                                 void *param);
 5457
 5458extern DECLSPEC SDL_bool SDLCALL SDL_RemoveTimer(SDL_TimerID id);
 5459
 5460#ifdef __cplusplus
 5461}
 5462#endif
 5463#undef _begin_code_h
 5464
 5465#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__WATCOMC__)  || defined(__BORLANDC__)
 5466#ifdef __BORLANDC__
 5467#pragma nopackwarning
 5468#endif
 5469#pragma pack(pop)
 5470#endif
 5471
 5472#endif
 5473#ifndef _SDL_version_h
 5474#define _SDL_version_h
 5475
 5476#ifdef _begin_code_h
 5477#error Nested inclusion of begin_code.h
 5478#endif
 5479#define _begin_code_h
 5480
 5481#ifndef SDL_DEPRECATED
 5482#  if (__GNUC__ >= 4)
 5483#    define SDL_DEPRECATED __attribute__((deprecated))
 5484#  else
 5485#    define SDL_DEPRECATED
 5486#  endif
 5487#endif
 5488
 5489#ifndef DECLSPEC
 5490# if defined(__WIN32__) || defined(__WINRT__)
 5491#  ifdef __BORLANDC__
 5492#   ifdef BUILD_SDL
 5493#    define DECLSPEC
 5494#   else
 5495#    define DECLSPEC    __declspec(dllimport)
 5496#   endif
 5497#  else
 5498#   define DECLSPEC __declspec(dllexport)
 5499#  endif
 5500# else
 5501#  if defined(__GNUC__) && __GNUC__ >= 4
 5502#   define DECLSPEC __attribute__ ((visibility("default")))
 5503#  elif defined(__GNUC__) && __GNUC__ >= 2
 5504#   define DECLSPEC __declspec(dllexport)
 5505#  else
 5506#   define DECLSPEC
 5507#  endif
 5508# endif
 5509#endif
 5510
 5511#ifndef SDLCALL
 5512#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
 5513#define SDLCALL __cdecl
 5514#else
 5515#define SDLCALL
 5516#endif
 5517#endif
 5518
 5519#ifdef __SYMBIAN32__
 5520#undef DECLSPEC
 5521#define DECLSPEC
 5522#endif
 5523
 5524#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
 5525#ifdef _MSC_VER
 5526#pragma warning(disable: 4103)
 5527#endif
 5528#ifdef __BORLANDC__
 5529#pragma nopackwarning
 5530#endif
 5531#ifdef _M_X64
 5532
 5533#pragma pack(push,8)
 5534#else
 5535#pragma pack(push,4)
 5536#endif
 5537#endif
 5538
 5539#ifndef SDL_INLINE
 5540#if defined(__GNUC__)
 5541#define SDL_INLINE __inline__
 5542#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
 5543      defined(__DMC__) || defined(__SC__) || \
 5544      defined(__WATCOMC__) || defined(__LCC__) || \
 5545      defined(__DECC)
 5546#define SDL_INLINE __inline
 5547#ifndef __inline__
 5548#define __inline__ __inline
 5549#endif
 5550#else
 5551#define SDL_INLINE inline
 5552#ifndef __inline__
 5553#define __inline__ inline
 5554#endif
 5555#endif
 5556#endif
 5557
 5558#ifndef SDL_FORCE_INLINE
 5559#if defined(_MSC_VER)
 5560#define SDL_FORCE_INLINE __forceinline
 5561#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
 5562#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
 5563#else
 5564#define SDL_FORCE_INLINE static SDL_INLINE
 5565#endif
 5566#endif
 5567
 5568#if !defined(__MACH__)
 5569#ifndef NULL
 5570#ifdef __cplusplus
 5571#define NULL 0
 5572#else
 5573#define NULL ((void *)0)
 5574#endif
 5575#endif
 5576#endif
 5577
 5578#ifdef __cplusplus
 5579extern "C" {
 5580#endif
 5581
 5582typedef struct SDL_version
 5583{
 5584    Uint8 major;
 5585    Uint8 minor;
 5586    Uint8 patch;
 5587} SDL_version;
 5588
 5589#define SDL_MAJOR_VERSION   2
 5590#define SDL_MINOR_VERSION   0
 5591#define SDL_PATCHLEVEL      3
 5592
 5593#define SDL_VERSION(x)                          \
 5594{                                   \
 5595    (x)->major = SDL_MAJOR_VERSION;                 \
 5596    (x)->minor = SDL_MINOR_VERSION;                 \
 5597    (x)->patch = SDL_PATCHLEVEL;                    \
 5598}
 5599
 5600#define SDL_VERSIONNUM(X, Y, Z)                     \
 5601    ((X)*1000 + (Y)*100 + (Z))
 5602
 5603#define SDL_COMPILEDVERSION \
 5604    SDL_VERSIONNUM(SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL)
 5605
 5606#define SDL_VERSION_ATLEAST(X, Y, Z) \
 5607    (SDL_COMPILEDVERSION >= SDL_VERSIONNUM(X, Y, Z))
 5608
 5609extern DECLSPEC void SDLCALL SDL_GetVersion(SDL_version * ver);
 5610
 5611extern DECLSPEC const char *SDLCALL SDL_GetRevision(void);
 5612
 5613extern DECLSPEC int SDLCALL SDL_GetRevisionNumber(void);
 5614
 5615#ifdef __cplusplus
 5616}
 5617#endif
 5618#undef _begin_code_h
 5619
 5620#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__WATCOMC__)  || defined(__BORLANDC__)
 5621#ifdef __BORLANDC__
 5622#pragma nopackwarning
 5623#endif
 5624#pragma pack(pop)
 5625#endif
 5626
 5627#endif
 5628
 5629#ifdef _begin_code_h
 5630#error Nested inclusion of begin_code.h
 5631#endif
 5632#define _begin_code_h
 5633
 5634#ifndef SDL_DEPRECATED
 5635#  if (__GNUC__ >= 4)
 5636#    define SDL_DEPRECATED __attribute__((deprecated))
 5637#  else
 5638#    define SDL_DEPRECATED
 5639#  endif
 5640#endif
 5641
 5642#ifndef DECLSPEC
 5643# if defined(__WIN32__) || defined(__WINRT__)
 5644#  ifdef __BORLANDC__
 5645#   ifdef BUILD_SDL
 5646#    define DECLSPEC
 5647#   else
 5648#    define DECLSPEC    __declspec(dllimport)
 5649#   endif
 5650#  else
 5651#   define DECLSPEC __declspec(dllexport)
 5652#  endif
 5653# else
 5654#  if defined(__GNUC__) && __GNUC__ >= 4
 5655#   define DECLSPEC __attribute__ ((visibility("default")))
 5656#  elif defined(__GNUC__) && __GNUC__ >= 2
 5657#   define DECLSPEC __declspec(dllexport)
 5658#  else
 5659#   define DECLSPEC
 5660#  endif
 5661# endif
 5662#endif
 5663
 5664#ifndef SDLCALL
 5665#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
 5666#define SDLCALL __cdecl
 5667#else
 5668#define SDLCALL
 5669#endif
 5670#endif
 5671
 5672#ifdef __SYMBIAN32__
 5673#undef DECLSPEC
 5674#define DECLSPEC
 5675#endif
 5676
 5677#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
 5678#ifdef _MSC_VER
 5679#pragma warning(disable: 4103)
 5680#endif
 5681#ifdef __BORLANDC__
 5682#pragma nopackwarning
 5683#endif
 5684#ifdef _M_X64
 5685
 5686#pragma pack(push,8)
 5687#else
 5688#pragma pack(push,4)
 5689#endif
 5690#endif
 5691
 5692#ifndef SDL_INLINE
 5693#if defined(__GNUC__)
 5694#define SDL_INLINE __inline__
 5695#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
 5696      defined(__DMC__) || defined(__SC__) || \
 5697      defined(__WATCOMC__) || defined(__LCC__) || \
 5698      defined(__DECC)
 5699#define SDL_INLINE __inline
 5700#ifndef __inline__
 5701#define __inline__ __inline
 5702#endif
 5703#else
 5704#define SDL_INLINE inline
 5705#ifndef __inline__
 5706#define __inline__ inline
 5707#endif
 5708#endif
 5709#endif
 5710
 5711#ifndef SDL_FORCE_INLINE
 5712#if defined(_MSC_VER)
 5713#define SDL_FORCE_INLINE __forceinline
 5714#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
 5715#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
 5716#else
 5717#define SDL_FORCE_INLINE static SDL_INLINE
 5718#endif
 5719#endif
 5720
 5721#if !defined(__MACH__)
 5722#ifndef NULL
 5723#ifdef __cplusplus
 5724#define NULL 0
 5725#else
 5726#define NULL ((void *)0)
 5727#endif
 5728#endif
 5729#endif
 5730
 5731#ifdef __cplusplus
 5732extern "C" {
 5733#endif
 5734
 5735#define SDL_INIT_TIMER          0x00000001
 5736#define SDL_INIT_AUDIO          0x00000010
 5737#define SDL_INIT_VIDEO          0x00000020
 5738#define SDL_INIT_JOYSTICK       0x00000200
 5739#define SDL_INIT_HAPTIC         0x00001000
 5740#define SDL_INIT_GAMECONTROLLER 0x00002000
 5741#define SDL_INIT_EVENTS         0x00004000
 5742#define SDL_INIT_NOPARACHUTE    0x00100000
 5743#define SDL_INIT_EVERYTHING ( \
 5744                SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTS | \
 5745                SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER \
 5746            )
 5747
 5748extern DECLSPEC int SDLCALL SDL_Init(Uint32 flags);
 5749
 5750extern DECLSPEC int SDLCALL SDL_InitSubSystem(Uint32 flags);
 5751
 5752extern DECLSPEC void SDLCALL SDL_QuitSubSystem(Uint32 flags);
 5753
 5754extern DECLSPEC Uint32 SDLCALL SDL_WasInit(Uint32 flags);
 5755
 5756extern DECLSPEC void SDLCALL SDL_Quit(void);
 5757
 5758#ifdef __cplusplus
 5759}
 5760#endif
 5761#undef _begin_code_h
 5762
 5763#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__WATCOMC__)  || defined(__BORLANDC__)
 5764#ifdef __BORLANDC__
 5765#pragma nopackwarning
 5766#endif
 5767#pragma pack(pop)
 5768#endif
 5769
 5770#endif
 5771#ifndef _SDL_internal_h
 5772#define _SDL_internal_h
 5773
 5774#endif
 5775#ifndef _SDL_internal_h
 5776#define _SDL_internal_h
 5777
 5778#endif
 5779
 5780#ifndef _SDL_error_c_h
 5781#define _SDL_error_c_h
 5782
 5783#define ERR_MAX_STRLEN  128
 5784#define ERR_MAX_ARGS    5
 5785
 5786typedef struct SDL_error
 5787{
 5788
 5789    int error;
 5790
 5791    char key[ERR_MAX_STRLEN];
 5792
 5793    int argc;
 5794    union
 5795    {
 5796        void *value_ptr;
 5797#if 0
 5798        unsigned char value_c;
 5799#endif
 5800        int value_i;
 5801        double value_f;
 5802        char buf[ERR_MAX_STRLEN];
 5803    } args[ERR_MAX_ARGS];
 5804} SDL_error;
 5805
 5806extern SDL_error *SDL_GetErrBuf(void);
 5807
 5808#endif
 5809extern SDL_AudioFormat SDL_FirstAudioFormat(SDL_AudioFormat format);
 5810extern SDL_AudioFormat SDL_NextAudioFormat(void);
 5811
 5812extern void SDL_CalculateAudioSpec(SDL_AudioSpec * spec);
 5813
 5814extern int SDLCALL SDL_RunAudio(void *audiop);
 5815
 5816typedef struct
 5817{
 5818    SDL_AudioFormat src_fmt;
 5819    SDL_AudioFormat dst_fmt;
 5820    SDL_AudioFilter filter;
 5821} SDL_AudioTypeFilters;
 5822extern const SDL_AudioTypeFilters sdl_audio_type_filters[];
 5823
 5824typedef struct
 5825{
 5826    SDL_AudioFormat fmt;
 5827    int channels;
 5828    int upsample;
 5829    int multiple;
 5830    SDL_AudioFilter filter;
 5831} SDL_AudioRateFilters;
 5832extern const SDL_AudioRateFilters sdl_audio_rate_filters[];
 5833#ifndef _SDL_sysaudio_h
 5834#define _SDL_sysaudio_h
 5835
 5836typedef struct SDL_AudioDevice SDL_AudioDevice;
 5837#define _THIS   SDL_AudioDevice *_this
 5838
 5839typedef void (*SDL_AddAudioDevice)(const char *name);
 5840
 5841typedef struct SDL_AudioDriverImpl
 5842{
 5843    void (*DetectDevices) (int iscapture, SDL_AddAudioDevice addfn);
 5844    int (*OpenDevice) (_THIS, const char *devname, int iscapture);
 5845    void (*ThreadInit) (_THIS);
 5846    void (*WaitDevice) (_THIS);
 5847    void (*PlayDevice) (_THIS);
 5848    Uint8 *(*GetDeviceBuf) (_THIS);
 5849    void (*WaitDone) (_THIS);
 5850    void (*CloseDevice) (_THIS);
 5851    void (*LockDevice) (_THIS);
 5852    void (*UnlockDevice) (_THIS);
 5853    void (*Deinitialize) (void);
 5854
 5855    int ProvidesOwnCallbackThread;
 5856    int SkipMixerLock;
 5857    int HasCaptureSupport;
 5858    int OnlyHasDefaultOutputDevice;
 5859    int OnlyHasDefaultInputDevice;
 5860} SDL_AudioDriverImpl;
 5861
 5862typedef struct SDL_AudioDriver
 5863{
 5864
 5865    const char *name;
 5866
 5867    const char *desc;
 5868
 5869    SDL_AudioDriverImpl impl;
 5870
 5871    char **outputDevices;
 5872    int outputDeviceCount;
 5873
 5874    char **inputDevices;
 5875    int inputDeviceCount;
 5876} SDL_AudioDriver;
 5877
 5878typedef struct
 5879{
 5880    Uint8 *buffer;
 5881    int max_len;
 5882    int read_pos, write_pos;
 5883} SDL_AudioStreamer;
 5884
 5885struct SDL_AudioDevice
 5886{
 5887
 5888    SDL_AudioSpec spec;
 5889
 5890    SDL_AudioCVT convert;
 5891
 5892    int use_streamer;
 5893    SDL_AudioStreamer streamer;
 5894
 5895    int iscapture;
 5896    int enabled;
 5897    int paused;
 5898    int opened;
 5899
 5900    Uint8 *fake_stream;
 5901
 5902    SDL_mutex *mixer_lock;
 5903
 5904    SDL_Thread *thread;
 5905    SDL_threadID threadid;
 5906
 5907    struct SDL_PrivateAudioData *hidden;
 5908};
 5909#undef _THIS
 5910
 5911typedef struct AudioBootStrap
 5912{
 5913    const char *name;
 5914    const char *desc;
 5915    int (*init) (SDL_AudioDriverImpl * impl);
 5916    int demand_only;
 5917} AudioBootStrap;
 5918
 5919#endif
 5920#ifndef _SDL_thread_c_h
 5921#define _SDL_thread_c_h
 5922
 5923#if SDL_THREADS_DISABLED
 5924typedef int SYS_ThreadHandle;
 5925#elif SDL_THREAD_BEOS
 5926#include "beos/SDL_systhread_c.h"
 5927#elif SDL_THREAD_EPOC
 5928#include "epoc/SDL_systhread_c.h"
 5929#elif SDL_THREAD_PTHREAD
 5930#include <pthread.h>
 5931
 5932typedef pthread_t SYS_ThreadHandle;
 5933#elif SDL_THREAD_WINDOWS
 5934#ifndef _SDL_systhread_c_h
 5935#define _SDL_systhread_c_h
 5936
 5937#ifndef _INCLUDED_WINDOWS_H
 5938#define _INCLUDED_WINDOWS_H
 5939
 5940#if defined(__WIN32__)
 5941#define WIN32_LEAN_AND_MEAN
 5942#define STRICT
 5943#ifndef UNICODE
 5944#define UNICODE 1
 5945#endif
 5946#undef _WIN32_WINNT
 5947#define _WIN32_WINNT  0x501
 5948#endif
 5949
 5950#include <windows.h>
 5951
 5952#if UNICODE
 5953#define WIN_StringToUTF8(S) SDL_iconv_string("UTF-8", "UTF-16LE", (char *)(S), (SDL_wcslen(S)+1)*sizeof(WCHAR))
 5954#define WIN_UTF8ToString(S) (WCHAR *)SDL_iconv_string("UTF-16LE", "UTF-8", (char *)(S), SDL_strlen(S)+1)
 5955#else
 5956
 5957#define WIN_StringToUTF8(S) SDL_iconv_string("UTF-8", "ASCII", (char *)(S), (SDL_strlen(S)+1))
 5958#define WIN_UTF8ToString(S) SDL_iconv_string("ASCII", "UTF-8", (char *)(S), SDL_strlen(S)+1)
 5959#endif
 5960
 5961extern int WIN_SetErrorFromHRESULT(const char *prefix, HRESULT hr);
 5962
 5963extern int WIN_SetError(const char *prefix);
 5964
 5965extern HRESULT WIN_CoInitialize(void);
 5966extern void WIN_CoUninitialize(void);
 5967
 5968#endif
 5969
 5970typedef HANDLE SYS_ThreadHandle;
 5971
 5972#endif
 5973#elif SDL_THREAD_PSP
 5974#include "psp/SDL_systhread_c.h"
 5975#else
 5976#error Need thread implementation for this platform
 5977typedef int SYS_ThreadHandle;
 5978#endif
 5979
 5980struct SDL_Thread
 5981{
 5982    SDL_threadID threadid;
 5983    SYS_ThreadHandle handle;
 5984    int status;
 5985    SDL_error errbuf;
 5986    char *name;
 5987    void *data;
 5988};
 5989
 5990extern void SDL_RunThread(void *data);
 5991
 5992#endif
 5993#ifndef _SDL_systhread_h
 5994#define _SDL_systhread_h
 5995
 5996#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
 5997extern int SDL_SYS_CreateThread(SDL_Thread * thread, void *args,
 5998                                pfnSDL_CurrentBeginThread pfnBeginThread,
 5999                                pfnSDL_CurrentEndThread pfnEndThread);
 6000#else
 6001extern int SDL_SYS_CreateThread(SDL_Thread * thread, void *args);
 6002#endif
 6003
 6004extern void SDL_SYS_SetupThread(const char *name);
 6005
 6006extern int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority);
 6007
 6008extern void SDL_SYS_WaitThread(SDL_Thread * thread);
 6009
 6010#endif
 6011#define ROUND_RESOLUTION(X) \
 6012    (((X+TIMER_RESOLUTION-1)/TIMER_RESOLUTION)*TIMER_RESOLUTION)
 6013
 6014extern void SDL_TicksInit(void);
 6015extern void SDL_TicksQuit(void);
 6016extern int SDL_TimerInit(void);
 6017extern void SDL_TimerQuit(void);
 6018#ifndef _SDL_udev_h
 6019#define _SDL_udev_h
 6020
 6021#if HAVE_LIBUDEV_H
 6022
 6023#ifndef SDL_USE_LIBUDEV
 6024#define SDL_USE_LIBUDEV 1
 6025#endif
 6026
 6027#include <libudev.h>
 6028#include <sys/time.h>
 6029#include <sys/types.h>
 6030
 6031typedef enum
 6032{
 6033    SDL_UDEV_DEVICEADDED = 0x0001,
 6034    SDL_UDEV_DEVICEREMOVED
 6035} SDL_UDEV_deviceevent;
 6036
 6037typedef enum
 6038{
 6039    SDL_UDEV_DEVICE_MOUSE       = 0x0001,
 6040    SDL_UDEV_DEVICE_KEYBOARD    = 0x0002,
 6041    SDL_UDEV_DEVICE_JOYSTICK    = 0x0004,
 6042    SDL_UDEV_DEVICE_SOUND       = 0x0008
 6043} SDL_UDEV_deviceclass;
 6044
 6045typedef void (*SDL_UDEV_Callback)(SDL_UDEV_deviceevent udev_type, int udev_class, const char *devpath);
 6046
 6047typedef struct SDL_UDEV_CallbackList {
 6048    SDL_UDEV_Callback callback;
 6049    struct SDL_UDEV_CallbackList *next;
 6050} SDL_UDEV_CallbackList;
 6051
 6052typedef struct SDL_UDEV_PrivateData
 6053{
 6054    const char *udev_library;
 6055    void *udev_handle;
 6056    struct udev *udev;
 6057    struct udev_monitor *udev_mon;
 6058    int ref_count;
 6059    SDL_UDEV_CallbackList *first, *last;
 6060
 6061    const char *(*udev_device_get_action)(struct udev_device *);
 6062    const char *(*udev_device_get_devnode)(struct udev_device *);
 6063    const char *(*udev_device_get_subsystem)(struct udev_device *);
 6064    const char *(*udev_device_get_property_value)(struct udev_device *, const char *);
 6065    struct udev_device *(*udev_device_new_from_syspath)(struct udev *, const char *);
 6066    void (*udev_device_unref)(struct udev_device *);
 6067    int (*udev_enumerate_add_match_property)(struct udev_enumerate *, const char *, const char *);
 6068    int (*udev_enumerate_add_match_subsystem)(struct udev_enumerate *, const char *);
 6069    struct udev_list_entry *(*udev_enumerate_get_list_entry)(struct udev_enumerate *);
 6070    struct udev_enumerate *(*udev_enumerate_new)(struct udev *);
 6071    int (*udev_enumerate_scan_devices)(struct udev_enumerate *);
 6072    void (*udev_enumerate_unref)(struct udev_enumerate *);
 6073    const char *(*udev_list_entry_get_name)(struct udev_list_entry *);
 6074    struct udev_list_entry *(*udev_list_entry_get_next)(struct udev_list_entry *);
 6075    int (*udev_monitor_enable_receiving)(struct udev_monitor *);
 6076    int (*udev_monitor_filter_add_match_subsystem_devtype)(struct udev_monitor *, const char *, const char *);
 6077    int (*udev_monitor_get_fd)(struct udev_monitor *);
 6078    struct udev_monitor *(*udev_monitor_new_from_netlink)(struct udev *, const char *);
 6079    struct udev_device *(*udev_monitor_receive_device)(struct udev_monitor *);
 6080    void (*udev_monitor_unref)(struct udev_monitor *);
 6081    struct udev *(*udev_new)(void);
 6082    void (*udev_unref)(struct udev *);
 6083    struct udev_device * (*udev_device_new_from_devnum)(struct udev *udev, char type, dev_t devnum);
 6084    dev_t (*udev_device_get_devnum) (struct udev_device *udev_device);
 6085} SDL_UDEV_PrivateData;
 6086
 6087extern int SDL_UDEV_Init(void);
 6088extern void SDL_UDEV_Quit(void);
 6089extern void SDL_UDEV_UnloadLibrary(void);
 6090extern int SDL_UDEV_LoadLibrary(void);
 6091extern void SDL_UDEV_Poll(void);
 6092extern void SDL_UDEV_Scan(void);
 6093extern int SDL_UDEV_AddCallback(SDL_UDEV_Callback cb);
 6094extern void SDL_UDEV_DelCallback(SDL_UDEV_Callback cb);
 6095
 6096#endif
 6097
 6098#endif
 6099
 6100#ifdef SDL_USE_LIBUDEV
 6101
 6102static char* SDL_UDEV_LIBS[] = { "libudev.so.1", "libudev.so.0" };
 6103
 6104#undef _THIS
 6105#define _THIS SDL_UDEV_PrivateData *_this
 6106static _THIS = NULL;
 6107
 6108static SDL_bool SDL_UDEV_load_sym(const char *fn, void **addr);
 6109static int SDL_UDEV_load_syms(void);
 6110static SDL_bool SDL_UDEV_hotplug_update_available(void);
 6111static void device_event(SDL_UDEV_deviceevent type, struct udev_device *dev);
 6112
 6113static SDL_bool
 6114SDL_UDEV_load_sym(const char *fn, void **addr)
 6115{
 6116    *addr = SDL_LoadFunction(_this->udev_handle, fn);
 6117    if (*addr == NULL) {
 6118
 6119        return SDL_FALSE;
 6120    }
 6121
 6122    return SDL_TRUE;
 6123}
 6124
 6125static int
 6126SDL_UDEV_load_syms(void)
 6127{
 6128
 6129    #define SDL_UDEV_SYM(x) \
 6130        if (!SDL_UDEV_load_sym(#x, (void **) (char *) & _this->x)) return -1
 6131
 6132    SDL_UDEV_SYM(udev_device_get_action);
 6133    SDL_UDEV_SYM(udev_device_get_devnode);
 6134    SDL_UDEV_SYM(udev_device_get_subsystem);
 6135    SDL_UDEV_SYM(udev_device_get_property_value);
 6136    SDL_UDEV_SYM(udev_device_new_from_syspath);
 6137    SDL_UDEV_SYM(udev_device_unref);
 6138    SDL_UDEV_SYM(udev_enumerate_add_match_property);
 6139    SDL_UDEV_SYM(udev_enumerate_add_match_subsystem);
 6140    SDL_UDEV_SYM(udev_enumerate_get_list_entry);
 6141    SDL_UDEV_SYM(udev_enumerate_new);
 6142    SDL_UDEV_SYM(udev_enumerate_scan_devices);
 6143    SDL_UDEV_SYM(udev_enumerate_unref);
 6144    SDL_UDEV_SYM(udev_list_entry_get_name);
 6145    SDL_UDEV_SYM(udev_list_entry_get_next);
 6146    SDL_UDEV_SYM(udev_monitor_enable_receiving);
 6147    SDL_UDEV_SYM(udev_monitor_filter_add_match_subsystem_devtype);
 6148    SDL_UDEV_SYM(udev_monitor_get_fd);
 6149    SDL_UDEV_SYM(udev_monitor_new_from_netlink);
 6150    SDL_UDEV_SYM(udev_monitor_receive_device);
 6151    SDL_UDEV_SYM(udev_monitor_unref);
 6152    SDL_UDEV_SYM(udev_new);
 6153    SDL_UDEV_SYM(udev_unref);
 6154    SDL_UDEV_SYM(udev_device_new_from_devnum);
 6155    SDL_UDEV_SYM(udev_device_get_devnum);
 6156    #undef SDL_UDEV_SYM
 6157
 6158    return 0;
 6159}
 6160
 6161static SDL_bool
 6162SDL_UDEV_hotplug_update_available(void)
 6163{
 6164    if (_this->udev_mon != NULL) {
 6165        const int fd = _this->udev_monitor_get_fd(_this->udev_mon);
 6166        fd_set fds;
 6167        struct timeval tv;
 6168
 6169        FD_ZERO(&fds);
 6170        FD_SET(fd, &fds);
 6171        tv.tv_sec = 0;
 6172        tv.tv_usec = 0;
 6173        if ((select(fd+1, &fds, NULL, NULL, &tv) > 0) && (FD_ISSET(fd, &fds))) {
 6174            return SDL_TRUE;
 6175        }
 6176    }
 6177    return SDL_FALSE;
 6178}
 6179
 6180int
 6181SDL_UDEV_Init(void)
 6182{
 6183    int retval = 0;
 6184
 6185    if (_this == NULL) {
 6186        _this = (SDL_UDEV_PrivateData *) SDL_calloc(1, sizeof(*_this));
 6187        if(_this == NULL) {
 6188            return SDL_OutOfMemory();
 6189        }
 6190
 6191        retval = SDL_UDEV_LoadLibrary();
 6192        if (retval < 0) {
 6193            SDL_UDEV_Quit();
 6194            return retval;
 6195        }
 6196
 6197        _this->udev = _this->udev_new();
 6198        if (_this->udev == NULL) {
 6199            SDL_UDEV_Quit();
 6200            return SDL_SetError("udev_new() failed");
 6201        }
 6202
 6203        _this->udev_mon = _this->udev_monitor_new_from_netlink(_this->udev, "udev");
 6204        if (_this->udev_mon == NULL) {
 6205            SDL_UDEV_Quit();
 6206            return SDL_SetError("udev_monitor_new_from_netlink() failed");
 6207        }
 6208
 6209        _this->udev_monitor_filter_add_match_subsystem_devtype(_this->udev_mon, "input", NULL);
 6210        _this->udev_monitor_filter_add_match_subsystem_devtype(_this->udev_mon, "sound", NULL);
 6211        _this->udev_monitor_enable_receiving(_this->udev_mon);
 6212
 6213        SDL_UDEV_Scan();
 6214
 6215    }
 6216
 6217    _this->ref_count += 1;
 6218
 6219    return retval;
 6220}
 6221
 6222void
 6223SDL_UDEV_Quit(void)
 6224{
 6225    SDL_UDEV_CallbackList *item;
 6226
 6227    if (_this == NULL) {
 6228        return;
 6229    }
 6230
 6231    _this->ref_count -= 1;
 6232
 6233    if (_this->ref_count < 1) {
 6234
 6235        if (_this->udev_mon != NULL) {
 6236            _this->udev_monitor_unref(_this->udev_mon);
 6237            _this->udev_mon = NULL;
 6238        }
 6239        if (_this->udev != NULL) {
 6240            _this->udev_unref(_this->udev);
 6241            _this->udev = NULL;
 6242        }
 6243
 6244        while (_this->first != NULL) {
 6245            item = _this->first;
 6246            _this->first = _this->first->next;
 6247            SDL_free(item);
 6248        }
 6249
 6250        SDL_UDEV_UnloadLibrary();
 6251        SDL_free(_this);
 6252        _this = NULL;
 6253    }
 6254}
 6255
 6256void
 6257SDL_UDEV_Scan(void)
 6258{
 6259    struct udev_enumerate *enumerate = NULL;
 6260    struct udev_list_entry *devs = NULL;
 6261    struct udev_list_entry *item = NULL;
 6262
 6263    if (_this == NULL) {
 6264        return;
 6265    }
 6266
 6267    enumerate = _this->udev_enumerate_new(_this->udev);
 6268    if (enumerate == NULL) {
 6269        SDL_UDEV_Quit();
 6270        SDL_SetError("udev_monitor_new_from_netlink() failed");
 6271        return;
 6272    }
 6273
 6274    _this->udev_enumerate_add_match_subsystem(enumerate, "input");
 6275    _this->udev_enumerate_add_match_subsystem(enumerate, "sound");
 6276
 6277    _this->udev_enumerate_scan_devices(enumerate);
 6278    devs = _this->udev_enumerate_get_list_entry(enumerate);
 6279    for (item = devs; item; item = _this->udev_list_entry_get_next(item)) {
 6280        const char *path = _this->udev_list_entry_get_name(item);
 6281        struct udev_device *dev = _this->udev_device_new_from_syspath(_this->udev, path);
 6282        if (dev != NULL) {
 6283            device_event(SDL_UDEV_DEVICEADDED, dev);
 6284            _this->udev_device_unref(dev);
 6285        }
 6286    }
 6287
 6288    _this->udev_enumerate_unref(enumerate);
 6289}
 6290
 6291void
 6292SDL_UDEV_UnloadLibrary(void)
 6293{
 6294    if (_this == NULL) {
 6295        return;
 6296    }
 6297
 6298    if (_this->udev_handle != NULL) {
 6299        SDL_UnloadObject(_this->udev_handle);
 6300        _this->udev_handle = NULL;
 6301    }
 6302}
 6303
 6304int
 6305SDL_UDEV_LoadLibrary(void)
 6306{
 6307    int retval = 0, i;
 6308
 6309    if (_this == NULL) {
 6310        return SDL_SetError("UDEV not initialized");
 6311    }
 6312
 6313    if (_this->udev_handle == NULL) {
 6314        for( i = 0 ; i < SDL_arraysize(SDL_UDEV_LIBS); i++) {
 6315            _this->udev_handle = SDL_LoadObject(SDL_UDEV_LIBS[i]);
 6316            if (_this->udev_handle != NULL) {
 6317                retval = SDL_UDEV_load_syms();
 6318                if (retval < 0) {
 6319                    SDL_UDEV_UnloadLibrary();
 6320                }
 6321                else {
 6322                    break;
 6323                }
 6324            }
 6325        }
 6326
 6327        if (_this->udev_handle == NULL) {
 6328            retval = -1;
 6329
 6330        }
 6331    }
 6332
 6333    return retval;
 6334}
 6335
 6336static void
 6337device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
 6338{
 6339    const char *subsystem;
 6340    const char *val = NULL;
 6341    int devclass = 0;
 6342    const char *path;
 6343    SDL_UDEV_CallbackList *item;
 6344
 6345    path = _this->udev_device_get_devnode(dev);
 6346    if (path == NULL) {
 6347        return;
 6348    }
 6349
 6350    subsystem = _this->udev_device_get_subsystem(dev);
 6351    if (SDL_strcmp(subsystem, "sound") == 0) {
 6352        devclass = SDL_UDEV_DEVICE_SOUND;
 6353    } else if (SDL_strcmp(subsystem, "input") == 0) {
 6354        val = _this->udev_device_get_property_value(dev, "ID_INPUT_JOYSTICK");
 6355        if (val != NULL && SDL_strcmp(val, "1") == 0 ) {
 6356            devclass |= SDL_UDEV_DEVICE_JOYSTICK;
 6357        }
 6358
 6359        val = _this->udev_device_get_property_value(dev, "ID_INPUT_MOUSE");
 6360        if (val != NULL && SDL_strcmp(val, "1") == 0 ) {
 6361            devclass |= SDL_UDEV_DEVICE_MOUSE;
 6362        }
 6363
 6364        val = _this->udev_device_get_property_value(dev, "ID_INPUT_KEYBOARD");
 6365        if (val != NULL && SDL_strcmp(val, "1") == 0 ) {
 6366            devclass |= SDL_UDEV_DEVICE_KEYBOARD;
 6367        }
 6368
 6369        if (devclass == 0) {
 6370            return;
 6371        }
 6372    } else {
 6373        return;
 6374    }
 6375
 6376    for (item = _this->first; item != NULL; item = item->next) {
 6377        item->callback(type, devclass, path);
 6378    }
 6379}
 6380
 6381void
 6382SDL_UDEV_Poll(void)
 6383{
 6384    struct udev_device *dev = NULL;
 6385    const char *action = NULL;
 6386
 6387    if (_this == NULL) {
 6388        return;
 6389    }
 6390
 6391    while (SDL_UDEV_hotplug_update_available()) {
 6392        dev = _this->udev_monitor_receive_device(_this->udev_mon);
 6393        if (dev == NULL) {
 6394            break;
 6395        }
 6396        action = _this->udev_device_get_action(dev);
 6397
 6398        if (SDL_strcmp(action, "add") == 0) {
 6399            device_event(SDL_UDEV_DEVICEADDED, dev);
 6400        } else if (SDL_strcmp(action, "remove") == 0) {
 6401            device_event(SDL_UDEV_DEVICEREMOVED, dev);
 6402        }
 6403
 6404        _this->udev_device_unref(dev);
 6405    }
 6406}
 6407
 6408int
 6409SDL_UDEV_AddCallback(SDL_UDEV_Callback cb)
 6410{
 6411    SDL_UDEV_CallbackList *item;
 6412    item = (SDL_UDEV_CallbackList *) SDL_calloc(1, sizeof (SDL_UDEV_CallbackList));
 6413    if (item == NULL) {
 6414        return SDL_OutOfMemory();
 6415    }
 6416
 6417    item->callback = cb;
 6418
 6419    if (_this->last == NULL) {
 6420        _this->first = _this->last = item;
 6421    } else {
 6422        _this->last->next = item;
 6423        _this->last = item;
 6424    }
 6425
 6426    return 1;
 6427}
 6428
 6429void
 6430SDL_UDEV_DelCallback(SDL_UDEV_Callback cb)
 6431{
 6432    SDL_UDEV_CallbackList *item;
 6433    SDL_UDEV_CallbackList *prev = NULL;
 6434
 6435    for (item = _this->first; item != NULL; item = item->next) {
 6436
 6437        if (item->callback == cb) {
 6438            if (prev != NULL) {
 6439                prev->next = item->next;
 6440            } else {
 6441                SDL_assert(_this->first == item);
 6442                _this->first = item->next;
 6443            }
 6444            if (item == _this->last) {
 6445                _this->last = prev;
 6446            }
 6447            SDL_free(item);
 6448            return;
 6449        }
 6450        prev = item;
 6451    }
 6452
 6453}
 6454
 6455#endif
 6456#ifdef SDL_LOADSO_DLOPEN
 6457
 6458#include <stdio.h>
 6459#include <dlfcn.h>
 6460
 6461void *
 6462SDL_LoadObject(const char *sofile)
 6463{
 6464    void *handle = dlopen(sofile, RTLD_NOW|RTLD_LOCAL);
 6465    const char *loaderror = (char *) dlerror();
 6466    if (handle == NULL) {
 6467        SDL_SetError("Failed loading %s: %s", sofile, loaderror);
 6468    }
 6469    return (handle);
 6470}
 6471
 6472void *
 6473SDL_LoadFunction(void *handle, const char *name)
 6474{
 6475    void *symbol = dlsym(handle, name);
 6476    if (symbol == NULL) {
 6477
 6478        size_t len = 1 + SDL_strlen(name) + 1;
 6479        char *_name = SDL_stack_alloc(char, len);
 6480        _name[0] = '_';
 6481        SDL_strlcpy(&_name[1], name, len);
 6482        symbol = dlsym(handle, _name);
 6483        SDL_stack_free(_name);
 6484        if (symbol == NULL) {
 6485            SDL_SetError("Failed loading %s: %s", name,
 6486                         (const char *) dlerror());
 6487        }
 6488    }
 6489    return (symbol);
 6490}
 6491
 6492void
 6493SDL_UnloadObject(void *handle)
 6494{
 6495    if (handle != NULL) {
 6496        dlclose(handle);
 6497    }
 6498}
 6499
 6500#endif
 6501#if defined(SDL_LOADSO_DUMMY) || defined(SDL_LOADSO_DISABLED)
 6502
 6503void *
 6504SDL_LoadObject(const char *sofile)
 6505{
 6506    const char *loaderror = "SDL_LoadObject() not implemented";
 6507    SDL_SetError("Failed loading %s: %s", sofile, loaderror);
 6508    return (NULL);
 6509}
 6510
 6511void *
 6512SDL_LoadFunction(void *handle, const char *name)
 6513{
 6514    const char *loaderror = "SDL_LoadFunction() not implemented";
 6515    SDL_SetError("Failed loading %s: %s", name, loaderror);
 6516    return (NULL);
 6517}
 6518
 6519void
 6520SDL_UnloadObject(void *handle)
 6521{
 6522
 6523}
 6524
 6525#endif
 6526#ifdef SDL_LOADSO_WINDOWS
 6527
 6528void *
 6529SDL_LoadObject(const char *sofile)
 6530{
 6531    LPTSTR tstr = WIN_UTF8ToString(sofile);
 6532#ifdef __WINRT__
 6533
 6534    void *handle = (void *) LoadPackagedLibrary(tstr, 0);
 6535#else
 6536    void *handle = (void *) LoadLibrary(tstr);
 6537#endif
 6538    SDL_free(tstr);
 6539
 6540    if (handle == NULL) {
 6541        char errbuf[512];
 6542        SDL_strlcpy(errbuf, "Failed loading ", SDL_arraysize(errbuf));
 6543        SDL_strlcat(errbuf, sofile, SDL_arraysize(errbuf));
 6544        WIN_SetError(errbuf);
 6545    }
 6546    return handle;
 6547}
 6548
 6549void *
 6550SDL_LoadFunction(void *handle, const char *name)
 6551{
 6552    void *symbol = (void *) GetProcAddress((HMODULE) handle, name);
 6553    if (symbol == NULL) {
 6554        char errbuf[512];
 6555        SDL_strlcpy(errbuf, "Failed loading ", SDL_arraysize(errbuf));
 6556        SDL_strlcat(errbuf, name, SDL_arraysize(errbuf));
 6557        WIN_SetError(errbuf);
 6558    }
 6559    return symbol;
 6560}
 6561
 6562void
 6563SDL_UnloadObject(void *handle)
 6564{
 6565    if (handle != NULL) {
 6566        FreeLibrary((HMODULE) handle);
 6567    }
 6568}
 6569
 6570#endif
 6571#if SDL_AUDIO_DRIVER_ALSA
 6572
 6573#include <sys/types.h>
 6574#include <signal.h>
 6575#include <errno.h>
 6576#include <string.h>
 6577
 6578#define SDL_AllocAudioMem   SDL_malloc
 6579#define SDL_FreeAudioMem    SDL_free
 6580#ifndef _SDL_ALSA_audio_h
 6581#define _SDL_ALSA_audio_h
 6582
 6583#include <alsa/asoundlib.h>
 6584
 6585#undef _THIS
 6586#define _THIS   SDL_AudioDevice *this
 6587
 6588#undef SDLAUDIOHIDDEN
 6589#define SDLAUDIOHIDDEN ((struct SDL_PrivateAudioDataALSA*)this->hidden)
 6590struct SDL_PrivateAudioDataALSA
 6591{
 6592
 6593    snd_pcm_t *pcm_handle;
 6594
 6595    Uint8 *mixbuf;
 6596    int mixlen;
 6597};
 6598
 6599#endif
 6600
 6601#ifdef SDL_AUDIO_DRIVER_ALSA_DYNAMIC
 6602#endif
 6603
 6604static int (*ALSA_snd_pcm_open)
 6605  (snd_pcm_t **, const char *, snd_pcm_stream_t, int);
 6606static int (*ALSA_snd_pcm_close) (snd_pcm_t * pcm);
 6607static snd_pcm_sframes_t(*ALSA_snd_pcm_writei)
 6608  (snd_pcm_t *, const void *, snd_pcm_uframes_t);
 6609static int (*ALSA_snd_pcm_recover) (snd_pcm_t *, int, int);
 6610static int (*ALSA_snd_pcm_prepare) (snd_pcm_t *);
 6611static int (*ALSA_snd_pcm_drain) (snd_pcm_t *);
 6612static const char *(*ALSA_snd_strerror) (int);
 6613static size_t(*ALSA_snd_pcm_hw_params_sizeof) (void);
 6614static size_t(*ALSA_snd_pcm_sw_params_sizeof) (void);
 6615static void (*ALSA_snd_pcm_hw_params_copy)
 6616  (snd_pcm_hw_params_t *, const snd_pcm_hw_params_t *);
 6617static int (*ALSA_snd_pcm_hw_params_any) (snd_pcm_t *, snd_pcm_hw_params_t *);
 6618static int (*ALSA_snd_pcm_hw_params_set_access)
 6619  (snd_pcm_t *, snd_pcm_hw_params_t *, snd_pcm_access_t);
 6620static int (*ALSA_snd_pcm_hw_params_set_format)
 6621  (snd_pcm_t *, snd_pcm_hw_params_t *, snd_pcm_format_t);
 6622static int (*ALSA_snd_pcm_hw_params_set_channels)
 6623  (snd_pcm_t *, snd_pcm_hw_params_t *, unsigned int);
 6624static int (*ALSA_snd_pcm_hw_params_get_channels)
 6625  (const snd_pcm_hw_params_t *, unsigned int *);
 6626static int (*ALSA_snd_pcm_hw_params_set_rate_near)
 6627  (snd_pcm_t *, snd_pcm_hw_params_t *, unsigned int *, int *);
 6628static int (*ALSA_snd_pcm_hw_params_set_period_size_near)
 6629  (snd_pcm_t *, snd_pcm_hw_params_t *, snd_pcm_uframes_t *, int *);
 6630static int (*ALSA_snd_pcm_hw_params_get_period_size)
 6631  (const snd_pcm_hw_params_t *, snd_pcm_uframes_t *, int *);
 6632static int (*ALSA_snd_pcm_hw_params_set_periods_near)
 6633  (snd_pcm_t *, snd_pcm_hw_params_t *, unsigned int *, int *);
 6634static int (*ALSA_snd_pcm_hw_params_get_periods)
 6635  (const snd_pcm_hw_params_t *, unsigned int *, int *);
 6636static int (*ALSA_snd_pcm_hw_params_set_buffer_size_near)
 6637  (snd_pcm_t *pcm, snd_pcm_hw_params_t *, snd_pcm_uframes_t *);
 6638static int (*ALSA_snd_pcm_hw_params_get_buffer_size)
 6639  (const snd_pcm_hw_params_t *, snd_pcm_uframes_t *);
 6640static int (*ALSA_snd_pcm_hw_params) (snd_pcm_t *, snd_pcm_hw_params_t *);
 6641static int (*ALSA_snd_pcm_sw_params_current) (snd_pcm_t *,
 6642                                              snd_pcm_sw_params_t *);
 6643static int (*ALSA_snd_pcm_sw_params_set_start_threshold)
 6644  (snd_pcm_t *, snd_pcm_sw_params_t *, snd_pcm_uframes_t);
 6645static int (*ALSA_snd_pcm_sw_params) (snd_pcm_t *, snd_pcm_sw_params_t *);
 6646static int (*ALSA_snd_pcm_nonblock) (snd_pcm_t *, int);
 6647static int (*ALSA_snd_pcm_wait)(snd_pcm_t *, int);
 6648static int (*ALSA_snd_pcm_sw_params_set_avail_min)
 6649  (snd_pcm_t *, snd_pcm_sw_params_t *, snd_pcm_uframes_t);
 6650
 6651#ifdef SDL_AUDIO_DRIVER_ALSA_DYNAMIC
 6652#define snd_pcm_hw_params_sizeof ALSA_snd_pcm_hw_params_sizeof
 6653#define snd_pcm_sw_params_sizeof ALSA_snd_pcm_sw_params_sizeof
 6654
 6655static const char *alsa_library = SDL_AUDIO_DRIVER_ALSA_DYNAMIC;
 6656static void *alsa_handle = NULL;
 6657
 6658static int
 6659load_alsa_sym(const char *fn, void **addr)
 6660{
 6661    *addr = SDL_LoadFunction(alsa_handle, fn);
 6662    if (*addr == NULL) {
 6663
 6664        return 0;
 6665    }
 6666
 6667    return 1;
 6668}
 6669
 6670#define SDL_ALSA_SYM(x) \
 6671    if (!load_alsa_sym(#x, (void **) (char *) &ALSA_##x)) return -1
 6672#else
 6673#define SDL_ALSA_SYM(x) ALSA_##x = x
 6674#endif
 6675
 6676static int
 6677load_alsa_syms(void)
 6678{
 6679    SDL_ALSA_SYM(snd_pcm_open);
 6680    SDL_ALSA_SYM(snd_pcm_close);
 6681    SDL_ALSA_SYM(snd_pcm_writei);
 6682    SDL_ALSA_SYM(snd_pcm_recover);
 6683    SDL_ALSA_SYM(snd_pcm_prepare);
 6684    SDL_ALSA_SYM(snd_pcm_drain);
 6685    SDL_ALSA_SYM(snd_strerror);
 6686    SDL_ALSA_SYM(snd_pcm_hw_params_sizeof);
 6687    SDL_ALSA_SYM(snd_pcm_sw_params_sizeof);
 6688    SDL_ALSA_SYM(snd_pcm_hw_params_copy);
 6689    SDL_ALSA_SYM(snd_pcm_hw_params_any);
 6690    SDL_ALSA_SYM(snd_pcm_hw_params_set_access);
 6691    SDL_ALSA_SYM(snd_pcm_hw_params_set_format);
 6692    SDL_ALSA_SYM(snd_pcm_hw_params_set_channels);
 6693    SDL_ALSA_SYM(snd_pcm_hw_params_get_channels);
 6694    SDL_ALSA_SYM(snd_pcm_hw_params_set_rate_near);
 6695    SDL_ALSA_SYM(snd_pcm_hw_params_set_period_size_near);
 6696    SDL_ALSA_SYM(snd_pcm_hw_params_get_period_size);
 6697    SDL_ALSA_SYM(snd_pcm_hw_params_set_periods_near);
 6698    SDL_ALSA_SYM(snd_pcm_hw_params_get_periods);
 6699    SDL_ALSA_SYM(snd_pcm_hw_params_set_buffer_size_near);
 6700    SDL_ALSA_SYM(snd_pcm_hw_params_get_buffer_size);
 6701    SDL_ALSA_SYM(snd_pcm_hw_params);
 6702    SDL_ALSA_SYM(snd_pcm_sw_params_current);
 6703    SDL_ALSA_SYM(snd_pcm_sw_params_set_start_threshold);
 6704    SDL_ALSA_SYM(snd_pcm_sw_params);
 6705    SDL_ALSA_SYM(snd_pcm_nonblock);
 6706    SDL_ALSA_SYM(snd_pcm_wait);
 6707    SDL_ALSA_SYM(snd_pcm_sw_params_set_avail_min);
 6708    return 0;
 6709}
 6710
 6711#undef SDL_ALSA_SYM
 6712
 6713#ifdef SDL_AUDIO_DRIVER_ALSA_DYNAMIC
 6714
 6715static void
 6716UnloadALSALibrary(void)
 6717{
 6718    if (alsa_handle != NULL) {
 6719        SDL_UnloadObject(alsa_handle);
 6720        alsa_handle = NULL;
 6721    }
 6722}
 6723
 6724static int
 6725LoadALSALibrary(void)
 6726{
 6727    int retval = 0;
 6728    if (alsa_handle == NULL) {
 6729        alsa_handle = SDL_LoadObject(alsa_library);
 6730        if (alsa_handle == NULL) {
 6731            retval = -1;
 6732
 6733        } else {
 6734            retval = load_alsa_syms();
 6735            if (retval < 0) {
 6736                UnloadALSALibrary();
 6737            }
 6738        }
 6739    }
 6740    return retval;
 6741}
 6742
 6743#else
 6744
 6745static void
 6746UnloadALSALibrary(void)
 6747{
 6748}
 6749
 6750static int
 6751LoadALSALibrary(void)
 6752{
 6753    load_alsa_syms();
 6754    return 0;
 6755}
 6756
 6757#endif
 6758
 6759static const char *
 6760ALSA_get_audio_device(int channels)
 6761{
 6762    const char *device;
 6763
 6764    device = SDL_getenv("AUDIODEV");
 6765    if (device == NULL) {
 6766        switch (channels) {
 6767        case 6:
 6768            device = "plug:surround51";
 6769            break;
 6770        case 4:
 6771            device = "plug:surround40";
 6772            break;
 6773        default:
 6774            device = "default";
 6775            break;
 6776        }
 6777    }
 6778    return device;
 6779}
 6780
 6781static void
 6782ALSA_WaitDevice(_THIS)
 6783{
 6784
 6785}
 6786
 6787#define SWIZ6(T) \
 6788    T *ptr = (T *) SDLAUDIOHIDDEN->mixbuf; \
 6789    Uint32 i; \
 6790    for (i = 0; i < this->spec.samples; i++, ptr += 6) { \
 6791        T tmp; \
 6792        tmp = ptr[2]; ptr[2] = ptr[4]; ptr[4] = tmp; \
 6793        tmp = ptr[3]; ptr[3] = ptr[5]; ptr[5] = tmp; \
 6794    }
 6795
 6796static SDL_INLINE void
 6797swizzle_alsa_channels_6_64bit(_THIS)
 6798{
 6799    SWIZ6(Uint64);
 6800}
 6801
 6802static SDL_INLINE void
 6803swizzle_alsa_channels_6_32bit(_THIS)
 6804{
 6805    SWIZ6(Uint32);
 6806}
 6807
 6808static SDL_INLINE void
 6809swizzle_alsa_channels_6_16bit(_THIS)
 6810{
 6811    SWIZ6(Uint16);
 6812}
 6813
 6814static SDL_INLINE void
 6815swizzle_alsa_channels_6_8bit(_THIS)
 6816{
 6817    SWIZ6(Uint8);
 6818}
 6819
 6820#undef SWIZ6
 6821
 6822static SDL_INLINE void
 6823swizzle_alsa_channels(_THIS)
 6824{
 6825    if (this->spec.channels == 6) {
 6826        const Uint16 fmtsize = (this->spec.format & 0xFF);
 6827        if (fmtsize == 16)
 6828            swizzle_alsa_channels_6_16bit(this);
 6829        else if (fmtsize == 8)
 6830            swizzle_alsa_channels_6_8bit(this);
 6831        else if (fmtsize == 32)
 6832            swizzle_alsa_channels_6_32bit(this);
 6833        else if (fmtsize == 64)
 6834            swizzle_alsa_channels_6_64bit(this);
 6835    }
 6836
 6837}
 6838
 6839static void
 6840ALSA_PlayDevice(_THIS)
 6841{
 6842    int status;
 6843    const Uint8 *sample_buf = (const Uint8 *) SDLAUDIOHIDDEN->mixbuf;
 6844    const int frame_size = (((int) (this->spec.format & 0xFF)) / 8) *
 6845                                this->spec.channels;
 6846    snd_pcm_uframes_t frames_left = ((snd_pcm_uframes_t) this->spec.samples);
 6847
 6848    swizzle_alsa_channels(this);
 6849
 6850    while ( frames_left > 0 && this->enabled ) {
 6851
 6852        status = ALSA_snd_pcm_writei(SDLAUDIOHIDDEN->pcm_handle,
 6853                                     sample_buf, frames_left);
 6854
 6855        if (status < 0) {
 6856            if (status == -EAGAIN) {
 6857
 6858                SDL_Delay(1);
 6859                continue;
 6860            }
 6861            status = ALSA_snd_pcm_recover(SDLAUDIOHIDDEN->pcm_handle, status, 0);
 6862            if (status < 0) {
 6863
 6864                fprintf(stderr, "ALSA write failed (unrecoverable): %s\n",
 6865                        ALSA_snd_strerror(status));
 6866                this->enabled = 0;
 6867                return;
 6868            }
 6869            continue;
 6870        }
 6871        sample_buf += status * frame_size;
 6872        frames_left -= status;
 6873    }
 6874}
 6875
 6876static Uint8 *
 6877ALSA_GetDeviceBuf(_THIS)
 6878{
 6879    return (SDLAUDIOHIDDEN->mixbuf);
 6880}
 6881
 6882static void
 6883ALSA_CloseDevice(_THIS)
 6884{
 6885    if (SDLAUDIOHIDDEN != NULL) {
 6886        SDL_FreeAudioMem(SDLAUDIOHIDDEN->mixbuf);
 6887        SDLAUDIOHIDDEN->mixbuf = NULL;
 6888        if (SDLAUDIOHIDDEN->pcm_handle) {
 6889            ALSA_snd_pcm_drain(SDLAUDIOHIDDEN->pcm_handle);
 6890            ALSA_snd_pcm_close(SDLAUDIOHIDDEN->pcm_handle);
 6891            SDLAUDIOHIDDEN->pcm_handle = NULL;
 6892        }
 6893        SDL_free(SDLAUDIOHIDDEN);
 6894        this->hidden = NULL;
 6895    }
 6896}
 6897
 6898static int
 6899ALSA_finalize_hardware(_THIS, snd_pcm_hw_params_t *hwparams, int override)
 6900{
 6901    int status;
 6902    snd_pcm_uframes_t bufsize;
 6903
 6904    status = ALSA_snd_pcm_hw_params(SDLAUDIOHIDDEN->pcm_handle, hwparams);
 6905    if ( status < 0 ) {
 6906        return(-1);
 6907    }
 6908
 6909    status = ALSA_snd_pcm_hw_params_get_buffer_size(hwparams, &bufsize);
 6910    if ( status < 0 ) {
 6911        return(-1);
 6912    }
 6913    if ( !override && bufsize != this->spec.samples * 2 ) {
 6914        return(-1);
 6915    }
 6916
 6917    this->spec.samples = bufsize / 2;
 6918
 6919    if ( SDL_getenv("SDL_AUDIO_ALSA_DEBUG") ) {
 6920        snd_pcm_uframes_t persize = 0;
 6921        unsigned int periods = 0;
 6922
 6923        ALSA_snd_pcm_hw_params_get_period_size(hwparams, &persize, NULL);
 6924        ALSA_snd_pcm_hw_params_get_periods(hwparams, &periods, NULL);
 6925
 6926        fprintf(stderr,
 6927            "ALSA: period size = %ld, periods = %u, buffer size = %lu\n",
 6928            persize, periods, bufsize);
 6929    }
 6930
 6931    return(0);
 6932}
 6933
 6934static int
 6935ALSA_set_period_size(_THIS, snd_pcm_hw_params_t *params, int override)
 6936{
 6937    const char *env;
 6938    int status;
 6939    snd_pcm_hw_params_t *hwparams;
 6940    snd_pcm_uframes_t frames;
 6941    unsigned int periods;
 6942
 6943    snd_pcm_hw_params_alloca(&hwparams);
 6944    ALSA_snd_pcm_hw_params_copy(hwparams, params);
 6945
 6946    if ( !override ) {
 6947        env = SDL_getenv("SDL_AUDIO_ALSA_SET_PERIOD_SIZE");
 6948        if ( env ) {
 6949            override = SDL_atoi(env);
 6950            if ( override == 0 ) {
 6951                return(-1);
 6952            }
 6953        }
 6954    }
 6955
 6956    frames = this->spec.samples;
 6957    status = ALSA_snd_pcm_hw_params_set_period_size_near(
 6958                SDLAUDIOHIDDEN->pcm_handle, hwparams, &frames, NULL);
 6959    if ( status < 0 ) {
 6960        return(-1);
 6961    }
 6962
 6963    periods = 2;
 6964    status = ALSA_snd_pcm_hw_params_set_periods_near(
 6965                SDLAUDIOHIDDEN->pcm_handle, hwparams, &periods, NULL);
 6966    if ( status < 0 ) {
 6967        return(-1);
 6968    }
 6969
 6970    return ALSA_finalize_hardware(this, hwparams, override);
 6971}
 6972
 6973static int
 6974ALSA_set_buffer_size(_THIS, snd_pcm_hw_params_t *params, int override)
 6975{
 6976    const char *env;
 6977    int status;
 6978    snd_pcm_hw_params_t *hwparams;
 6979    snd_pcm_uframes_t frames;
 6980
 6981    snd_pcm_hw_params_alloca(&hwparams);
 6982    ALSA_snd_pcm_hw_params_copy(hwparams, params);
 6983
 6984    if ( !override ) {
 6985        env = SDL_getenv("SDL_AUDIO_ALSA_SET_BUFFER_SIZE");
 6986        if ( env ) {
 6987            override = SDL_atoi(env);
 6988            if ( override == 0 ) {
 6989                return(-1);
 6990            }
 6991        }
 6992    }
 6993
 6994    frames = this->spec.samples * 2;
 6995    status = ALSA_snd_pcm_hw_params_set_buffer_size_near(
 6996                    SDLAUDIOHIDDEN->pcm_handle, hwparams, &frames);
 6997    if ( status < 0 ) {
 6998        return(-1);
 6999    }
 7000
 7001    return ALSA_finalize_hardware(this, hwparams, override);
 7002}
 7003
 7004static int
 7005ALSA_OpenDevice(_THIS, const char *devname, int iscapture)
 7006{
 7007    int status = 0;
 7008    snd_pcm_t *pcm_handle = NULL;
 7009    snd_pcm_hw_params_t *hwparams = NULL;
 7010    snd_pcm_sw_params_t *swparams = NULL;
 7011    snd_pcm_format_t format = 0;
 7012    SDL_AudioFormat test_format = 0;
 7013    unsigned int rate = 0;
 7014    unsigned int channels = 0;
 7015
 7016    this->hidden = (struct SDL_PrivateAudioData *)
 7017        SDL_malloc((sizeof *SDLAUDIOHIDDEN));
 7018    if (SDLAUDIOHIDDEN == NULL) {
 7019        return SDL_OutOfMemory();
 7020    }
 7021    SDL_memset(SDLAUDIOHIDDEN, 0, (sizeof *SDLAUDIOHIDDEN));
 7022
 7023    status = ALSA_snd_pcm_open(&pcm_handle,
 7024                               ALSA_get_audio_device(this->spec.channels),
 7025                               SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
 7026
 7027    if (status < 0) {
 7028        ALSA_CloseDevice(this);
 7029        return SDL_SetError("ALSA: Couldn't open audio device: %s",
 7030                            ALSA_snd_strerror(status));
 7031    }
 7032
 7033    SDLAUDIOHIDDEN->pcm_handle = pcm_handle;
 7034
 7035    snd_pcm_hw_params_alloca(&hwparams);
 7036    status = ALSA_snd_pcm_hw_params_any(pcm_handle, hwparams);
 7037    if (status < 0) {
 7038        ALSA_CloseDevice(this);
 7039        return SDL_SetError("ALSA: Couldn't get hardware config: %s",
 7040                            ALSA_snd_strerror(status));
 7041    }
 7042
 7043    status = ALSA_snd_pcm_hw_params_set_access(pcm_handle, hwparams,
 7044                                               SND_PCM_ACCESS_RW_INTERLEAVED);
 7045    if (status < 0) {
 7046        ALSA_CloseDevice(this);
 7047        return SDL_SetError("ALSA: Couldn't set interleaved access: %s",
 7048                     ALSA_snd_strerror(status));
 7049    }
 7050
 7051    status = -1;
 7052    for (test_format = SDL_FirstAudioFormat(this->spec.format);
 7053         test_format && (status < 0);) {
 7054        status = 0;
 7055        switch (test_format) {
 7056        case AUDIO_U8:
 7057            format = SND_PCM_FORMAT_U8;
 7058            break;
 7059        case AUDIO_S8:
 7060            format = SND_PCM_FORMAT_S8;
 7061            break;
 7062        case AUDIO_S16LSB:
 7063            format = SND_PCM_FORMAT_S16_LE;
 7064            break;
 7065        case AUDIO_S16MSB:
 7066            format = SND_PCM_FORMAT_S16_BE;
 7067            break;
 7068        case AUDIO_U16LSB:
 7069            format = SND_PCM_FORMAT_U16_LE;
 7070            break;
 7071        case AUDIO_U16MSB:
 7072            format = SND_PCM_FORMAT_U16_BE;
 7073            break;
 7074        case AUDIO_S32LSB:
 7075            format = SND_PCM_FORMAT_S32_LE;
 7076            break;
 7077        case AUDIO_S32MSB:
 7078            format = SND_PCM_FORMAT_S32_BE;
 7079            break;
 7080        case AUDIO_F32LSB:
 7081            format = SND_PCM_FORMAT_FLOAT_LE;
 7082            break;
 7083        case AUDIO_F32MSB:
 7084            format = SND_PCM_FORMAT_FLOAT_BE;
 7085            break;
 7086        default:
 7087            status = -1;
 7088            break;
 7089        }
 7090        if (status >= 0) {
 7091            status = ALSA_snd_pcm_hw_params_set_format(pcm_handle,
 7092                                                       hwparams, format);
 7093        }
 7094        if (status < 0) {
 7095            test_format = SDL_NextAudioFormat();
 7096        }
 7097    }
 7098    if (status < 0) {
 7099        ALSA_CloseDevice(this);
 7100        return SDL_SetError("ALSA: Couldn't find any hardware audio formats");
 7101    }
 7102    this->spec.format = test_format;
 7103
 7104    status = ALSA_snd_pcm_hw_params_set_channels(pcm_handle, hwparams,
 7105                                                 this->spec.channels);
 7106    channels = this->spec.channels;
 7107    if (status < 0) {
 7108        status = ALSA_snd_pcm_hw_params_get_channels(hwparams, &channels);
 7109        if (status < 0) {
 7110            ALSA_CloseDevice(this);
 7111            return SDL_SetError("ALSA: Couldn't set audio channels");
 7112        }
 7113        this->spec.channels = channels;
 7114    }
 7115
 7116    rate = this->spec.freq;
 7117    status = ALSA_snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams,
 7118                                                  &rate, NULL);
 7119    if (status < 0) {
 7120        ALSA_CloseDevice(this);
 7121        return SDL_SetError("ALSA: Couldn't set audio frequency: %s",
 7122                            ALSA_snd_strerror(status));
 7123    }
 7124    this->spec.freq = rate;
 7125
 7126    if ( ALSA_set_period_size(this, hwparams, 0) < 0 &&
 7127         ALSA_set_buffer_size(this, hwparams, 0) < 0 ) {
 7128
 7129        if ( ALSA_set_period_size(this, hwparams, 1) < 0 ) {
 7130            ALSA_CloseDevice(this);
 7131            return SDL_SetError("Couldn't set hardware audio parameters: %s", ALSA_snd_strerror(status));
 7132        }
 7133    }
 7134
 7135    snd_pcm_sw_params_alloca(&swparams);
 7136    status = ALSA_snd_pcm_sw_params_current(pcm_handle, swparams);
 7137    if (status < 0) {
 7138        ALSA_CloseDevice(this);
 7139        return SDL_SetError("ALSA: Couldn't get software config: %s",
 7140                            ALSA_snd_strerror(status));
 7141    }
 7142    status = ALSA_snd_pcm_sw_params_set_avail_min(pcm_handle, swparams, this->spec.samples);
 7143    if (status < 0) {
 7144        ALSA_CloseDevice(this);
 7145        return SDL_SetError("Couldn't set minimum available samples: %s",
 7146                            ALSA_snd_strerror(status));
 7147    }
 7148    status =
 7149        ALSA_snd_pcm_sw_params_set_start_threshold(pcm_handle, swparams, 1);
 7150    if (status < 0) {
 7151        ALSA_CloseDevice(this);
 7152        return SDL_SetError("ALSA: Couldn't set start threshold: %s",
 7153                            ALSA_snd_strerror(status));
 7154    }
 7155    status = ALSA_snd_pcm_sw_params(pcm_handle, swparams);
 7156    if (status < 0) {
 7157        ALSA_CloseDevice(this);
 7158        return SDL_SetError("Couldn't set software audio parameters: %s",
 7159                            ALSA_snd_strerror(status));
 7160    }
 7161
 7162    SDL_CalculateAudioSpec(&this->spec);
 7163
 7164    SDLAUDIOHIDDEN->mixlen = this->spec.size;
 7165    SDLAUDIOHIDDEN->mixbuf = (Uint8 *) SDL_AllocAudioMem(SDLAUDIOHIDDEN->mixlen);
 7166    if (SDLAUDIOHIDDEN->mixbuf == NULL) {
 7167        ALSA_CloseDevice(this);
 7168        return SDL_OutOfMemory();
 7169    }
 7170    SDL_memset(SDLAUDIOHIDDEN->mixbuf, this->spec.silence, SDLAUDIOHIDDEN->mixlen);
 7171
 7172    ALSA_snd_pcm_nonblock(pcm_handle, 0);
 7173
 7174    return 0;
 7175}
 7176
 7177static void
 7178ALSA_Deinitialize(void)
 7179{
 7180    UnloadALSALibrary();
 7181}
 7182
 7183static int
 7184ALSA_Init(SDL_AudioDriverImpl * impl)
 7185{
 7186    if (LoadALSALibrary() < 0) {
 7187        return 0;
 7188    }
 7189
 7190    impl->OpenDevice = ALSA_OpenDevice;
 7191    impl->WaitDevice = ALSA_WaitDevice;
 7192    impl->GetDeviceBuf = ALSA_GetDeviceBuf;
 7193    impl->PlayDevice = ALSA_PlayDevice;
 7194    impl->CloseDevice = ALSA_CloseDevice;
 7195    impl->Deinitialize = ALSA_Deinitialize;
 7196    impl->OnlyHasDefaultOutputDevice = 1;
 7197
 7198    return 1;
 7199}
 7200
 7201AudioBootStrap ALSA_bootstrap = {
 7202    "alsa", "ALSA PCM audio", ALSA_Init, 0
 7203};
 7204
 7205#endif
 7206#if SDL_AUDIO_DRIVER_ARTS
 7207
 7208#ifdef HAVE_SIGNAL_H
 7209#include <signal.h>
 7210#endif
 7211#include <unistd.h>
 7212#include <errno.h>
 7213
 7214#define SDL_AllocAudioMem   SDL_malloc
 7215#define SDL_FreeAudioMem    SDL_free
 7216#ifndef _SDL_artscaudio_h
 7217#define _SDL_artscaudio_h
 7218
 7219#include <artsc.h>
 7220
 7221#undef _THIS
 7222#define _THIS   SDL_AudioDevice *this
 7223
 7224#undef SDLAUDIOHIDDEN
 7225#define SDLAUDIOHIDDEN ((struct SDL_PrivateAudioDataARTS*)this->hidden)
 7226struct SDL_PrivateAudioDataARTS
 7227{
 7228
 7229    arts_stream_t stream;
 7230
 7231    pid_t parent;
 7232
 7233    Uint8 *mixbuf;
 7234    int mixlen;
 7235
 7236    float frame_ticks;
 7237    float next_frame;
 7238};
 7239#define FUDGE_TICKS 10
 7240
 7241#endif
 7242
 7243#ifdef SDL_AUDIO_DRIVER_ARTS_DYNAMIC
 7244#ifndef _SDLname_h_
 7245#define _SDLname_h_
 7246
 7247#if defined(__STDC__) || defined(__cplusplus)
 7248#define NeedFunctionPrototypes 1
 7249#endif
 7250
 7251#define SDL_NAME(X) SDL_##X
 7252
 7253#endif
 7254#else
 7255#define SDL_NAME(X)	X
 7256#endif
 7257
 7258#ifdef SDL_AUDIO_DRIVER_ARTS_DYNAMIC
 7259
 7260static const char *arts_library = SDL_AUDIO_DRIVER_ARTS_DYNAMIC;
 7261static void *arts_handle = NULL;
 7262
 7263static int (*SDL_NAME(arts_init)) (void);
 7264static void (*SDL_NAME(arts_free)) (void);
 7265static arts_stream_t(*SDL_NAME(arts_play_stream)) (int rate, int bits,
 7266                                                   int channels,
 7267                                                   const char *name);
 7268static int (*SDL_NAME(arts_stream_set)) (arts_stream_t s,
 7269                                         arts_parameter_t param, int value);
 7270static int (*SDL_NAME(arts_stream_get)) (arts_stream_t s,
 7271                                         arts_parameter_t param);
 7272static int (*SDL_NAME(arts_write)) (arts_stream_t s, const void *buffer,
 7273                                    int count);
 7274static void (*SDL_NAME(arts_close_stream)) (arts_stream_t s);
 7275static int (*SDL_NAME(arts_suspend))(void);
 7276static int (*SDL_NAME(arts_suspended)) (void);
 7277static const char *(*SDL_NAME(arts_error_text)) (int errorcode);
 7278
 7279#define SDL_ARTS_SYM(x) { #x, (void **) (char *) &SDL_NAME(x) }
 7280static struct
 7281{
 7282    const char *name;
 7283    void **func;
 7284} arts_functions[] = {
 7285
 7286    SDL_ARTS_SYM(arts_init),
 7287    SDL_ARTS_SYM(arts_free),
 7288    SDL_ARTS_SYM(arts_play_stream),
 7289    SDL_ARTS_SYM(arts_stream_set),
 7290    SDL_ARTS_SYM(arts_stream_get),
 7291    SDL_ARTS_SYM(arts_write),
 7292    SDL_ARTS_SYM(arts_close_stream),
 7293    SDL_ARTS_SYM(arts_suspend),
 7294    SDL_ARTS_SYM(arts_suspended),
 7295    SDL_ARTS_SYM(arts_error_text),
 7296
 7297};
 7298
 7299#undef SDL_ARTS_SYM
 7300
 7301static void
 7302UnloadARTSLibrary()
 7303{
 7304    if (arts_handle != NULL) {
 7305        SDL_UnloadObject(arts_handle);
 7306        arts_handle = NULL;
 7307    }
 7308}
 7309
 7310static int
 7311LoadARTSLibrary(void)
 7312{
 7313    int i, retval = -1;
 7314
 7315    if (arts_handle == NULL) {
 7316        arts_handle = SDL_LoadObject(arts_library);
 7317        if (arts_handle != NULL) {
 7318            retval = 0;
 7319            for (i = 0; i < SDL_arraysize(arts_functions); ++i) {
 7320                *arts_functions[i].func =
 7321                    SDL_LoadFunction(arts_handle, arts_functions[i].name);
 7322                if (!*arts_functions[i].func) {
 7323                    retval = -1;
 7324                    UnloadARTSLibrary();
 7325                    break;
 7326                }
 7327            }
 7328        }
 7329    }
 7330
 7331    return retval;
 7332}
 7333
 7334#else
 7335
 7336static void
 7337UnloadARTSLibrary()
 7338{
 7339    return;
 7340}
 7341
 7342static int
 7343LoadARTSLibrary(void)
 7344{
 7345    return 0;
 7346}
 7347
 7348#endif
 7349
 7350static void
 7351ARTS_WaitDevice(_THIS)
 7352{
 7353    Sint32 ticks;
 7354
 7355    {
 7356        static int cnt = 0;
 7357
 7358        if (SDLAUDIOHIDDEN->parent && (((++cnt) % 10) == 0)) {
 7359            if (kill(SDLAUDIOHIDDEN->parent, 0) < 0 && errno == ESRCH) {
 7360                this->enabled = 0;
 7361            }
 7362        }
 7363    }
 7364
 7365    ticks =
 7366        ((Sint32) (SDLAUDIOHIDDEN->next_frame - SDL_GetTicks())) - FUDGE_TICKS;
 7367    if (ticks > 0) {
 7368        SDL_Delay(ticks);
 7369    }
 7370}
 7371
 7372static void
 7373ARTS_PlayDevice(_THIS)
 7374{
 7375
 7376    int written = SDL_NAME(arts_write) (SDLAUDIOHIDDEN->stream,
 7377                                        SDLAUDIOHIDDEN->mixbuf,
 7378                                        SDLAUDIOHIDDEN->mixlen);
 7379
 7380    if (SDLAUDIOHIDDEN->frame_ticks) {
 7381        SDLAUDIOHIDDEN->next_frame += SDLAUDIOHIDDEN->frame_ticks;
 7382    }
 7383
 7384    if (written < 0) {
 7385        this->enabled = 0;
 7386    }
 7387#ifdef DEBUG_AUDIO
 7388    fprintf(stderr, "Wrote %d bytes of audio data\n", written);
 7389#endif
 7390}
 7391
 7392static void
 7393ARTS_WaitDone(_THIS)
 7394{
 7395
 7396}
 7397
 7398static Uint8 *
 7399ARTS_GetDeviceBuf(_THIS)
 7400{
 7401    return (SDLAUDIOHIDDEN->mixbuf);
 7402}
 7403
 7404static void
 7405ARTS_CloseDevice(_THIS)
 7406{
 7407    if (SDLAUDIOHIDDEN != NULL) {
 7408        SDL_FreeAudioMem(SDLAUDIOHIDDEN->mixbuf);
 7409        SDLAUDIOHIDDEN->mixbuf = NULL;
 7410        if (SDLAUDIOHIDDEN->stream) {
 7411            SDL_NAME(arts_close_stream) (SDLAUDIOHIDDEN->stream);
 7412            SDLAUDIOHIDDEN->stream = 0;
 7413        }
 7414        SDL_NAME(arts_free) ();
 7415        SDL_free(SDLAUDIOHIDDEN);
 7416        this->hidden = NULL;
 7417    }
 7418}
 7419
 7420static int
 7421ARTS_Suspend(void)
 7422{
 7423    const Uint32 abortms = SDL_GetTicks() + 3000;
 7424    while ( (!SDL_NAME(arts_suspended)()) && !SDL_TICKS_PASSED(SDL_GetTicks(), abortms) ) {
 7425        if ( SDL_NAME(arts_suspend)() ) {
 7426            break;
 7427        }
 7428    }
 7429    return SDL_NAME(arts_suspended)();
 7430}
 7431
 7432static int
 7433ARTS_OpenDevice(_THIS, const char *devname, int iscapture)
 7434{
 7435    int rc = 0;
 7436    int bits = 0, frag_spec = 0;
 7437    SDL_AudioFormat test_format = 0, format = 0;
 7438
 7439    this->hidden = (struct SDL_PrivateAudioData *)
 7440        SDL_malloc((sizeof *SDLAUDIOHIDDEN));
 7441    if (SDLAUDIOHIDDEN == NULL) {
 7442        return SDL_OutOfMemory();
 7443    }
 7444    SDL_memset(SDLAUDIOHIDDEN, 0, (sizeof *SDLAUDIOHIDDEN));
 7445
 7446    for (test_format = SDL_FirstAudioFormat(this->spec.format);
 7447         !format && test_format;) {
 7448#ifdef DEBUG_AUDIO
 7449        fprintf(stderr, "Trying format 0x%4.4x\n", test_format);
 7450#endif
 7451        switch (test_format) {
 7452        case AUDIO_U8:
 7453            bits = 8;
 7454            format = 1;
 7455            break;
 7456        case AUDIO_S16LSB:
 7457            bits = 16;
 7458            format = 1;
 7459            break;
 7460        default:
 7461            format = 0;
 7462            break;
 7463        }
 7464        if (!format) {
 7465            test_format = SDL_NextAudioFormat();
 7466        }
 7467    }
 7468    if (format == 0) {
 7469        ARTS_CloseDevice(this);
 7470        return SDL_SetError("Couldn't find any hardware audio formats");
 7471    }
 7472    this->spec.format = test_format;
 7473
 7474    if ((rc = SDL_NAME(arts_init) ()) != 0) {
 7475        ARTS_CloseDevice(this);
 7476        return SDL_SetError("Unable to initialize ARTS: %s",
 7477                            SDL_NAME(arts_error_text) (rc));
 7478    }
 7479
 7480    if (!ARTS_Suspend()) {
 7481        ARTS_CloseDevice(this);
 7482        return SDL_SetError("ARTS can not open audio device");
 7483    }
 7484
 7485    SDLAUDIOHIDDEN->stream = SDL_NAME(arts_play_stream) (this->spec.freq,
 7486                                                       bits,
 7487                                                       this->spec.channels,
 7488                                                       "SDL");
 7489
 7490    SDL_NAME(arts_write) (SDLAUDIOHIDDEN->stream, "", 0);
 7491
 7492    SDL_CalculateAudioSpec(&this->spec);
 7493
 7494    for (frag_spec = 0; (0x01 << frag_spec) < this->spec.size; ++frag_spec);
 7495    if ((0x01 << frag_spec) != this->spec.size) {
 7496        ARTS_CloseDevice(this);
 7497        return SDL_SetError("Fragment size must be a power of two");
 7498    }
 7499    frag_spec |= 0x00020000;
 7500
 7501#ifdef ARTS_P_PACKET_SETTINGS
 7502    SDL_NAME(arts_stream_set) (SDLAUDIOHIDDEN->stream,
 7503                               ARTS_P_PACKET_SETTINGS, frag_spec);
 7504#else
 7505    SDL_NAME(arts_stream_set) (SDLAUDIOHIDDEN->stream, ARTS_P_PACKET_SIZE,
 7506                               frag_spec & 0xffff);
 7507    SDL_NAME(arts_stream_set) (SDLAUDIOHIDDEN->stream, ARTS_P_PACKET_COUNT,
 7508                               frag_spec >> 16);
 7509#endif
 7510    this->spec.size = SDL_NAME(arts_stream_get) (SDLAUDIOHIDDEN->stream,
 7511                                                 ARTS_P_PACKET_SIZE);
 7512
 7513    SDLAUDIOHIDDEN->mixlen = this->spec.size;
 7514    SDLAUDIOHIDDEN->mixbuf = (Uint8 *) SDL_AllocAudioMem(SDLAUDIOHIDDEN->mixlen);
 7515    if (SDLAUDIOHIDDEN->mixbuf == NULL) {
 7516        ARTS_CloseDevice(this);
 7517        return SDL_OutOfMemory();
 7518    }
 7519    SDL_memset(SDLAUDIOHIDDEN->mixbuf, this->spec.silence, this->spec.size);
 7520
 7521    SDLAUDIOHIDDEN->parent = getpid();
 7522
 7523    return 0;
 7524}
 7525
 7526static void
 7527ARTS_Deinitialize(void)
 7528{
 7529    UnloadARTSLibrary();
 7530}
 7531
 7532static int
 7533ARTS_Init(SDL_AudioDriverImpl * impl)
 7534{
 7535    if (LoadARTSLibrary() < 0) {
 7536        return 0;
 7537    } else {
 7538        if (SDL_NAME(arts_init) () != 0) {
 7539            UnloadARTSLibrary();
 7540            SDL_SetError("ARTS: arts_init failed (no audio server?)");
 7541            return 0;
 7542        }
 7543
 7544        if (ARTS_Suspend()) {
 7545            arts_stream_t stream;
 7546            stream = SDL_NAME(arts_play_stream) (44100, 16, 2, "SDL");
 7547            SDL_NAME(arts_write) (stream, "", 0);
 7548            SDL_NAME(arts_close_stream) (stream);
 7549        }
 7550
 7551        SDL_NAME(arts_free) ();
 7552    }
 7553
 7554    impl->OpenDevice = ARTS_OpenDevice;
 7555    impl->PlayDevice = ARTS_PlayDevice;
 7556    impl->WaitDevice = ARTS_WaitDevice;
 7557    impl->GetDeviceBuf = ARTS_GetDeviceBuf;
 7558    impl->CloseDevice = ARTS_CloseDevice;
 7559    impl->WaitDone = ARTS_WaitDone;
 7560    impl->Deinitialize = ARTS_Deinitialize;
 7561    impl->OnlyHasDefaultOutputDevice = 1;
 7562
 7563    return 1;
 7564}
 7565
 7566AudioBootStrap ARTS_bootstrap = {
 7567    "arts", "Analog RealTime Synthesizer", ARTS_Init, 0
 7568};
 7569
 7570#endif
 7571#if SDL_AUDIO_DRIVER_BSD
 7572
 7573#include <errno.h>
 7574#include <unistd.h>
 7575#include <fcntl.h>
 7576#include <sys/time.h>
 7577#include <sys/ioctl.h>
 7578#include <sys/stat.h>
 7579#include <sys/types.h>
 7580#include <sys/audioio.h>
 7581
 7582#define SDL_AllocAudioMem   SDL_malloc
 7583#define SDL_FreeAudioMem    SDL_free
 7584#ifdef USE_BLOCKING_WRITES
 7585#define OPEN_FLAGS_OUTPUT O_WRONLY
 7586#define OPEN_FLAGS_INPUT O_RDONLY
 7587#else
 7588#define OPEN_FLAGS_OUTPUT (O_WRONLY|O_NONBLOCK)
 7589#define OPEN_FLAGS_INPUT (O_RDONLY|O_NONBLOCK)
 7590#endif
 7591
 7592void SDL_EnumUnixAudioDevices(int iscapture, int classic,
 7593                              int (*test) (int fd), SDL_AddAudioDevice addfn);
 7594#ifndef _SDL_bsdaudio_h
 7595#define _SDL_bsdaudio_h
 7596
 7597#undef _THIS
 7598#define _THIS   SDL_AudioDevice *this
 7599
 7600#undef SDLAUDIOHIDDEN
 7601#define SDLAUDIOHIDDEN ((struct SDL_PrivateAudioDataBSDAUDIO*)this->hidden)
 7602struct SDL_PrivateAudioDataBSDAUDIO
 7603{
 7604
 7605    int audio_fd;
 7606
 7607    pid_t parent;
 7608
 7609    Uint8 *mixbuf;
 7610    int mixlen;
 7611
 7612    float frame_ticks;
 7613    float next_frame;
 7614};
 7615
 7616#define FUDGE_TICKS 10
 7617
 7618#endif
 7619
 7620static void
 7621BSDAUDIO_DetectDevices(int iscapture, SDL_AddAudioDevice addfn)
 7622{
 7623    SDL_EnumUnixAudioDevices(iscapture, 0, NULL, addfn);
 7624}
 7625
 7626static void
 7627BSDAUDIO_Status(_THIS)
 7628{
 7629#ifdef DEBUG_AUDIO
 7630
 7631    audio_info_t info;
 7632
 7633    if (ioctl(SDLAUDIOHIDDEN->audio_fd, AUDIO_GETINFO, &info) < 0) {
 7634        fprintf(stderr, "AUDIO_GETINFO failed.\n");
 7635        return;
 7636    }
 7637    fprintf(stderr, "\n"
 7638            "[play/record info]\n"
 7639            "buffer size	:   %d bytes\n"
 7640            "sample rate	:   %i Hz\n"
 7641            "channels	:   %i\n"
 7642            "precision	:   %i-bit\n"
 7643            "encoding	:   0x%x\n"
 7644            "seek		:   %i\n"
 7645            "sample count	:   %i\n"
 7646            "EOF count	:   %i\n"
 7647            "paused		:   %s\n"
 7648            "error occured	:   %s\n"
 7649            "waiting		:   %s\n"
 7650            "active		:   %s\n"
 7651            "",
 7652            info.play.buffer_size,
 7653            info.play.sample_rate,
 7654            info.play.channels,
 7655            info.play.precision,
 7656            info.play.encoding,
 7657            info.play.seek,
 7658            info.play.samples,
 7659            info.play.eof,
 7660            info.play.pause ? "yes" : "no",
 7661            info.play.error ? "yes" : "no",
 7662            info.play.waiting ? "yes" : "no",
 7663            info.play.active ? "yes" : "no");
 7664
 7665    fprintf(stderr, "\n"
 7666            "[audio info]\n"
 7667            "monitor_gain	:   %i\n"
 7668            "hw block size	:   %d bytes\n"
 7669            "hi watermark	:   %i\n"
 7670            "lo watermark	:   %i\n"
 7671            "audio mode	:   %s\n"
 7672            "",
 7673            info.monitor_gain,
 7674            info.blocksize,
 7675            info.hiwat, info.lowat,
 7676            (info.mode == AUMODE_PLAY) ? "PLAY"
 7677            : (info.mode = AUMODE_RECORD) ? "RECORD"
 7678            : (info.mode == AUMODE_PLAY_ALL ? "PLAY_ALL" : "?"));
 7679
 7680#endif
 7681}
 7682
 7683static void
 7684BSDAUDIO_WaitDevice(_THIS)
 7685{
 7686#ifndef USE_BLOCKING_WRITES
 7687
 7688    if (SDLAUDIOHIDDEN->frame_ticks) {
 7689
 7690        Sint32 ticks;
 7691
 7692        ticks = ((Sint32) (SDLAUDIOHIDDEN->next_frame - SDL_GetTicks())) - FUDGE_TICKS;
 7693        if (ticks > 0) {
 7694            SDL_Delay(ticks);
 7695        }
 7696    } else {
 7697
 7698        fd_set fdset;
 7699        struct timeval timeout;
 7700
 7701        FD_ZERO(&fdset);
 7702        FD_SET(SDLAUDIOHIDDEN->audio_fd, &fdset);
 7703        timeout.tv_sec = 10;
 7704        timeout.tv_usec = 0;
 7705#ifdef DEBUG_AUDIO
 7706        fprintf(stderr, "Waiting for audio to get ready\n");
 7707#endif
 7708        if (select(SDLAUDIOHIDDEN->audio_fd + 1, NULL, &fdset, NULL, &timeout)
 7709            <= 0) {
 7710            const char *message =
 7711                "Audio timeout - buggy audio driver? (disabled)";
 7712
 7713            fprintf(stderr, "SDL: %s\n", message);
 7714            this->enabled = 0;
 7715
 7716            SDLAUDIOHIDDEN->audio_fd = -1;
 7717#ifdef DEBUG_AUDIO
 7718            fprintf(stderr, "Done disabling audio\n");
 7719#endif
 7720        }
 7721#ifdef DEBUG_AUDIO
 7722        fprintf(stderr, "Ready!\n");
 7723#endif
 7724    }
 7725#endif
 7726}
 7727
 7728static void
 7729BSDAUDIO_PlayDevice(_THIS)
 7730{
 7731    int written, p = 0;
 7732
 7733    do {
 7734        written = write(SDLAUDIOHIDDEN->audio_fd,
 7735                        &SDLAUDIOHIDDEN->mixbuf[p], SDLAUDIOHIDDEN->mixlen - p);
 7736
 7737        if (written > 0)
 7738            p += written;
 7739        if (written == -1 && errno != 0 && errno != EAGAIN && errno != EINTR) {
 7740
 7741            perror("audio");
 7742            break;
 7743        }
 7744
 7745        if (p < written
 7746            || ((written < 0) && ((errno == 0) || (errno == EAGAIN)))) {
 7747            SDL_Delay(1);
 7748        }
 7749    } while (p < written);
 7750
 7751    if (SDLAUDIOHIDDEN->frame_ticks) {
 7752        SDLAUDIOHIDDEN->next_frame += SDLAUDIOHIDDEN->frame_ticks;
 7753    }
 7754
 7755    if (written < 0) {
 7756        this->enabled = 0;
 7757    }
 7758#ifdef DEBUG_AUDIO
 7759    fprintf(stderr, "Wrote %d bytes of audio data\n", written);
 7760#endif
 7761}
 7762
 7763static Uint8 *
 7764BSDAUDIO_GetDeviceBuf(_THIS)
 7765{
 7766    return (SDLAUDIOHIDDEN->mixbuf);
 7767}
 7768
 7769static void
 7770BSDAUDIO_CloseDevice(_THIS)
 7771{
 7772    if (SDLAUDIOHIDDEN != NULL) {
 7773        SDL_FreeAudioMem(SDLAUDIOHIDDEN->mixbuf);
 7774        SDLAUDIOHIDDEN->mixbuf = NULL;
 7775        if (SDLAUDIOHIDDEN->audio_fd >= 0) {
 7776            close(SDLAUDIOHIDDEN->audio_fd);
 7777            SDLAUDIOHIDDEN->audio_fd = -1;
 7778        }
 7779        SDL_free(SDLAUDIOHIDDEN);
 7780        this->hidden = NULL;
 7781    }
 7782}
 7783
 7784static int
 7785BSDAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
 7786{
 7787    const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT);
 7788    SDL_AudioFormat format = 0;
 7789    audio_info_t info;
 7790
 7791    if (devname == NULL) {
 7792        devname = SDL_GetAudioDeviceName(0, iscapture);
 7793        if (devname == NULL) {
 7794            return SDL_SetError("No such audio device");
 7795        }
 7796    }
 7797
 7798    this->hidden = (struct SDL_PrivateAudioData *)
 7799        SDL_malloc((sizeof *SDLAUDIOHIDDEN));
 7800    if (SDLAUDIOHIDDEN == NULL) {
 7801        return SDL_OutOfMemory();
 7802    }
 7803    SDL_memset(SDLAUDIOHIDDEN, 0, (sizeof *SDLAUDIOHIDDEN));
 7804
 7805    SDLAUDIOHIDDEN->audio_fd = open(devname, flags, 0);
 7806    if (SDLAUDIOHIDDEN->audio_fd < 0) {
 7807        return SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
 7808    }
 7809
 7810    AUDIO_INITINFO(&info);
 7811
 7812    SDL_CalculateAudioSpec(&this->spec);
 7813
 7814    info.mode = AUMODE_PLAY;
 7815    if (ioctl(SDLAUDIOHIDDEN->audio_fd, AUDIO_SETINFO, &info) < 0) {
 7816        BSDAUDIO_CloseDevice(this);
 7817        return SDL_SetError("Couldn't put device into play mode");
 7818    }
 7819
 7820    AUDIO_INITINFO(&info);
 7821    for (format = SDL_FirstAudioFormat(this->spec.format);
 7822         format; format = SDL_NextAudioFormat()) {
 7823        switch (format) {
 7824        case AUDIO_U8:
 7825            info.play.encoding = AUDIO_ENCODING_ULINEAR;
 7826            info.play.precision = 8;
 7827            break;
 7828        case AUDIO_S8:
 7829            info.play.encoding = AUDIO_ENCODING_SLINEAR;
 7830            info.play.precision = 8;
 7831            break;
 7832        case AUDIO_S16LSB:
 7833            info.play.encoding = AUDIO_ENCODING_SLINEAR_LE;
 7834            info.play.precision = 16;
 7835            break;
 7836        case AUDIO_S16MSB:
 7837            info.play.encoding = AUDIO_ENCODING_SLINEAR_BE;
 7838            info.play.precision = 16;
 7839            break;
 7840        case AUDIO_U16LSB:
 7841            info.play.encoding = AUDIO_ENCODING_ULINEAR_LE;
 7842            info.play.precision = 16;
 7843            break;
 7844        case AUDIO_U16MSB:
 7845            info.play.encoding = AUDIO_ENCODING_ULINEAR_BE;
 7846            info.play.precision = 16;
 7847            break;
 7848        default:
 7849            continue;
 7850        }
 7851
 7852        if (ioctl(SDLAUDIOHIDDEN->audio_fd, AUDIO_SETINFO, &info) == 0) {
 7853            break;
 7854        }
 7855    }
 7856
 7857    if (!format) {
 7858        BSDAUDIO_CloseDevice(this);
 7859        return SDL_SetError("No supported encoding for 0x%x", this->spec.format);
 7860    }
 7861
 7862    this->spec.format = format;
 7863
 7864    AUDIO_INITINFO(&info);
 7865    info.play.channels = this->spec.channels;
 7866    if (ioctl(SDLAUDIOHIDDEN->audio_fd, AUDIO_SETINFO, &info) == -1) {
 7867        this->spec.channels = 1;
 7868    }
 7869    AUDIO_INITINFO(&info);
 7870    info.play.sample_rate = this->spec.freq;
 7871    info.blocksize = this->spec.size;
 7872    info.hiwat = 5;
 7873    info.lowat = 3;
 7874    (void) ioctl(SDLAUDIOHIDDEN->audio_fd, AUDIO_SETINFO, &info);
 7875    (void) ioctl(SDLAUDIOHIDDEN->audio_fd, AUDIO_GETINFO, &info);
 7876    this->spec.freq = info.play.sample_rate;
 7877
 7878    SDLAUDIOHIDDEN->mixlen = this->spec.size;
 7879    SDLAUDIOHIDDEN->mixbuf = (Uint8 *) SDL_AllocAudioMem(SDLAUDIOHIDDEN->mixlen);
 7880    if (SDLAUDIOHIDDEN->mixbuf == NULL) {
 7881        BSDAUDIO_CloseDevice(this);
 7882        return SDL_OutOfMemory();
 7883    }
 7884    SDL_memset(SDLAUDIOHIDDEN->mixbuf, this->spec.silence, this->spec.size);
 7885
 7886    BSDAUDIO_Status(this);
 7887
 7888    return 0;
 7889}
 7890
 7891static int
 7892BSDAUDIO_Init(SDL_AudioDriverImpl * impl)
 7893{
 7894
 7895    impl->DetectDevices = BSDAUDIO_DetectDevices;
 7896    impl->OpenDevice = BSDAUDIO_OpenDevice;
 7897    impl->PlayDevice = BSDAUDIO_PlayDevice;
 7898    impl->WaitDevice = BSDAUDIO_WaitDevice;
 7899    impl->GetDeviceBuf = BSDAUDIO_GetDeviceBuf;
 7900    impl->CloseDevice = BSDAUDIO_CloseDevice;
 7901
 7902    return 1;
 7903}
 7904
 7905AudioBootStrap BSD_AUDIO_bootstrap = {
 7906    "bsd", "BSD audio", BSDAUDIO_Init, 0
 7907};
 7908
 7909#endif
 7910#if SDL_AUDIO_DRIVER_COREAUDIO
 7911
 7912#ifndef _SDL_coreaudio_h
 7913#define _SDL_coreaudio_h
 7914
 7915#if !defined(__IPHONEOS__)
 7916#define MACOSX_COREAUDIO 1
 7917#endif
 7918
 7919#if MACOSX_COREAUDIO
 7920#include <CoreAudio/CoreAudio.h>
 7921#include <CoreServices/CoreServices.h>
 7922#else
 7923#include <AudioToolbox/AudioToolbox.h>
 7924#endif
 7925
 7926#include <AudioUnit/AudioUnit.h>
 7927
 7928#undef _THIS
 7929#define _THIS   SDL_AudioDevice *this
 7930
 7931#undef SDLAUDIOHIDDEN
 7932#define SDLAUDIOHIDDEN ((struct SDL_PrivateAudioDataCOREAUDIO*)this->hidden)
 7933struct SDL_PrivateAudioDataCOREAUDIO
 7934{
 7935    AudioUnit audioUnit;
 7936    int audioUnitOpened;
 7937    void *buffer;
 7938    UInt32 bufferOffset;
 7939    UInt32 bufferSize;
 7940#if MACOSX_COREAUDIO
 7941    AudioDeviceID deviceID;
 7942#endif
 7943};
 7944
 7945#endif
 7946
 7947#pragma clang diagnostic ignored "-Wdeprecated-declarations"
 7948
 7949#define DEBUG_COREAUDIO 0
 7950
 7951static void COREAUDIO_CloseDevice(_THIS);
 7952
 7953#define CHECK_RESULT(msg) \
 7954    if (result != noErr) { \
 7955        COREAUDIO_CloseDevice(this); \
 7956        SDL_SetError("CoreAudio error (%s): %d", msg, (int) result); \
 7957        return 0; \
 7958    }
 7959
 7960#if MACOSX_COREAUDIO
 7961typedef void (*addDevFn)(const char *name, AudioDeviceID devId, void *data);
 7962
 7963static void
 7964addToDevList(const char *name, AudioDeviceID devId, void *data)
 7965{
 7966    SDL_AddAudioDevice addfn = (SDL_AddAudioDevice) data;
 7967    addfn(name);
 7968}
 7969
 7970typedef struct
 7971{
 7972    const char *findname;
 7973    AudioDeviceID devId;
 7974    int found;
 7975} FindDevIdData;
 7976
 7977static void
 7978findDevId(const char *name, AudioDeviceID devId, void *_data)
 7979{
 7980    FindDevIdData *data = (FindDevIdData *) _data;
 7981    if (!data->found) {
 7982        if (SDL_strcmp(name, data->findname) == 0) {
 7983            data->found = 1;
 7984            data->devId = devId;
 7985        }
 7986    }
 7987}
 7988
 7989static void
 7990build_device_list(int iscapture, addDevFn addfn, void *addfndata)
 7991{
 7992    OSStatus result = noErr;
 7993    UInt32 size = 0;
 7994    AudioDeviceID *devs = NULL;
 7995    UInt32 i = 0;
 7996    UInt32 max = 0;
 7997
 7998    AudioObjectPropertyAddress addr = {
 7999        kAudioHardwarePropertyDevices,
 8000        kAudioObjectPropertyScopeGlobal,
 8001        kAudioObjectPropertyElementMaster
 8002    };
 8003
 8004    result = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &addr,
 8005                                            0, NULL, &size);
 8006    if (result != kAudioHardwareNoError)
 8007        return;
 8008
 8009    devs = (AudioDeviceID *) alloca(size);
 8010    if (devs == NULL)
 8011        return;
 8012
 8013    result = AudioObjectGetPropertyData(kAudioObjectSystemObject, &addr,
 8014                                        0, NULL, &size, devs);
 8015    if (result != kAudioHardwareNoError)
 8016        return;
 8017
 8018    max = size / sizeof (AudioDeviceID);
 8019    for (i = 0; i < max; i++) {
 8020        CFStringRef cfstr = NULL;
 8021        char *ptr = NULL;
 8022        AudioDeviceID dev = devs[i];
 8023        AudioBufferList *buflist = NULL;
 8024        int usable = 0;
 8025        CFIndex len = 0;
 8026
 8027        addr.mScope = iscapture ? kAudioDevicePropertyScopeInput :
 8028                        kAudioDevicePropertyScopeOutput;
 8029        addr.mSelector = kAudioDevicePropertyStreamConfiguration;
 8030
 8031        result = AudioObjectGetPropertyDataSize(dev, &addr, 0, NULL, &size);
 8032        if (result != noErr)
 8033            continue;
 8034
 8035        buflist = (AudioBufferList *) SDL_malloc(size);
 8036        if (buflist == NULL)
 8037            continue;
 8038
 8039        result = AudioObjectGetPropertyData(dev, &addr, 0, NULL,
 8040                                            &size, buflist);
 8041
 8042        if (result == noErr) {
 8043            UInt32 j;
 8044            for (j = 0; j < buflist->mNumberBuffers; j++) {
 8045                if (buflist->mBuffers[j].mNumberChannels > 0) {
 8046                    usable = 1;
 8047                    break;
 8048                }
 8049            }
 8050        }
 8051
 8052        SDL_free(buflist);
 8053
 8054        if (!usable)
 8055            continue;
 8056
 8057        addr.mSelector = kAudioObjectPropertyName;
 8058        size = sizeof (CFStringRef);
 8059        result = AudioObjectGetPropertyData(dev, &addr, 0, NULL, &size, &cfstr);
 8060        if (result != kAudioHardwareNoError)
 8061            continue;
 8062
 8063        len = CFStringGetMaximumSizeForEncoding(CFStringGetLength(cfstr),
 8064                                                kCFStringEncodingUTF8);
 8065
 8066        ptr = (char *) SDL_malloc(len + 1);
 8067        usable = ((ptr != NULL) &&
 8068                  (CFStringGetCString
 8069                   (cfstr, ptr, len + 1, kCFStringEncodingUTF8)));
 8070
 8071        CFRelease(cfstr);
 8072
 8073        if (usable) {
 8074            len = strlen(ptr);
 8075
 8076            while ((len > 0) && (ptr[len - 1] == ' ')) {
 8077                len--;
 8078            }
 8079            usable = (len > 0);
 8080        }
 8081
 8082        if (usable) {
 8083            ptr[len] = '\0';
 8084
 8085#if DEBUG_COREAUDIO
 8086            printf("COREAUDIO: Found %s device #%d: '%s' (devid %d)\n",
 8087                   ((iscapture) ? "capture" : "output"),
 8088                   (int) *devCount, ptr, (int) dev);
 8089#endif
 8090            addfn(ptr, dev, addfndata);
 8091        }
 8092        SDL_free(ptr);
 8093    }
 8094}
 8095
 8096static void
 8097COREAUDIO_DetectDevices(int iscapture, SDL_AddAudioDevice addfn)
 8098{
 8099    build_device_list(iscapture, addToDevList, addfn);
 8100}
 8101
 8102static int
 8103find_device_by_name(_THIS, const char *devname, int iscapture)
 8104{
 8105    AudioDeviceID devid = 0;
 8106    OSStatus result = noErr;
 8107    UInt32 size = 0;
 8108    UInt32 alive = 0;
 8109    pid_t pid = 0;
 8110
 8111    AudioObjectPropertyAddress addr = {
 8112        0,
 8113        kAudioObjectPropertyScopeGlobal,
 8114        kAudioObjectPropertyElementMaster
 8115    };
 8116
 8117    if (devname == NULL) {
 8118        size = sizeof (AudioDeviceID);
 8119        addr.mSelector =
 8120            ((iscapture) ? kAudioHardwarePropertyDefaultInputDevice :
 8121            kAudioHardwarePropertyDefaultOutputDevice);
 8122        result = AudioObjectGetPropertyData(kAudioObjectSystemObject, &addr,
 8123                                            0, NULL, &size, &devid);
 8124        CHECK_RESULT("AudioHardwareGetProperty (default device)");
 8125    } else {
 8126        FindDevIdData data;
 8127        SDL_zero(data);
 8128        data.findname = devname;
 8129        build_device_list(iscapture, findDevId, &data);
 8130        if (!data.found) {
 8131            SDL_SetError("CoreAudio: No such audio device.");
 8132            return 0;
 8133        }
 8134        devid = data.devId;
 8135    }
 8136
 8137    addr.mSelector = kAudioDevicePropertyDeviceIsAlive;
 8138    addr.mScope = iscapture ? kAudioDevicePropertyScopeInput :
 8139                    kAudioDevicePropertyScopeOutput;
 8140
 8141    size = sizeof (alive);
 8142    result = AudioObjectGetPropertyData(devid, &addr, 0, NULL, &size, &alive);
 8143    CHECK_RESULT
 8144        ("AudioDeviceGetProperty (kAudioDevicePropertyDeviceIsAlive)");
 8145
 8146    if (!alive) {
 8147        SDL_SetError("CoreAudio: requested device exists, but isn't alive.");
 8148        return 0;
 8149    }
 8150
 8151    addr.mSelector = kAudioDevicePropertyHogMode;
 8152    size = sizeof (pid);
 8153    result = AudioObjectGetPropertyData(devid, &addr, 0, NULL, &size, &pid);
 8154
 8155    if ((result == noErr) && (pid != -1)) {
 8156        SDL_SetError("CoreAudio: requested device is being hogged.");
 8157        return 0;
 8158    }
 8159
 8160    SDLAUDIOHIDDEN->deviceID = devid;
 8161    return 1;
 8162}
 8163#endif
 8164
 8165static OSStatus
 8166outputCallback(void *inRefCon,
 8167               AudioUnitRenderActionFlags * ioActionFlags,
 8168               const AudioTimeStamp * inTimeStamp,
 8169               UInt32 inBusNumber, UInt32 inNumberFrames,
 8170               AudioBufferList * ioData)
 8171{
 8172    SDL_AudioDevice *this = (SDL_AudioDevice *) inRefCon;
 8173    AudioBuffer *abuf;
 8174    UInt32 remaining, len;
 8175    void *ptr;
 8176    UInt32 i;
 8177
 8178    if (!this->enabled || this->paused) {
 8179        for (i = 0; i < ioData->mNumberBuffers; i++) {
 8180            abuf = &ioData->mBuffers[i];
 8181            SDL_memset(abuf->mData, this->spec.silence, abuf->mDataByteSize);
 8182        }
 8183        return 0;
 8184    }
 8185
 8186    for (i = 0; i < ioData->mNumberBuffers; i++) {
 8187        abuf = &ioData->mBuffers[i];
 8188        remaining = abuf->mDataByteSize;
 8189        ptr = abuf->mData;
 8190        while (remaining > 0) {
 8191            if (SDLAUDIOHIDDEN->bufferOffset >= SDLAUDIOHIDDEN->bufferSize) {
 8192
 8193                SDL_LockMutex(this->mixer_lock);
 8194                (*this->spec.callback)(this->spec.userdata,
 8195                            SDLAUDIOHIDDEN->buffer, SDLAUDIOHIDDEN->bufferSize);
 8196                SDL_UnlockMutex(this->mixer_lock);
 8197                SDLAUDIOHIDDEN->bufferOffset = 0;
 8198            }
 8199
 8200            len = SDLAUDIOHIDDEN->bufferSize - SDLAUDIOHIDDEN->bufferOffset;
 8201            if (len > remaining)
 8202                len = remaining;
 8203            SDL_memcpy(ptr, (char *)SDLAUDIOHIDDEN->buffer +
 8204                       SDLAUDIOHIDDEN->bufferOffset, len);
 8205            ptr = (char *)ptr + len;
 8206            remaining -= len;
 8207            SDLAUDIOHIDDEN->bufferOffset += len;
 8208        }
 8209    }
 8210
 8211    return 0;
 8212}
 8213
 8214static OSStatus
 8215inputCallback(void *inRefCon,
 8216              AudioUnitRenderActionFlags * ioActionFlags,
 8217              const AudioTimeStamp * inTimeStamp,
 8218              UInt32 inBusNumber, UInt32 inNumberFrames,
 8219              AudioBufferList * ioData)
 8220{
 8221
 8222    return noErr;
 8223}
 8224
 8225static void
 8226COREAUDIO_CloseDevice(_THIS)
 8227{
 8228    if (SDLAUDIOHIDDEN != NULL) {
 8229        if (SDLAUDIOHIDDEN->audioUnitOpened) {
 8230            OSStatus result = noErr;
 8231            AURenderCallbackStruct callback;
 8232            const AudioUnitElement output_bus = 0;
 8233            const AudioUnitElement input_bus = 1;
 8234            const int iscapture = this->iscapture;
 8235            const AudioUnitElement bus =
 8236                ((iscapture) ? input_bus : output_bus);
 8237            const AudioUnitScope scope =
 8238                ((iscapture) ? kAudioUnitScope_Output :
 8239                 kAudioUnitScope_Input);
 8240
 8241            result = AudioOutputUnitStop(SDLAUDIOHIDDEN->audioUnit);
 8242
 8243            SDL_memset(&callback, 0, sizeof(AURenderCallbackStruct));
 8244            result = AudioUnitSetProperty(SDLAUDIOHIDDEN->audioUnit,
 8245                                          kAudioUnitProperty_SetRenderCallback,
 8246                                          scope, bus, &callback,
 8247                                          sizeof(callback));
 8248
 8249            #if MACOSX_COREAUDIO
 8250            CloseComponent(SDLAUDIOHIDDEN->audioUnit);
 8251            #else
 8252            AudioComponentInstanceDispose(SDLAUDIOHIDDEN->audioUnit);
 8253            #endif
 8254
 8255            SDLAUDIOHIDDEN->audioUnitOpened = 0;
 8256        }
 8257        SDL_free(SDLAUDIOHIDDEN->buffer);
 8258        SDL_free(SDLAUDIOHIDDEN);
 8259        this->hidden = NULL;
 8260    }
 8261}
 8262
 8263static int
 8264prepare_audiounit(_THIS, const char *devname, int iscapture,
 8265                  const AudioStreamBasicDescription * strdesc)
 8266{
 8267    OSStatus result = noErr;
 8268    AURenderCallbackStruct callback;
 8269#if MACOSX_COREAUDIO
 8270    ComponentDescription desc;
 8271    Component comp = NULL;
 8272#else
 8273    AudioComponentDescription desc;
 8274    AudioComponent comp = NULL;
 8275#endif
 8276    const AudioUnitElement output_bus = 0;
 8277    const AudioUnitElement input_bus = 1;
 8278    const AudioUnitElement bus = ((iscapture) ? input_bus : output_bus);
 8279    const AudioUnitScope scope = ((iscapture) ? kAudioUnitScope_Output :
 8280                                  kAudioUnitScope_Input);
 8281
 8282#if MACOSX_COREAUDIO
 8283    if (!find_device_by_name(this, devname, iscapture)) {
 8284        SDL_SetError("Couldn't find requested CoreAudio device");
 8285        return 0;
 8286    }
 8287#endif
 8288
 8289    SDL_zero(desc);
 8290    desc.componentType = kAudioUnitType_Output;
 8291    desc.componentManufacturer = kAudioUnitManufacturer_Apple;
 8292
 8293#if MACOSX_COREAUDIO
 8294    desc.componentSubType = kAudioUnitSubType_DefaultOutput;
 8295    comp = FindNextComponent(NULL, &desc);
 8296#else
 8297    desc.componentSubType = kAudioUnitSubType_RemoteIO;
 8298    comp = AudioComponentFindNext(NULL, &desc);
 8299#endif
 8300
 8301    if (comp == NULL) {
 8302        SDL_SetError("Couldn't find requested CoreAudio component");
 8303        return 0;
 8304    }
 8305
 8306#if MACOSX_COREAUDIO
 8307    result = OpenAComponent(comp, &SDLAUDIOHIDDEN->audioUnit);
 8308    CHECK_RESULT("OpenAComponent");
 8309#else
 8310
 8311    result = AudioComponentInstanceNew(comp, &SDLAUDIOHIDDEN->audioUnit);
 8312    CHECK_RESULT("AudioComponentInstanceNew");
 8313#endif
 8314
 8315    SDLAUDIOHIDDEN->audioUnitOpened = 1;
 8316
 8317#if MACOSX_COREAUDIO
 8318    result = AudioUnitSetProperty(SDLAUDIOHIDDEN->audioUnit,
 8319                                  kAudioOutputUnitProperty_CurrentDevice,
 8320                                  kAudioUnitScope_Global, 0,
 8321                                  &SDLAUDIOHIDDEN->deviceID,
 8322                                  sizeof(AudioDeviceID));
 8323    CHECK_RESULT
 8324        ("AudioUnitSetProperty (kAudioOutputUnitProperty_CurrentDevice)");
 8325#endif
 8326
 8327    result = AudioUnitSetProperty(SDLAUDIOHIDDEN->audioUnit,
 8328                                  kAudioUnitProperty_StreamFormat,
 8329                                  scope, bus, strdesc, sizeof(*strdesc));
 8330    CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_StreamFormat)");
 8331
 8332    SDL_memset(&callback, 0, sizeof(AURenderCallbackStruct));
 8333    callback.inputProc = ((iscapture) ? inputCallback : outputCallback);
 8334    callback.inputProcRefCon = this;
 8335    result = AudioUnitSetProperty(SDLAUDIOHIDDEN->audioUnit,
 8336                                  kAudioUnitProperty_SetRenderCallback,
 8337                                  scope, bus, &callback, sizeof(callback));
 8338    CHECK_RESULT
 8339        ("AudioUnitSetProperty (kAudioUnitProperty_SetRenderCallback)");
 8340
 8341    SDL_CalculateAudioSpec(&this->spec);
 8342
 8343    SDLAUDIOHIDDEN->bufferOffset = SDLAUDIOHIDDEN->bufferSize = this->spec.size;
 8344    SDLAUDIOHIDDEN->buffer = SDL_malloc(SDLAUDIOHIDDEN->bufferSize);
 8345
 8346    result = AudioUnitInitialize(SDLAUDIOHIDDEN->audioUnit);
 8347    CHECK_RESULT("AudioUnitInitialize");
 8348
 8349    result = AudioOutputUnitStart(SDLAUDIOHIDDEN->audioUnit);
 8350    CHECK_RESULT("AudioOutputUnitStart");
 8351
 8352    return 1;
 8353}
 8354
 8355static int
 8356COREAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
 8357{
 8358    AudioStreamBasicDescription strdesc;
 8359    SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
 8360    int valid_datatype = 0;
 8361
 8362    this->hidden = (struct SDL_PrivateAudioData *)
 8363        SDL_malloc((sizeof *SDLAUDIOHIDDEN));
 8364    if (SDLAUDIOHIDDEN == NULL) {
 8365        return SDL_OutOfMemory();
 8366    }
 8367    SDL_memset(SDLAUDIOHIDDEN, 0, (sizeof *SDLAUDIOHIDDEN));
 8368
 8369    SDL_memset(&strdesc, '\0', sizeof(AudioStreamBasicDescription));
 8370    strdesc.mFormatID = kAudioFormatLinearPCM;
 8371    strdesc.mFormatFlags = kLinearPCMFormatFlagIsPacked;
 8372    strdesc.mChannelsPerFrame = this->spec.channels;
 8373    strdesc.mSampleRate = this->spec.freq;
 8374    strdesc.mFramesPerPacket = 1;
 8375
 8376    while ((!valid_datatype) && (test_format)) {
 8377        this->spec.format = test_format;
 8378
 8379        switch (test_format) {
 8380        case AUDIO_U8:
 8381        case AUDIO_S8:
 8382        case AUDIO_U16LSB:
 8383        case AUDIO_S16LSB:
 8384        case AUDIO_U16MSB:
 8385        case AUDIO_S16MSB:
 8386        case AUDIO_S32LSB:
 8387        case AUDIO_S32MSB:
 8388        case AUDIO_F32LSB:
 8389        case AUDIO_F32MSB:
 8390            valid_datatype = 1;
 8391            strdesc.mBitsPerChannel = SDL_AUDIO_BITSIZE(this->spec.format);
 8392            if (SDL_AUDIO_ISBIGENDIAN(this->spec.format))
 8393                strdesc.mFormatFlags |= kLinearPCMFormatFlagIsBigEndian;
 8394
 8395            if (SDL_AUDIO_ISFLOAT(this->spec.format))
 8396                strdesc.mFormatFlags |= kLinearPCMFormatFlagIsFloat;
 8397            else if (SDL_AUDIO_ISSIGNED(this->spec.format))
 8398                strdesc.mFormatFlags |= kLinearPCMFormatFlagIsSignedInteger;
 8399            break;
 8400        }
 8401    }
 8402
 8403    if (!valid_datatype) {
 8404        COREAUDIO_CloseDevice(this);
 8405        return SDL_SetError("Unsupported audio format");
 8406    }
 8407
 8408    strdesc.mBytesPerFrame =
 8409        strdesc.mBitsPerChannel * strdesc.mChannelsPerFrame / 8;
 8410    strdesc.mBytesPerPacket =
 8411        strdesc.mBytesPerFrame * strdesc.mFramesPerPacket;
 8412
 8413    if (!prepare_audiounit(this, devname, iscapture, &strdesc)) {
 8414        COREAUDIO_CloseDevice(this);
 8415        return -1;
 8416    }
 8417
 8418    return 0;
 8419}
 8420
 8421static int
 8422COREAUDIO_Init(SDL_AudioDriverImpl * impl)
 8423{
 8424
 8425    impl->OpenDevice = COREAUDIO_OpenDevice;
 8426    impl->CloseDevice = COREAUDIO_CloseDevice;
 8427
 8428#if MACOSX_COREAUDIO
 8429    impl->DetectDevices = COREAUDIO_DetectDevices;
 8430#else
 8431    impl->OnlyHasDefaultOutputDevice = 1;
 8432
 8433    AudioSessionInitialize(NULL, NULL, NULL, nil);
 8434    UInt32 category = kAudioSessionCategory_AmbientSound;
 8435    AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(UInt32), &category);
 8436#endif
 8437
 8438    impl->ProvidesOwnCallbackThread = 1;
 8439
 8440    return 1;
 8441}
 8442
 8443AudioBootStrap COREAUDIO_bootstrap = {
 8444    "coreaudio", "CoreAudio", COREAUDIO_Init, 0
 8445};
 8446
 8447#endif
 8448#if SDL_AUDIO_DRIVER_DSOUND
 8449
 8450#ifndef _SDL_directsound_h
 8451#define _SDL_directsound_h
 8452
 8453#ifndef _directx_h
 8454#define _directx_h
 8455
 8456#include <mmsystem.h>
 8457#ifndef WIN32
 8458#define WIN32
 8459#endif
 8460#undef  WINNT
 8461
 8462#ifndef FAR
 8463#define FAR
 8464#endif
 8465
 8466#ifndef MAKE_HRESULT
 8467#define MAKE_HRESULT(sev,fac,code) \
 8468    ((HRESULT)(((unsigned long)(sev)<<31) | ((unsigned long)(fac)<<16) | ((unsigned long)(code))))
 8469#endif
 8470
 8471#ifndef S_OK
 8472#define S_OK        (HRESULT)0x00000000L
 8473#endif
 8474
 8475#ifndef SUCCEEDED
 8476#define SUCCEEDED(x)    ((HRESULT)(x) >= 0)
 8477#endif
 8478#ifndef FAILED
 8479#define FAILED(x)   ((HRESULT)(x)<0)
 8480#endif
 8481
 8482#ifndef E_FAIL
 8483#define E_FAIL      (HRESULT)0x80000008L
 8484#endif
 8485#ifndef E_NOINTERFACE
 8486#define E_NOINTERFACE   (HRESULT)0x80004002L
 8487#endif
 8488#ifndef E_OUTOFMEMORY
 8489#define E_OUTOFMEMORY   (HRESULT)0x8007000EL
 8490#endif
 8491#ifndef E_INVALIDARG
 8492#define E_INVALIDARG    (HRESULT)0x80070057L
 8493#endif
 8494#ifndef E_NOTIMPL
 8495#define E_NOTIMPL   (HRESULT)0x80004001L
 8496#endif
 8497#ifndef REGDB_E_CLASSNOTREG
 8498#define REGDB_E_CLASSNOTREG (HRESULT)0x80040154L
 8499#endif
 8500
 8501#ifndef SEVERITY_ERROR
 8502#define SEVERITY_ERROR  1
 8503#endif
 8504
 8505#ifndef FACILITY_WIN32
 8506#define FACILITY_WIN32  7
 8507#endif
 8508
 8509#ifndef FIELD_OFFSET
 8510#define FIELD_OFFSET(type, field)    ((LONG)&(((type *)0)->field))
 8511#endif
 8512
 8513#define DIRECTDRAW_VERSION  0x0700
 8514#define DIRECTSOUND_VERSION 0x0800
 8515#define DIRECTINPUT_VERSION 0x0500
 8516
 8517#include <ddraw.h>
 8518#define COM_NO_WINDOWS_H
 8519#include <objbase.h>
 8520#include <float.h>
 8521
 8522#ifndef DIRECTSOUND_VERSION
 8523#define DIRECTSOUND_VERSION 0x0800
 8524#endif
 8525
 8526#ifdef __cplusplus
 8527extern "C" {
 8528#endif
 8529
 8530#ifndef __DSOUND_INCLUDED__
 8531#define __DSOUND_INCLUDED__
 8532
 8533#ifndef DX_SHARED_DEFINES
 8534
 8535typedef float D3DVALUE, *LPD3DVALUE;
 8536
 8537#ifndef D3DCOLOR_DEFINED
 8538typedef DWORD D3DCOLOR;
 8539#define D3DCOLOR_DEFINED
 8540#endif
 8541
 8542#ifndef LPD3DCOLOR_DEFINED
 8543typedef DWORD *LPD3DCOLOR;
 8544#define LPD3DCOLOR_DEFINED
 8545#endif
 8546
 8547#ifndef D3DVECTOR_DEFINED
 8548typedef struct _D3DVECTOR {
 8549    float x;
 8550    float y;
 8551    float z;
 8552} D3DVECTOR;
 8553#define D3DVECTOR_DEFINED
 8554#endif
 8555
 8556#ifndef LPD3DVECTOR_DEFINED
 8557typedef D3DVECTOR *LPD3DVECTOR;
 8558#define LPD3DVECTOR_DEFINED
 8559#endif
 8560
 8561#define DX_SHARED_DEFINES
 8562#endif
 8563
 8564#define _FACDS  0x878
 8565#define MAKE_DSHRESULT(code)  MAKE_HRESULT(1, _FACDS, code)
 8566
 8567DEFINE_GUID(CLSID_DirectSound, 0x47d4d946, 0x62e8, 0x11cf, 0x93, 0xbc, 0x44, 0x45, 0x53, 0x54, 0x0, 0x0);
 8568
 8569DEFINE_GUID(CLSID_DirectSound8, 0x3901cc3f, 0x84b5, 0x4fa4, 0xba, 0x35, 0xaa, 0x81, 0x72, 0xb8, 0xa0, 0x9b);
 8570
 8571DEFINE_GUID(CLSID_DirectSoundCapture, 0xb0210780, 0x89cd, 0x11d0, 0xaf, 0x8, 0x0, 0xa0, 0xc9, 0x25, 0xcd, 0x16);
 8572
 8573DEFINE_GUID(CLSID_DirectSoundCapture8, 0xe4bcac13, 0x7f99, 0x4908, 0x9a, 0x8e, 0x74, 0xe3, 0xbf, 0x24, 0xb6, 0xe1);
 8574
 8575DEFINE_GUID(CLSID_DirectSoundFullDuplex, 0xfea4300c, 0x7959, 0x4147, 0xb2, 0x6a, 0x23, 0x77, 0xb9, 0xe7, 0xa9, 0x1d);
 8576
 8577DEFINE_GUID(DSDEVID_DefaultPlayback, 0xdef00000, 0x9c6d, 0x47ed, 0xaa, 0xf1, 0x4d, 0xda, 0x8f, 0x2b, 0x5c, 0x03);
 8578
 8579DEFINE_GUID(DSDEVID_DefaultCapture, 0xdef00001, 0x9c6d, 0x47ed, 0xaa, 0xf1, 0x4d, 0xda, 0x8f, 0x2b, 0x5c, 0x03);
 8580
 8581DEFINE_GUID(DSDEVID_DefaultVoicePlayback, 0xdef00002, 0x9c6d, 0x47ed, 0xaa, 0xf1, 0x4d, 0xda, 0x8f, 0x2b, 0x5c, 0x03);
 8582
 8583DEFINE_GUID(DSDEVID_DefaultVoiceCapture, 0xdef00003, 0x9c6d, 0x47ed, 0xaa, 0xf1, 0x4d, 0xda, 0x8f, 0x2b, 0x5c, 0x03);
 8584
 8585#ifdef __cplusplus
 8586struct IDirectSound;
 8587struct IDirectSoundBuffer;
 8588struct IDirectSound3DListener;
 8589struct IDirectSound3DBuffer;
 8590struct IDirectSoundCapture;
 8591struct IDirectSoundCaptureBuffer;
 8592struct IDirectSoundNotify;
 8593#endif
 8594
 8595#if DIRECTSOUND_VERSION >= 0x0800
 8596
 8597#ifdef __cplusplus
 8598struct IDirectSound8;
 8599struct IDirectSoundBuffer8;
 8600struct IDirectSoundCaptureBuffer8;
 8601struct IDirectSoundFXGargle;
 8602struct IDirectSoundFXChorus;
 8603struct IDirectSoundFXFlanger;
 8604struct IDirectSoundFXEcho;
 8605struct IDirectSoundFXDistortion;
 8606struct IDirectSoundFXCompressor;
 8607struct IDirectSoundFXParamEq;
 8608struct IDirectSoundFXWavesReverb;
 8609struct IDirectSoundFXI3DL2Reverb;
 8610struct IDirectSoundCaptureFXAec;
 8611struct IDirectSoundCaptureFXNoiseSuppress;
 8612struct IDirectSoundFullDuplex;
 8613#endif
 8614
 8615#define IDirectSoundCapture8            IDirectSoundCapture
 8616#define IDirectSound3DListener8         IDirectSound3DListener
 8617#define IDirectSound3DBuffer8           IDirectSound3DBuffer
 8618#define IDirectSoundNotify8             IDirectSoundNotify
 8619#define IDirectSoundFXGargle8           IDirectSoundFXGargle
 8620#define IDirectSoundFXChorus8           IDirectSoundFXChorus
 8621#define IDirectSoundFXFlanger8          IDirectSoundFXFlanger
 8622#define IDirectSoundFXEcho8             IDirectSoundFXEcho
 8623#define IDirectSoundFXDistortion8       IDirectSoundFXDistortion
 8624#define IDirectSoundFXCompressor8       IDirectSoundFXCompressor
 8625#define IDirectSoundFXParamEq8          IDirectSoundFXParamEq
 8626#define IDirectSoundFXWavesReverb8      IDirectSoundFXWavesReverb
 8627#define IDirectSoundFXI3DL2Reverb8      IDirectSoundFXI3DL2Reverb
 8628#define IDirectSoundCaptureFXAec8       IDirectSoundCaptureFXAec
 8629#define IDirectSoundCaptureFXNoiseSuppress8 IDirectSoundCaptureFXNoiseSuppress
 8630#define IDirectSoundFullDuplex8         IDirectSoundFullDuplex
 8631
 8632#endif
 8633
 8634typedef struct IDirectSound                 *LPDIRECTSOUND;
 8635typedef struct IDirectSoundBuffer           *LPDIRECTSOUNDBUFFER;
 8636typedef struct IDirectSound3DListener       *LPDIRECTSOUND3DLISTENER;
 8637typedef struct IDirectSound3DBuffer         *LPDIRECTSOUND3DBUFFER;
 8638typedef struct IDirectSoundCapture          *LPDIRECTSOUNDCAPTURE;
 8639typedef struct IDirectSoundCaptureBuffer    *LPDIRECTSOUNDCAPTUREBUFFER;
 8640typedef struct IDirectSoundNotify           *LPDIRECTSOUNDNOTIFY;
 8641
 8642#if DIRECTSOUND_VERSION >= 0x0800
 8643typedef struct IDirectSoundFXGargle         *LPDIRECTSOUNDFXGARGLE;
 8644typedef struct IDirectSoundFXChorus         *LPDIRECTSOUNDFXCHORUS;
 8645typedef struct IDirectSoundFXFlanger        *LPDIRECTSOUNDFXFLANGER;
 8646typedef struct IDirectSoundFXEcho           *LPDIRECTSOUNDFXECHO;
 8647typedef struct IDirectSoundFXDistortion     *LPDIRECTSOUNDFXDISTORTION;
 8648typedef struct IDirectSoundFXCompressor     *LPDIRECTSOUNDFXCOMPRESSOR;
 8649typedef struct IDirectSoundFXParamEq        *LPDIRECTSOUNDFXPARAMEQ;
 8650typedef struct IDirectSoundFXWavesReverb    *LPDIRECTSOUNDFXWAVESREVERB;
 8651typedef struct IDirectSoundFXI3DL2Reverb    *LPDIRECTSOUNDFXI3DL2REVERB;
 8652typedef struct IDirectSoundCaptureFXAec     *LPDIRECTSOUNDCAPTUREFXAEC;
 8653typedef struct IDirectSoundCaptureFXNoiseSuppress *LPDIRECTSOUNDCAPTUREFXNOISESUPPRESS;
 8654typedef struct IDirectSoundFullDuplex       *LPDIRECTSOUNDFULLDUPLEX;
 8655
 8656typedef struct IDirectSound8                *LPDIRECTSOUND8;
 8657typedef struct IDirectSoundBuffer8          *LPDIRECTSOUNDBUFFER8;
 8658typedef struct IDirectSound3DListener8      *LPDIRECTSOUND3DLISTENER8;
 8659typedef struct IDirectSound3DBuffer8        *LPDIRECTSOUND3DBUFFER8;
 8660typedef struct IDirectSoundCapture8         *LPDIRECTSOUNDCAPTURE8;
 8661typedef struct IDirectSoundCaptureBuffer8   *LPDIRECTSOUNDCAPTUREBUFFER8;
 8662typedef struct IDirectSoundNotify8          *LPDIRECTSOUNDNOTIFY8;
 8663typedef struct IDirectSoundFXGargle8        *LPDIRECTSOUNDFXGARGLE8;
 8664typedef struct IDirectSoundFXChorus8        *LPDIRECTSOUNDFXCHORUS8;
 8665typedef struct IDirectSoundFXFlanger8       *LPDIRECTSOUNDFXFLANGER8;
 8666typedef struct IDirectSoundFXEcho8          *LPDIRECTSOUNDFXECHO8;
 8667typedef struct IDirectSoundFXDistortion8    *LPDIRECTSOUNDFXDISTORTION8;
 8668typedef struct IDirectSoundFXCompressor8    *LPDIRECTSOUNDFXCOMPRESSOR8;
 8669typedef struct IDirectSoundFXParamEq8       *LPDIRECTSOUNDFXPARAMEQ8;
 8670typedef struct IDirectSoundFXWavesReverb8   *LPDIRECTSOUNDFXWAVESREVERB8;
 8671typedef struct IDirectSoundFXI3DL2Reverb8   *LPDIRECTSOUNDFXI3DL2REVERB8;
 8672typedef struct IDirectSoundCaptureFXAec8    *LPDIRECTSOUNDCAPTUREFXAEC8;
 8673typedef struct IDirectSoundCaptureFXNoiseSuppress8 *LPDIRECTSOUNDCAPTUREFXNOISESUPPRESS8;
 8674typedef struct IDirectSoundFullDuplex8      *LPDIRECTSOUNDFULLDUPLEX8;
 8675
 8676#endif
 8677
 8678#if DIRECTSOUND_VERSION >= 0x0800
 8679#define IID_IDirectSoundCapture8            IID_IDirectSoundCapture
 8680#define IID_IDirectSound3DListener8         IID_IDirectSound3DListener
 8681#define IID_IDirectSound3DBuffer8           IID_IDirectSound3DBuffer
 8682#define IID_IDirectSoundNotify8             IID_IDirectSoundNotify
 8683#define IID_IDirectSoundFXGargle8           IID_IDirectSoundFXGargle
 8684#define IID_IDirectSoundFXChorus8           IID_IDirectSoundFXChorus
 8685#define IID_IDirectSoundFXFlanger8          IID_IDirectSoundFXFlanger
 8686#define IID_IDirectSoundFXEcho8             IID_IDirectSoundFXEcho
 8687#define IID_IDirectSoundFXDistortion8       IID_IDirectSoundFXDistortion
 8688#define IID_IDirectSoundFXCompressor8       IID_IDirectSoundFXCompressor
 8689#define IID_IDirectSoundFXParamEq8          IID_IDirectSoundFXParamEq
 8690#define IID_IDirectSoundFXWavesReverb8      IID_IDirectSoundFXWavesReverb
 8691#define IID_IDirectSoundFXI3DL2Reverb8      IID_IDirectSoundFXI3DL2Reverb
 8692#define IID_IDirectSoundCaptureFXAec8       IID_IDirectSoundCaptureFXAec
 8693#define IID_IDirectSoundCaptureFXNoiseSuppress8 IID_IDirectSoundCaptureFXNoiseSuppress
 8694#define IID_IDirectSoundFullDuplex8         IID_IDirectSoundFullDuplex
 8695#endif
 8696
 8697#ifndef _LPCWAVEFORMATEX_DEFINED
 8698#define _LPCWAVEFORMATEX_DEFINED
 8699typedef const WAVEFORMATEX *LPCWAVEFORMATEX;
 8700#endif
 8701
 8702#ifndef __LPCGUID_DEFINED__
 8703#define __LPCGUID_DEFINED__
 8704typedef const GUID *LPCGUID;
 8705#endif
 8706
 8707typedef LPDIRECTSOUND *LPLPDIRECTSOUND;
 8708typedef LPDIRECTSOUNDBUFFER *LPLPDIRECTSOUNDBUFFER;
 8709typedef LPDIRECTSOUND3DLISTENER *LPLPDIRECTSOUND3DLISTENER;
 8710typedef LPDIRECTSOUND3DBUFFER *LPLPDIRECTSOUND3DBUFFER;
 8711typedef LPDIRECTSOUNDCAPTURE *LPLPDIRECTSOUNDCAPTURE;
 8712typedef LPDIRECTSOUNDCAPTUREBUFFER *LPLPDIRECTSOUNDCAPTUREBUFFER;
 8713typedef LPDIRECTSOUNDNOTIFY *LPLPDIRECTSOUNDNOTIFY;
 8714
 8715#if DIRECTSOUND_VERSION >= 0x0800
 8716typedef LPDIRECTSOUND8 *LPLPDIRECTSOUND8;
 8717typedef LPDIRECTSOUNDBUFFER8 *LPLPDIRECTSOUNDBUFFER8;
 8718typedef LPDIRECTSOUNDCAPTURE8 *LPLPDIRECTSOUNDCAPTURE8;
 8719typedef LPDIRECTSOUNDCAPTUREBUFFER8 *LPLPDIRECTSOUNDCAPTUREBUFFER8;
 8720#endif
 8721
 8722typedef struct _DSCAPS
 8723{
 8724    DWORD           dwSize;
 8725    DWORD           dwFlags;
 8726    DWORD           dwMinSecondarySampleRate;
 8727    DWORD           dwMaxSecondarySampleRate;
 8728    DWORD           dwPrimaryBuffers;
 8729    DWORD           dwMaxHwMixingAllBuffers;
 8730    DWORD           dwMaxHwMixingStaticBuffers;
 8731    DWORD           dwMaxHwMixingStreamingBuffers;
 8732    DWORD           dwFreeHwMixingAllBuffers;
 8733    DWORD           dwFreeHwMixingStaticBuffers;
 8734    DWORD           dwFreeHwMixingStreamingBuffers;
 8735    DWORD           dwMaxHw3DAllBuffers;
 8736    DWORD           dwMaxHw3DStaticBuffers;
 8737    DWORD           dwMaxHw3DStreamingBuffers;
 8738    DWORD           dwFreeHw3DAllBuffers;
 8739    DWORD           dwFreeHw3DStaticBuffers;
 8740    DWORD           dwFreeHw3DStreamingBuffers;
 8741    DWORD           dwTotalHwMemBytes;
 8742    DWORD           dwFreeHwMemBytes;
 8743    DWORD           dwMaxContigFreeHwMemBytes;
 8744    DWORD           dwUnlockTransferRateHwBuffers;
 8745    DWORD           dwPlayCpuOverheadSwBuffers;
 8746    DWORD           dwReserved1;
 8747    DWORD           dwReserved2;
 8748} DSCAPS, *LPDSCAPS;
 8749
 8750typedef const DSCAPS *LPCDSCAPS;
 8751
 8752typedef struct _DSBCAPS
 8753{
 8754    DWORD           dwSize;
 8755    DWORD           dwFlags;
 8756    DWORD           dwBufferBytes;
 8757    DWORD           dwUnlockTransferRate;
 8758    DWORD           dwPlayCpuOverhead;
 8759} DSBCAPS, *LPDSBCAPS;
 8760
 8761typedef const DSBCAPS *LPCDSBCAPS;
 8762
 8763#if DIRECTSOUND_VERSION >= 0x0800
 8764
 8765    typedef struct _DSEFFECTDESC
 8766    {
 8767        DWORD       dwSize;
 8768        DWORD       dwFlags;
 8769        GUID        guidDSFXClass;
 8770        DWORD       dwReserved1;
 8771        DWORD       dwReserved2;
 8772    } DSEFFECTDESC, *LPDSEFFECTDESC;
 8773    typedef const DSEFFECTDESC *LPCDSEFFECTDESC;
 8774
 8775    #define DSFX_LOCHARDWARE    0x00000001
 8776    #define DSFX_LOCSOFTWARE    0x00000002
 8777
 8778    enum
 8779    {
 8780        DSFXR_PRESENT,
 8781        DSFXR_LOCHARDWARE,
 8782        DSFXR_LOCSOFTWARE,
 8783        DSFXR_UNALLOCATED,
 8784        DSFXR_FAILED,
 8785        DSFXR_UNKNOWN,
 8786        DSFXR_SENDLOOP
 8787    };
 8788
 8789    typedef struct _DSCEFFECTDESC
 8790    {
 8791        DWORD       dwSize;
 8792        DWORD       dwFlags;
 8793        GUID        guidDSCFXClass;
 8794        GUID        guidDSCFXInstance;
 8795        DWORD       dwReserved1;
 8796        DWORD       dwReserved2;
 8797    } DSCEFFECTDESC, *LPDSCEFFECTDESC;
 8798    typedef const DSCEFFECTDESC *LPCDSCEFFECTDESC;
 8799
 8800    #define DSCFX_LOCHARDWARE   0x00000001
 8801    #define DSCFX_LOCSOFTWARE   0x00000002
 8802
 8803    #define DSCFXR_LOCHARDWARE  0x00000010
 8804    #define DSCFXR_LOCSOFTWARE  0x00000020
 8805    #define DSCFXR_UNALLOCATED  0x00000040
 8806    #define DSCFXR_FAILED       0x00000080
 8807    #define DSCFXR_UNKNOWN      0x00000100
 8808
 8809#endif
 8810
 8811typedef struct _DSBUFFERDESC
 8812{
 8813    DWORD           dwSize;
 8814    DWORD           dwFlags;
 8815    DWORD           dwBufferBytes;
 8816    DWORD           dwReserved;
 8817    LPWAVEFORMATEX  lpwfxFormat;
 8818#if DIRECTSOUND_VERSION >= 0x0700
 8819    GUID            guid3DAlgorithm;
 8820#endif
 8821} DSBUFFERDESC, *LPDSBUFFERDESC;
 8822
 8823typedef const DSBUFFERDESC *LPCDSBUFFERDESC;
 8824
 8825typedef struct _DSBUFFERDESC1
 8826{
 8827    DWORD           dwSize;
 8828    DWORD           dwFlags;
 8829    DWORD           dwBufferBytes;
 8830    DWORD           dwReserved;
 8831    LPWAVEFORMATEX  lpwfxFormat;
 8832} DSBUFFERDESC1, *LPDSBUFFERDESC1;
 8833
 8834typedef const DSBUFFERDESC1 *LPCDSBUFFERDESC1;
 8835
 8836typedef struct _DS3DBUFFER
 8837{
 8838    DWORD           dwSize;
 8839    D3DVECTOR       vPosition;
 8840    D3DVECTOR       vVelocity;
 8841    DWORD           dwInsideConeAngle;
 8842    DWORD           dwOutsideConeAngle;
 8843    D3DVECTOR       vConeOrientation;
 8844    LONG            lConeOutsideVolume;
 8845    D3DVALUE        flMinDistance;
 8846    D3DVALUE        flMaxDistance;
 8847    DWORD           dwMode;
 8848} DS3DBUFFER, *LPDS3DBUFFER;
 8849
 8850typedef const DS3DBUFFER *LPCDS3DBUFFER;
 8851
 8852typedef struct _DS3DLISTENER
 8853{
 8854    DWORD           dwSize;
 8855    D3DVECTOR       vPosition;
 8856    D3DVECTOR       vVelocity;
 8857    D3DVECTOR       vOrientFront;
 8858    D3DVECTOR       vOrientTop;
 8859    D3DVALUE        flDistanceFactor;
 8860    D3DVALUE        flRolloffFactor;
 8861    D3DVALUE        flDopplerFactor;
 8862} DS3DLISTENER, *LPDS3DLISTENER;
 8863
 8864typedef const DS3DLISTENER *LPCDS3DLISTENER;
 8865
 8866typedef struct _DSCCAPS
 8867{
 8868    DWORD           dwSize;
 8869    DWORD           dwFlags;
 8870    DWORD           dwFormats;
 8871    DWORD           dwChannels;
 8872} DSCCAPS, *LPDSCCAPS;
 8873
 8874typedef const DSCCAPS *LPCDSCCAPS;
 8875
 8876typedef struct _DSCBUFFERDESC1
 8877{
 8878    DWORD           dwSize;
 8879    DWORD           dwFlags;
 8880    DWORD           dwBufferBytes;
 8881    DWORD           dwReserved;
 8882    LPWAVEFORMATEX  lpwfxFormat;
 8883} DSCBUFFERDESC1, *LPDSCBUFFERDESC1;
 8884
 8885typedef struct _DSCBUFFERDESC
 8886{
 8887    DWORD           dwSize;
 8888    DWORD           dwFlags;
 8889    DWORD           dwBufferBytes;
 8890    DWORD           dwReserved;
 8891    LPWAVEFORMATEX  lpwfxFormat;
 8892#if DIRECTSOUND_VERSION >= 0x0800
 8893    DWORD           dwFXCount;
 8894    LPDSCEFFECTDESC lpDSCFXDesc;
 8895#endif
 8896} DSCBUFFERDESC, *LPDSCBUFFERDESC;
 8897
 8898typedef const DSCBUFFERDESC *LPCDSCBUFFERDESC;
 8899
 8900typedef struct _DSCBCAPS
 8901{
 8902    DWORD           dwSize;
 8903    DWORD           dwFlags;
 8904    DWORD           dwBufferBytes;
 8905    DWORD           dwReserved;
 8906} DSCBCAPS, *LPDSCBCAPS;
 8907
 8908typedef const DSCBCAPS *LPCDSCBCAPS;
 8909
 8910typedef struct _DSBPOSITIONNOTIFY
 8911{
 8912    DWORD           dwOffset;
 8913    HANDLE          hEventNotify;
 8914} DSBPOSITIONNOTIFY, *LPDSBPOSITIONNOTIFY;
 8915
 8916typedef const DSBPOSITIONNOTIFY *LPCDSBPOSITIONNOTIFY;
 8917
 8918typedef BOOL (CALLBACK *LPDSENUMCALLBACKA)(LPGUID, LPCSTR, LPCSTR, LPVOID);
 8919typedef BOOL (CALLBACK *LPDSENUMCALLBACKW)(LPGUID, LPCWSTR, LPCWSTR, LPVOID);
 8920
 8921extern HRESULT WINAPI DirectSoundCreate(LPCGUID pcGuidDevice, LPDIRECTSOUND *ppDS, LPUNKNOWN pUnkOuter);
 8922extern HRESULT WINAPI DirectSoundEnumerateA(LPDSENUMCALLBACKA pDSEnumCallback, LPVOID pContext);
 8923extern HRESULT WINAPI DirectSoundEnumerateW(LPDSENUMCALLBACKW pDSEnumCallback, LPVOID pContext);
 8924
 8925extern HRESULT WINAPI DirectSoundCaptureCreate(LPCGUID pcGuidDevice, LPDIRECTSOUNDCAPTURE *ppDSC, LPUNKNOWN pUnkOuter);
 8926extern HRESULT WINAPI DirectSoundCaptureEnumerateA(LPDSENUMCALLBACKA pDSEnumCallback, LPVOID pContext);
 8927extern HRESULT WINAPI DirectSoundCaptureEnumerateW(LPDSENUMCALLBACKW pDSEnumCallback, LPVOID pContext);
 8928
 8929#if DIRECTSOUND_VERSION >= 0x0800
 8930extern HRESULT WINAPI DirectSoundCreate8(LPCGUID pcGuidDevice, LPDIRECTSOUND8 *ppDS8, LPUNKNOWN pUnkOuter);
 8931extern HRESULT WINAPI DirectSoundCaptureCreate8(LPCGUID pcGuidDevice, LPDIRECTSOUNDCAPTURE8 *ppDSC8, LPUNKNOWN pUnkOuter);
 8932extern HRESULT WINAPI DirectSoundFullDuplexCreate(LPCGUID pcGuidCaptureDevice, LPCGUID pcGuidRenderDevice,
 8933        LPCDSCBUFFERDESC pcDSCBufferDesc, LPCDSBUFFERDESC pcDSBufferDesc, HWND hWnd,
 8934        DWORD dwLevel, LPDIRECTSOUNDFULLDUPLEX* ppDSFD, LPDIRECTSOUNDCAPTUREBUFFER8 *ppDSCBuffer8,
 8935        LPDIRECTSOUNDBUFFER8 *ppDSBuffer8, LPUNKNOWN pUnkOuter);
 8936#define DirectSoundFullDuplexCreate8 DirectSoundFullDuplexCreate
 8937
 8938extern HRESULT WINAPI GetDeviceID(LPCGUID pGuidSrc, LPGUID pGuidDest);
 8939#endif
 8940
 8941#ifdef UNICODE
 8942#define LPDSENUMCALLBACK            LPDSENUMCALLBACKW
 8943#define DirectSoundEnumerate        DirectSoundEnumerateW
 8944#define DirectSoundCaptureEnumerate DirectSoundCaptureEnumerateW
 8945#else
 8946#define LPDSENUMCALLBACK            LPDSENUMCALLBACKA
 8947#define DirectSoundEnumerate        DirectSoundEnumerateA
 8948#define DirectSoundCaptureEnumerate DirectSoundCaptureEnumerateA
 8949#endif
 8950
 8951#if !defined(__cplusplus) || defined(CINTERFACE)
 8952#ifndef IUnknown_QueryInterface
 8953#define IUnknown_QueryInterface(p,a,b)  (p)->lpVtbl->QueryInterface(p,a,b)
 8954#endif
 8955#ifndef IUnknown_AddRef
 8956#define IUnknown_AddRef(p)              (p)->lpVtbl->AddRef(p)
 8957#endif
 8958#ifndef IUnknown_Release
 8959#define IUnknown_Release(p)             (p)->lpVtbl->Release(p)
 8960#endif
 8961#else
 8962#ifndef IUnknown_QueryInterface
 8963#define IUnknown_QueryInterface(p,a,b)  (p)->QueryInterface(a,b)
 8964#endif
 8965#ifndef IUnknown_AddRef
 8966#define IUnknown_AddRef(p)              (p)->AddRef()
 8967#endif
 8968#ifndef IUnknown_Release
 8969#define IUnknown_Release(p)             (p)->Release()
 8970#endif
 8971#endif
 8972
 8973#ifndef __IReferenceClock_INTERFACE_DEFINED__
 8974#define __IReferenceClock_INTERFACE_DEFINED__
 8975
 8976typedef LONGLONG REFERENCE_TIME;
 8977typedef REFERENCE_TIME *LPREFERENCE_TIME;
 8978
 8979DEFINE_GUID(IID_IReferenceClock, 0x56a86897, 0x0ad4, 0x11ce, 0xb0, 0x3a, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70);
 8980
 8981#undef INTERFACE
 8982#define INTERFACE IReferenceClock
 8983
 8984DECLARE_INTERFACE_(IReferenceClock, IUnknown)
 8985{
 8986
 8987    STDMETHOD(QueryInterface)       (THIS_ REFIID, LPVOID *) PURE;
 8988    STDMETHOD_(ULONG,AddRef)        (THIS) PURE;
 8989    STDMETHOD_(ULONG,Release)       (THIS) PURE;
 8990
 8991    STDMETHOD(GetTime)              (THIS_ REFERENCE_TIME *pTime) PURE;
 8992    STDMETHOD(AdviseTime)           (THIS_ REFERENCE_TIME rtBaseTime, REFERENCE_TIME rtStreamTime,
 8993                                           HANDLE hEvent, LPDWORD pdwAdviseCookie) PURE;
 8994    STDMETHOD(AdvisePeriodic)       (THIS_ REFERENCE_TIME rtStartTime, REFERENCE_TIME rtPeriodTime,
 8995                                           HANDLE hSemaphore, LPDWORD pdwAdviseCookie) PURE;
 8996    STDMETHOD(Unadvise)             (THIS_ DWORD dwAdviseCookie) PURE;
 8997};
 8998
 8999#endif
 9000
 9001#ifndef IReferenceClock_QueryInterface
 9002
 9003#define IReferenceClock_QueryInterface(p,a,b)      IUnknown_QueryInterface(p,a,b)
 9004#define IReferenceClock_AddRef(p)                  IUnknown_AddRef(p)
 9005#define IReferenceClock_Release(p)                 IUnknown_Release(p)
 9006
 9007#if !defined(__cplusplus) || defined(CINTERFACE)
 9008#define IReferenceClock_GetTime(p,a)               (p)->lpVtbl->GetTime(p,a)
 9009#define IReferenceClock_AdviseTime(p,a,b,c,d)      (p)->lpVtbl->AdviseTime(p,a,b,c,d)
 9010#define IReferenceClock_AdvisePeriodic(p,a,b,c,d)  (p)->lpVtbl->AdvisePeriodic(p,a,b,c,d)
 9011#define IReferenceClock_Unadvise(p,a)              (p)->lpVtbl->Unadvise(p,a)
 9012#else
 9013#define IReferenceClock_GetTime(p,a)               (p)->GetTime(a)
 9014#define IReferenceClock_AdviseTime(p,a,b,c,d)      (p)->AdviseTime(a,b,c,d)
 9015#define IReferenceClock_AdvisePeriodic(p,a,b,c,d)  (p)->AdvisePeriodic(a,b,c,d)
 9016#define IReferenceClock_Unadvise(p,a)              (p)->Unadvise(a)
 9017#endif
 9018
 9019#endif
 9020
 9021DEFINE_GUID(IID_IDirectSound, 0x279AFA83, 0x4981, 0x11CE, 0xA5, 0x21, 0x00, 0x20, 0xAF, 0x0B, 0xE5, 0x60);
 9022
 9023#undef INTERFACE
 9024#define INTERFACE IDirectSound
 9025
 9026DECLARE_INTERFACE_(IDirectSound, IUnknown)
 9027{
 9028
 9029    STDMETHOD(QueryInterface)       (THIS_ REFIID, LPVOID *) PURE;
 9030    STDMETHOD_(ULONG,AddRef)        (THIS) PURE;
 9031    STDMETHOD_(ULONG,Release)       (THIS) PURE;
 9032
 9033    STDMETHOD(CreateSoundBuffer)    (THIS_ LPCDSBUFFERDESC pcDSBufferDesc, LPDIRECTSOUNDBUFFER *ppDSBuffer, LPUNKNOWN pUnkOuter) PURE;
 9034    STDMETHOD(GetCaps)              (THIS_ LPDSCAPS pDSCaps) PURE;
 9035    STDMETHOD(DuplicateSoundBuffer) (THIS_ LPDIRECTSOUNDBUFFER pDSBufferOriginal, LPDIRECTSOUNDBUFFER *ppDSBufferDuplicate) PURE;
 9036    STDMETHOD(SetCooperativeLevel)  (THIS_ HWND hwnd, DWORD dwLevel) PURE;
 9037    STDMETHOD(Compact)              (THIS) PURE;
 9038    STDMETHOD(GetSpeakerConfig)     (THIS_ LPDWORD pdwSpeakerConfig) PURE;
 9039    STDMETHOD(SetSpeakerConfig)     (THIS_ DWORD dwSpeakerConfig) PURE;
 9040    STDMETHOD(Initialize)           (THIS_ LPCGUID pcGuidDevice) PURE;
 9041};
 9042
 9043#define IDirectSound_QueryInterface(p,a,b)       IUnknown_QueryInterface(p,a,b)
 9044#define IDirectSound_AddRef(p)                   IUnknown_AddRef(p)
 9045#define IDirectSound_Release(p)                  IUnknown_Release(p)
 9046
 9047#if !defined(__cplusplus) || defined(CINTERFACE)
 9048#define IDirectSound_CreateSoundBuffer(p,a,b,c)  (p)->lpVtbl->CreateSoundBuffer(p,a,b,c)
 9049#define IDirectSound_GetCaps(p,a)                (p)->lpVtbl->GetCaps(p,a)
 9050#define IDirectSound_DuplicateSoundBuffer(p,a,b) (p)->lpVtbl->DuplicateSoundBuffer(p,a,b)
 9051#define IDirectSound_SetCooperativeLevel(p,a,b)  (p)->lpVtbl->SetCooperativeLevel(p,a,b)
 9052#define IDirectSound_Compact(p)                  (p)->lpVtbl->Compact(p)
 9053#define IDirectSound_GetSpeakerConfig(p,a)       (p)->lpVtbl->GetSpeakerConfig(p,a)
 9054#define IDirectSound_SetSpeakerConfig(p,b)       (p)->lpVtbl->SetSpeakerConfig(p,b)
 9055#define IDirectSound_Initialize(p,a)             (p)->lpVtbl->Initialize(p,a)
 9056#else
 9057#define IDirectSound_CreateSoundBuffer(p,a,b,c)  (p)->CreateSoundBuffer(a,b,c)
 9058#define IDirectSound_GetCaps(p,a)                (p)->GetCaps(a)
 9059#define IDirectSound_DuplicateSoundBuffer(p,a,b) (p)->DuplicateSoundBuffer(a,b)
 9060#define IDirectSound_SetCooperativeLevel(p,a,b)  (p)->SetCooperativeLevel(a,b)
 9061#define IDirectSound_Compact(p)                  (p)->Compact()
 9062#define IDirectSound_GetSpeakerConfig(p,a)       (p)->GetSpeakerConfig(a)
 9063#define IDirectSound_SetSpeakerConfig(p,b)       (p)->SetSpeakerConfig(b)
 9064#define IDirectSound_Initialize(p,a)             (p)->Initialize(a)
 9065#endif
 9066
 9067#if DIRECTSOUND_VERSION >= 0x0800
 9068
 9069DEFINE_GUID(IID_IDirectSound8, 0xC50A7E93, 0xF395, 0x4834, 0x9E, 0xF6, 0x7F, 0xA9, 0x9D, 0xE5, 0x09, 0x66);
 9070
 9071#undef INTERFACE
 9072#define INTERFACE IDirectSound8
 9073
 9074DECLARE_INTERFACE_(IDirectSound8, IDirectSound)
 9075{
 9076
 9077    STDMETHOD(QueryInterface)       (THIS_ REFIID, LPVOID *) PURE;
 9078    STDMETHOD_(ULONG,AddRef)        (THIS) PURE;
 9079    STDMETHOD_(ULONG,Release)       (THIS) PURE;
 9080
 9081    STDMETHOD(CreateSoundBuffer)    (THIS_ LPCDSBUFFERDESC pcDSBufferDesc, LPDIRECTSOUNDBUFFER *ppDSBuffer, LPUNKNOWN pUnkOuter) PURE;
 9082    STDMETHOD(GetCaps)              (THIS_ LPDSCAPS pDSCaps) PURE;
 9083    STDMETHOD(DuplicateSoundBuffer) (THIS_ LPDIRECTSOUNDBUFFER pDSBufferOriginal, LPDIRECTSOUNDBUFFER *ppDSBufferDuplicate) PURE;
 9084    STDMETHOD(SetCooperativeLevel)  (THIS_ HWND hwnd, DWORD dwLevel) PURE;
 9085    STDMETHOD(Compact)              (THIS) PURE;
 9086    STDMETHOD(GetSpeakerConfig)     (THIS_ LPDWORD pdwSpeakerConfig) PURE;
 9087    STDMETHOD(SetSpeakerConfig)     (THIS_ DWORD dwSpeakerConfig) PURE;
 9088    STDMETHOD(Initialize)           (THIS_ LPCGUID pcGuidDevice) PURE;
 9089
 9090    STDMETHOD(VerifyCertification)  (THIS_ LPDWORD pdwCertified) PURE;
 9091};
 9092
 9093#define IDirectSound8_QueryInterface(p,a,b)       IDirectSound_QueryInterface(p,a,b)
 9094#define IDirectSound8_AddRef(p)                   IDirectSound_AddRef(p)
 9095#define IDirectSound8_Release(p)                  IDirectSound_Release(p)
 9096#define IDirectSound8_CreateSoundBuffer(p,a,b,c)  IDirectSound_CreateSoundBuffer(p,a,b,c)
 9097#define IDirectSound8_GetCaps(p,a)                IDirectSound_GetCaps(p,a)
 9098#define IDirectSound8_DuplicateSoundBuffer(p,a,b) IDirectSound_DuplicateSoundBuffer(p,a,b)
 9099#define IDirectSound8_SetCooperativeLevel(p,a,b)  IDirectSound_SetCooperativeLevel(p,a,b)
 9100#define IDirectSound8_Compact(p)                  IDirectSound_Compact(p)
 9101#define IDirectSound8_GetSpeakerConfig(p,a)       IDirectSound_GetSpeakerConfig(p,a)
 9102#define IDirectSound8_SetSpeakerConfig(p,a)       IDirectSound_SetSpeakerConfig(p,a)
 9103#define IDirectSound8_Initialize(p,a)             IDirectSound_Initialize(p,a)
 9104
 9105#if !defined(__cplusplus) || defined(CINTERFACE)
 9106#define IDirectSound8_VerifyCertification(p,a)           (p)->lpVtbl->VerifyCertification(p,a)
 9107#else
 9108#define IDirectSound8_VerifyCertification(p,a)           (p)->VerifyCertification(a)
 9109#endif
 9110
 9111#endif
 9112
 9113DEFINE_GUID(IID_IDirectSoundBuffer, 0x279AFA85, 0x4981, 0x11CE, 0xA5, 0x21, 0x00, 0x20, 0xAF, 0x0B, 0xE5, 0x60);
 9114
 9115#undef INTERFACE
 9116#define INTERFACE IDirectSoundBuffer
 9117
 9118DECLARE_INTERFACE_(IDirectSoundBuffer, IUnknown)
 9119{
 9120
 9121    STDMETHOD(QueryInterface)       (THIS_ REFIID, LPVOID *) PURE;
 9122    STDMETHOD_(ULONG,AddRef)        (THIS) PURE;
 9123    STDMETHOD_(ULONG,Release)       (THIS) PURE;
 9124
 9125    STDMETHOD(GetCaps)              (THIS_ LPDSBCAPS pDSBufferCaps) PURE;
 9126    STDMETHOD(GetCurrentPosition)   (THIS_ LPDWORD pdwCurrentPlayCursor, LPDWORD pdwCurrentWriteCursor) PURE;
 9127    STDMETHOD(GetFormat)            (THIS_ LPWAVEFORMATEX pwfxFormat, DWORD dwSizeAllocated, LPDWORD pdwSizeWritten) PURE;
 9128    STDMETHOD(GetVolume)            (THIS_ LPLONG plVolume) PURE;
 9129    STDMETHOD(GetPan)               (THIS_ LPLONG plPan) PURE;
 9130    STDMETHOD(GetFrequency)         (THIS_ LPDWORD pdwFrequency) PURE;
 9131    STDMETHOD(GetStatus)            (THIS_ LPDWORD pdwStatus) PURE;
 9132    STDMETHOD(Initialize)           (THIS_ LPDIRECTSOUND pDirectSound, LPCDSBUFFERDESC pcDSBufferDesc) PURE;
 9133    STDMETHOD(Lock)                 (THIS_ DWORD dwOffset, DWORD dwBytes, LPVOID *ppvAudioPtr1, LPDWORD pdwAudioBytes1,
 9134                                           LPVOID *ppvAudioPtr2, LPDWORD pdwAudioBytes2, DWORD dwFlags) PURE;
 9135    STDMETHOD(Play)                 (THIS_ DWORD dwReserved1, DWORD dwPriority, DWORD dwFlags) PURE;
 9136    STDMETHOD(SetCurrentPosition)   (THIS_ DWORD dwNewPosition) PURE;
 9137    STDMETHOD(SetFormat)            (THIS_ LPCWAVEFORMATEX pcfxFormat) PURE;
 9138    STDMETHOD(SetVolume)            (THIS_ LONG lVolume) PURE;
 9139    STDMETHOD(SetPan)               (THIS_ LONG lPan) PURE;
 9140    STDMETHOD(SetFrequency)         (THIS_ DWORD dwFrequency) PURE;
 9141    STDMETHOD(Stop)                 (THIS) PURE;
 9142    STDMETHOD(Unlock)               (THIS_ LPVOID pvAudioPtr1, DWORD dwAudioBytes1, LPVOID pvAudioPtr2, DWORD dwAudioBytes2) PURE;
 9143    STDMETHOD(Restore)              (THIS) PURE;
 9144};
 9145
 9146#define IDirectSoundBuffer_QueryInterface(p,a,b)        IUnknown_QueryInterface(p,a,b)
 9147#define IDirectSoundBuffer_AddRef(p)                    IUnknown_AddRef(p)
 9148#define IDirectSoundBuffer_Release(p)                   IUnknown_Release(p)
 9149
 9150#if !defined(__cplusplus) || defined(CINTERFACE)
 9151#define IDirectSoundBuffer_GetCaps(p,a)                 (p)->lpVtbl->GetCaps(p,a)
 9152#define IDirectSoundBuffer_GetCurrentPosition(p,a,b)    (p)->lpVtbl->GetCurrentPosition(p,a,b)
 9153#define IDirectSoundBuffer_GetFormat(p,a,b,c)           (p)->lpVtbl->GetFormat(p,a,b,c)
 9154#define IDirectSoundBuffer_GetVolume(p,a)               (p)->lpVtbl->GetVolume(p,a)
 9155#define IDirectSoundBuffer_GetPan(p,a)                  (p)->lpVtbl->GetPan(p,a)
 9156#define IDirectSoundBuffer_GetFrequency(p,a)            (p)->lpVtbl->GetFrequency(p,a)
 9157#define IDirectSoundBuffer_GetStatus(p,a)               (p)->lpVtbl->GetStatus(p,a)
 9158#define IDirectSoundBuffer_Initialize(p,a,b)            (p)->lpVtbl->Initialize(p,a,b)
 9159#define IDirectSoundBuffer_Lock(p,a,b,c,d,e,f,g)        (p)->lpVtbl->Lock(p,a,b,c,d,e,f,g)
 9160#define IDirectSoundBuffer_Play(p,a,b,c)                (p)->lpVtbl->Play(p,a,b,c)
 9161#define IDirectSoundBuffer_SetCurrentPosition(p,a)      (p)->lpVtbl->SetCurrentPosition(p,a)
 9162#define IDirectSoundBuffer_SetFormat(p,a)               (p)->lpVtbl->SetFormat(p,a)
 9163#define IDirectSoundBuffer_SetVolume(p,a)               (p)->lpVtbl->SetVolume(p,a)
 9164#define IDirectSoundBuffer_SetPan(p,a)                  (p)->lpVtbl->SetPan(p,a)
 9165#define IDirectSoundBuffer_SetFrequency(p,a)            (p)->lpVtbl->SetFrequency(p,a)
 9166#define IDirectSoundBuffer_Stop(p)                      (p)->lpVtbl->Stop(p)
 9167#define IDirectSoundBuffer_Unlock(p,a,b,c,d)            (p)->lpVtbl->Unlock(p,a,b,c,d)
 9168#define IDirectSoundBuffer_Restore(p)                   (p)->lpVtbl->Restore(p)
 9169#else
 9170#define IDirectSoundBuffer_GetCaps(p,a)                 (p)->GetCaps(a)
 9171#define IDirectSoundBuffer_GetCurrentPosition(p,a,b)    (p)->GetCurrentPosition(a,b)
 9172#define IDirectSoundBuffer_GetFormat(p,a,b,c)           (p)->GetFormat(a,b,c)
 9173#define IDirectSoundBuffer_GetVolume(p,a)               (p)->GetVolume(a)
 9174#define IDirectSoundBuffer_GetPan(p,a)                  (p)->GetPan(a)
 9175#define IDirectSoundBuffer_GetFrequency(p,a)            (p)->GetFrequency(a)
 9176#define IDirectSoundBuffer_GetStatus(p,a)               (p)->GetStatus(a)
 9177#define IDirectSoundBuffer_Initialize(p,a,b)            (p)->Initialize(a,b)
 9178#define IDirectSoundBuffer_Lock(p,a,b,c,d,e,f,g)        (p)->Lock(a,b,c,d,e,f,g)
 9179#define IDirectSoundBuffer_Play(p,a,b,c)                (p)->Play(a,b,c)
 9180#define IDirectSoundBuffer_SetCurrentPosition(p,a)      (p)->SetCurrentPosition(a)
 9181#define IDirectSoundBuffer_SetFormat(p,a)               (p)->SetFormat(a)
 9182#define IDirectSoundBuffer_SetVolume(p,a)               (p)->SetVolume(a)
 9183#define IDirectSoundBuffer_SetPan(p,a)                  (p)->SetPan(a)
 9184#define IDirectSoundBuffer_SetFrequency(p,a)            (p)->SetFrequency(a)
 9185#define IDirectSoundBuffer_Stop(p)                      (p)->Stop()
 9186#define IDirectSoundBuffer_Unlock(p,a,b,c,d)            (p)->Unlock(a,b,c,d)
 9187#define IDirectSoundBuffer_Restore(p)                   (p)->Restore()
 9188#endif
 9189
 9190#if DIRECTSOUND_VERSION >= 0x0800
 9191
 9192DEFINE_GUID(IID_IDirectSoundBuffer8, 0x6825a449, 0x7524, 0x4d82, 0x92, 0x0f, 0x50, 0xe3, 0x6a, 0xb3, 0xab, 0x1e);
 9193
 9194#undef INTERFACE
 9195#define INTERFACE IDirectSoundBuffer8
 9196
 9197DECLARE_INTERFACE_(IDirectSoundBuffer8, IDirectSoundBuffer)
 9198{
 9199
 9200    STDMETHOD(QueryInterface)       (THIS_ REFIID, LPVOID *) PURE;
 9201    STDMETHOD_(ULONG,AddRef)        (THIS) PURE;
 9202    STDMETHOD_(ULONG,Release)       (THIS) PURE;
 9203
 9204    STDMETHOD(GetCaps)              (THIS_ LPDSBCAPS pDSBufferCaps) PURE;
 9205    STDMETHOD(GetCurrentPosition)   (THIS_ LPDWORD pdwCurrentPlayCursor, LPDWORD pdwCurrentWriteCursor) PURE;
 9206    STDMETHOD(GetFormat)            (THIS_ LPWAVEFORMATEX pwfxFormat, DWORD dwSizeAllocated, LPDWORD pdwSizeWritten) PURE;
 9207    STDMETHOD(GetVolume)            (THIS_ LPLONG plVolume) PURE;
 9208    STDMETHOD(GetPan)               (THIS_ LPLONG plPan) PURE;
 9209    STDMETHOD(GetFrequency)         (THIS_ LPDWORD pdwFrequency) PURE;
 9210    STDMETHOD(GetStatus)            (THIS_ LPDWORD pdwStatus) PURE;
 9211    STDMETHOD(Initialize)           (THIS_ LPDIRECTSOUND pDirectSound, LPCDSBUFFERDESC pcDSBufferDesc) PURE;
 9212    STDMETHOD(Lock)                 (THIS_ DWORD dwOffset, DWORD dwBytes, LPVOID *ppvAudioPtr1, LPDWORD pdwAudioBytes1,
 9213                                           LPVOID *ppvAudioPtr2, LPDWORD pdwAudioBytes2, DWORD dwFlags) PURE;
 9214    STDMETHOD(Play)                 (THIS_ DWORD dwReserved1, DWORD dwPriority, DWORD dwFlags) PURE;
 9215    STDMETHOD(SetCurrentPosition)   (THIS_ DWORD dwNewPosition) PURE;
 9216    STDMETHOD(SetFormat)            (THIS_ LPCWAVEFORMATEX pcfxFormat) PURE;
 9217    STDMETHOD(SetVolume)            (THIS_ LONG lVolume) PURE;
 9218    STDMETHOD(SetPan)               (THIS_ LONG lPan) PURE;
 9219    STDMETHOD(SetFrequency)         (THIS_ DWORD dwFrequency) PURE;
 9220    STDMETHOD(Stop)                 (THIS) PURE;
 9221    STDMETHOD(Unlock)               (THIS_ LPVOID pvAudioPtr1, DWORD dwAudioBytes1, LPVOID pvAudioPtr2, DWORD dwAudioBytes2) PURE;
 9222    STDMETHOD(Restore)              (THIS) PURE;
 9223
 9224    STDMETHOD(SetFX)                (THIS_ DWORD dwEffectsCount, LPDSEFFECTDESC pDSFXDesc, LPDWORD pdwResultCodes) PURE;
 9225    STDMETHOD(AcquireResources)     (THIS_ DWORD dwFlags, DWORD dwEffectsCount, LPDWORD pdwResultCodes) PURE;
 9226    STDMETHOD(GetObjectInPath)      (THIS_ REFGUID rguidObject, DWORD dwIndex, REFGUID rguidInterface, LPVOID *ppObject) PURE;
 9227};
 9228
 9229DEFINE_GUID(GUID_All_Objects, 0xaa114de5, 0xc262, 0x4169, 0xa1, 0xc8, 0x23, 0xd6, 0x98, 0xcc, 0x73, 0xb5);
 9230
 9231#define IDirectSoundBuffer8_QueryInterface(p,a,b)           IUnknown_QueryInterface(p,a,b)
 9232#define IDirectSoundBuffer8_AddRef(p)                       IUnknown_AddRef(p)
 9233#define IDirectSoundBuffer8_Release(p)                      IUnknown_Release(p)
 9234
 9235#define IDirectSoundBuffer8_GetCaps(p,a)                    IDirectSoundBuffer_GetCaps(p,a)
 9236#define IDirectSoundBuffer8_GetCurrentPosition(p,a,b)       IDirectSoundBuffer_GetCurrentPosition(p,a,b)
 9237#define IDirectSoundBuffer8_GetFormat(p,a,b,c)              IDirectSoundBuffer_GetFormat(p,a,b,c)
 9238#define IDirectSoundBuffer8_GetVolume(p,a)                  IDirectSoundBuffer_GetVolume(p,a)
 9239#define IDirectSoundBuffer8_GetPan(p,a)                     IDirectSoundBuffer_GetPan(p,a)
 9240#define IDirectSoundBuffer8_GetFrequency(p,a)               IDirectSoundBuffer_GetFrequency(p,a)
 9241#define IDirectSoundBuffer8_GetStatus(p,a)                  IDirectSoundBuffer_GetStatus(p,a)
 9242#define IDirectSoundBuffer8_Initialize(p,a,b)               IDirectSoundBuffer_Initialize(p,a,b)
 9243#define IDirectSoundBuffer8_Lock(p,a,b,c,d,e,f,g)           IDirectSoundBuffer_Lock(p,a,b,c,d,e,f,g)
 9244#define IDirectSoundBuffer8_Play(p,a,b,c)                   IDirectSoundBuffer_Play(p,a,b,c)
 9245#define IDirectSoundBuffer8_SetCurrentPosition(p,a)         IDirectSoundBuffer_SetCurrentPosition(p,a)
 9246#define IDirectSoundBuffer8_SetFormat(p,a)                  IDirectSoundBuffer_SetFormat(p,a)
 9247#define IDirectSoundBuffer8_SetVolume(p,a)                  IDirectSoundBuffer_SetVolume(p,a)
 9248#define IDirectSoundBuffer8_SetPan(p,a)                     IDirectSoundBuffer_SetPan(p,a)
 9249#define IDirectSoundBuffer8_SetFrequency(p,a)               IDirectSoundBuffer_SetFrequency(p,a)
 9250#define IDirectSoundBuffer8_Stop(p)                         IDirectSoundBuffer_Stop(p)
 9251#define IDirectSoundBuffer8_Unlock(p,a,b,c,d)               IDirectSoundBuffer_Unlock(p,a,b,c,d)
 9252#define IDirectSoundBuffer8_Restore(p)                      IDirectSoundBuffer_Restore(p)
 9253
 9254#if !defined(__cplusplus) || defined(CINTERFACE)
 9255#define IDirectSoundBuffer8_SetFX(p,a,b,c)                  (p)->lpVtbl->SetFX(p,a,b,c)
 9256#define IDirectSoundBuffer8_AcquireResources(p,a,b,c)       (p)->lpVtbl->AcquireResources(p,a,b,c)
 9257#define IDirectSoundBuffer8_GetObjectInPath(p,a,b,c,d)      (p)->lpVtbl->GetObjectInPath(p,a,b,c,d)
 9258#else
 9259#define IDirectSoundBuffer8_SetFX(p,a,b,c)                  (p)->SetFX(a,b,c)
 9260#define IDirectSoundBuffer8_AcquireResources(p,a,b,c)       (p)->AcquireResources(a,b,c)
 9261#define IDirectSoundBuffer8_GetObjectInPath(p,a,b,c,d)      (p)->GetObjectInPath(a,b,c,d)
 9262#endif
 9263
 9264#endif
 9265
 9266DEFINE_GUID(IID_IDirectSound3DListener, 0x279AFA84, 0x4981, 0x11CE, 0xA5, 0x21, 0x00, 0x20, 0xAF, 0x0B, 0xE5, 0x60);
 9267
 9268#undef INTERFACE
 9269#define INTERFACE IDirectSound3DListener
 9270
 9271DECLARE_INTERFACE_(IDirectSound3DListener, IUnknown)
 9272{
 9273
 9274    STDMETHOD(QueryInterface)           (THIS_ REFIID, LPVOID *) PURE;
 9275    STDMETHOD_(ULONG,AddRef)            (THIS) PURE;
 9276    STDMETHOD_(ULONG,Release)           (THIS) PURE;
 9277
 9278    STDMETHOD(GetAllParameters)         (THIS_ LPDS3DLISTENER pListener) PURE;
 9279    STDMETHOD(GetDistanceFactor)        (THIS_ D3DVALUE* pflDistanceFactor) PURE;
 9280    STDMETHOD(GetDopplerFactor)         (THIS_ D3DVALUE* pflDopplerFactor) PURE;
 9281    STDMETHOD(GetOrientation)           (THIS_ D3DVECTOR* pvOrientFront, D3DVECTOR* pvOrientTop) PURE;
 9282    STDMETHOD(GetPosition)              (THIS_ D3DVECTOR* pvPosition) PURE;
 9283    STDMETHOD(GetRolloffFactor)         (THIS_ D3DVALUE* pflRolloffFactor) PURE;
 9284    STDMETHOD(GetVelocity)              (THIS_ D3DVECTOR* pvVelocity) PURE;
 9285    STDMETHOD(SetAllParameters)         (THIS_ LPCDS3DLISTENER pcListener, DWORD dwApply) PURE;
 9286    STDMETHOD(SetDistanceFactor)        (THIS_ D3DVALUE flDistanceFactor, DWORD dwApply) PURE;
 9287    STDMETHOD(SetDopplerFactor)         (THIS_ D3DVALUE flDopplerFactor, DWORD dwApply) PURE;
 9288    STDMETHOD(SetOrientation)           (THIS_ D3DVALUE xFront, D3DVALUE yFront, D3DVALUE zFront,
 9289                                               D3DVALUE xTop, D3DVALUE yTop, D3DVALUE zTop, DWORD dwApply) PURE;
 9290    STDMETHOD(SetPosition)              (THIS_ D3DVALUE x, D3DVALUE y, D3DVALUE z, DWORD dwApply) PURE;
 9291    STDMETHOD(SetRolloffFactor)         (THIS_ D3DVALUE flRolloffFactor, DWORD dwApply) PURE;
 9292    STDMETHOD(SetVelocity)              (THIS_ D3DVALUE x, D3DVALUE y, D3DVALUE z, DWORD dwApply) PURE;
 9293    STDMETHOD(CommitDeferredSettings)   (THIS) PURE;
 9294};
 9295
 9296#define IDirectSound3DListener_QueryInterface(p,a,b)            IUnknown_QueryInterface(p,a,b)
 9297#define IDirectSound3DListener_AddRef(p)                        IUnknown_AddRef(p)
 9298#define IDirectSound3DListener_Release(p)                       IUnknown_Release(p)
 9299
 9300#if !defined(__cplusplus) || defined(CINTERFACE)
 9301#define IDirectSound3DListener_GetAllParameters(p,a)            (p)->lpVtbl->GetAllParameters(p,a)
 9302#define IDirectSound3DListener_GetDistanceFactor(p,a)           (p)->lpVtbl->GetDistanceFactor(p,a)
 9303#define IDirectSound3DListener_GetDopplerFactor(p,a)            (p)->lpVtbl->GetDopplerFactor(p,a)
 9304#define IDirectSound3DListener_GetOrientation(p,a,b)            (p)->lpVtbl->GetOrientation(p,a,b)
 9305#define IDirectSound3DListener_GetPosition(p,a)                 (p)->lpVtbl->GetPosition(p,a)
 9306#define IDirectSound3DListener_GetRolloffFactor(p,a)            (p)->lpVtbl->GetRolloffFactor(p,a)
 9307#define IDirectSound3DListener_GetVelocity(p,a)                 (p)->lpVtbl->GetVelocity(p,a)
 9308#define IDirectSound3DListener_SetAllParameters(p,a,b)          (p)->lpVtbl->SetAllParameters(p,a,b)
 9309#define IDirectSound3DListener_SetDistanceFactor(p,a,b)         (p)->lpVtbl->SetDistanceFactor(p,a,b)
 9310#define IDirectSound3DListener_SetDopplerFactor(p,a,b)          (p)->lpVtbl->SetDopplerFactor(p,a,b)
 9311#define IDirectSound3DListener_SetOrientation(p,a,b,c,d,e,f,g)  (p)->lpVtbl->SetOrientation(p,a,b,c,d,e,f,g)
 9312#define IDirectSound3DListener_SetPosition(p,a,b,c,d)           (p)->lpVtbl->SetPosition(p,a,b,c,d)
 9313#define IDirectSound3DListener_SetRolloffFactor(p,a,b)          (p)->lpVtbl->SetRolloffFactor(p,a,b)
 9314#define IDirectSound3DListener_SetVelocity(p,a,b,c,d)           (p)->lpVtbl->SetVelocity(p,a,b,c,d)
 9315#define IDirectSound3DListener_CommitDeferredSettings(p)        (p)->lpVtbl->CommitDeferredSettings(p)
 9316#else
 9317#define IDirectSound3DListener_GetAllParameters(p,a)            (p)->GetAllParameters(a)
 9318#define IDirectSound3DListener_GetDistanceFactor(p,a)           (p)->GetDistanceFactor(a)
 9319#define IDirectSound3DListener_GetDopplerFactor(p,a)            (p)->GetDopplerFactor(a)
 9320#define IDirectSound3DListener_GetOrientation(p,a,b)            (p)->GetOrientation(a,b)
 9321#define IDirectSound3DListener_GetPosition(p,a)                 (p)->GetPosition(a)
 9322#define IDirectSound3DListener_GetRolloffFactor(p,a)            (p)->GetRolloffFactor(a)
 9323#define IDirectSound3DListener_GetVelocity(p,a)                 (p)->GetVelocity(a)
 9324#define IDirectSound3DListener_SetAllParameters(p,a,b)          (p)->SetAllParameters(a,b)
 9325#define IDirectSound3DListener_SetDistanceFactor(p,a,b)         (p)->SetDistanceFactor(a,b)
 9326#define IDirectSound3DListener_SetDopplerFactor(p,a,b)          (p)->SetDopplerFactor(a,b)
 9327#define IDirectSound3DListener_SetOrientation(p,a,b,c,d,e,f,g)  (p)->SetOrientation(a,b,c,d,e,f,g)
 9328#define IDirectSound3DListener_SetPosition(p,a,b,c,d)           (p)->SetPosition(a,b,c,d)
 9329#define IDirectSound3DListener_SetRolloffFactor(p,a,b)          (p)->SetRolloffFactor(a,b)
 9330#define IDirectSound3DListener_SetVelocity(p,a,b,c,d)           (p)->SetVelocity(a,b,c,d)
 9331#define IDirectSound3DListener_CommitDeferredSettings(p)        (p)->CommitDeferredSettings()
 9332#endif
 9333
 9334DEFINE_GUID(IID_IDirectSound3DBuffer, 0x279AFA86, 0x4981, 0x11CE, 0xA5, 0x21, 0x00, 0x20, 0xAF, 0x0B, 0xE5, 0x60);
 9335
 9336#undef INTERFACE
 9337#define INTERFACE IDirectSound3DBuffer
 9338
 9339DECLARE_INTERFACE_(IDirectSound3DBuffer, IUnknown)
 9340{
 9341
 9342    STDMETHOD(QueryInterface)       (THIS_ REFIID, LPVOID *) PURE;
 9343    STDMETHOD_(ULONG,AddRef)        (THIS) PURE;
 9344    STDMETHOD_(ULONG,Release)       (THIS) PURE;
 9345
 9346    STDMETHOD(GetAllParameters)     (THIS_ LPDS3DBUFFER pDs3dBuffer) PURE;
 9347    STDMETHOD(GetConeAngles)        (THIS_ LPDWORD pdwInsideConeAngle, LPDWORD pdwOutsideConeAngle) PURE;
 9348    STDMETHOD(GetConeOrientation)   (THIS_ D3DVECTOR* pvOrientation) PURE;
 9349    STDMETHOD(GetConeOutsideVolume) (THIS_ LPLONG plConeOutsideVolume) PURE;
 9350    STDMETHOD(GetMaxDistance)       (THIS_ D3DVALUE* pflMaxDistance) PURE;
 9351    STDMETHOD(GetMinDistance)       (THIS_ D3DVALUE* pflMinDistance) PURE;
 9352    STDMETHOD(GetMode)              (THIS_ LPDWORD pdwMode) PURE;
 9353    STDMETHOD(GetPosition)          (THIS_ D3DVECTOR* pvPosition) PURE;
 9354    STDMETHOD(GetVelocity)          (THIS_ D3DVECTOR* pvVelocity) PURE;
 9355    STDMETHOD(SetAllParameters)     (THIS_ LPCDS3DBUFFER pcDs3dBuffer, DWORD dwApply) PURE;
 9356    STDMETHOD(SetConeAngles)        (THIS_ DWORD dwInsideConeAngle, DWORD dwOutsideConeAngle, DWORD dwApply) PURE;
 9357    STDMETHOD(SetConeOrientation)   (THIS_ D3DVALUE x, D3DVALUE y, D3DVALUE z, DWORD dwApply) PURE;
 9358    STDMETHOD(SetConeOutsideVolume) (THIS_ LONG lConeOutsideVolume, DWORD dwApply) PURE;
 9359    STDMETHOD(SetMaxDistance)       (THIS_ D3DVALUE flMaxDistance, DWORD dwApply) PURE;
 9360    STDMETHOD(SetMinDistance)       (THIS_ D3DVALUE flMinDistance, DWORD dwApply) PURE;
 9361    STDMETHOD(SetMode)              (THIS_ DWORD dwMode, DWORD dwApply) PURE;
 9362    STDMETHOD(SetPosition)          (THIS_ D3DVALUE x, D3DVALUE y, D3DVALUE z, DWORD dwApply) PURE;
 9363    STDMETHOD(SetVelocity)          (THIS_ D3DVALUE x, D3DVALUE y, D3DVALUE z, DWORD dwApply) PURE;
 9364};
 9365
 9366#define IDirectSound3DBuffer_QueryInterface(p,a,b)          IUnknown_QueryInterface(p,a,b)
 9367#define IDirectSound3DBuffer_AddRef(p)                      IUnknown_AddRef(p)
 9368#define IDirectSound3DBuffer_Release(p)                     IUnknown_Release(p)
 9369
 9370#if !defined(__cplusplus) || defined(CINTERFACE)
 9371#define IDirectSound3DBuffer_GetAllParameters(p,a)          (p)->lpVtbl->GetAllParameters(p,a)
 9372#define IDirectSound3DBuffer_GetConeAngles(p,a,b)           (p)->lpVtbl->GetConeAngles(p,a,b)
 9373#define IDirectSound3DBuffer_GetConeOrientation(p,a)        (p)->lpVtbl->GetConeOrientation(p,a)
 9374#define IDirectSound3DBuffer_GetConeOutsideVolume(p,a)      (p)->lpVtbl->GetConeOutsideVolume(p,a)
 9375#define IDirectSound3DBuffer_GetPosition(p,a)               (p)->lpVtbl->GetPosition(p,a)
 9376#define IDirectSound3DBuffer_GetMinDistance(p,a)            (p)->lpVtbl->GetMinDistance(p,a)
 9377#define IDirectSound3DBuffer_GetMaxDistance(p,a)            (p)->lpVtbl->GetMaxDistance(p,a)
 9378#define IDirectSound3DBuffer_GetMode(p,a)                   (p)->lpVtbl->GetMode(p,a)
 9379#define IDirectSound3DBuffer_GetVelocity(p,a)               (p)->lpVtbl->GetVelocity(p,a)
 9380#define IDirectSound3DBuffer_SetAllParameters(p,a,b)        (p)->lpVtbl->SetAllParameters(p,a,b)
 9381#define IDirectSound3DBuffer_SetConeAngles(p,a,b,c)         (p)->lpVtbl->SetConeAngles(p,a,b,c)
 9382#define IDirectSound3DBuffer_SetConeOrientation(p,a,b,c,d)  (p)->lpVtbl->SetConeOrientation(p,a,b,c,d)
 9383#define IDirectSound3DBuffer_SetConeOutsideVolume(p,a,b)    (p)->lpVtbl->SetConeOutsideVolume(p,a,b)
 9384#define IDirectSound3DBuffer_SetPosition(p,a,b,c,d)         (p)->lpVtbl->SetPosition(p,a,b,c,d)
 9385#define IDirectSound3DBuffer_SetMinDistance(p,a,b)          (p)->lpVtbl->SetMinDistance(p,a,b)
 9386#define IDirectSound3DBuffer_SetMaxDistance(p,a,b)          (p)->lpVtbl->SetMaxDistance(p,a,b)
 9387#define IDirectSound3DBuffer_SetMode(p,a,b)                 (p)->lpVtbl->SetMode(p,a,b)
 9388#define IDirectSound3DBuffer_SetVelocity(p,a,b,c,d)         (p)->lpVtbl->SetVelocity(p,a,b,c,d)
 9389#else
 9390#define IDirectSound3DBuffer_GetAllParameters(p,a)          (p)->GetAllParameters(a)
 9391#define IDirectSound3DBuffer_GetConeAngles(p,a,b)           (p)->GetConeAngles(a,b)
 9392#define IDirectSound3DBuffer_GetConeOrientation(p,a)        (p)->GetConeOrientation(a)
 9393#define IDirectSound3DBuffer_GetConeOutsideVolume(p,a)      (p)->GetConeOutsideVolume(a)
 9394#define IDirectSound3DBuffer_GetPosition(p,a)               (p)->GetPosition(a)
 9395#define IDirectSound3DBuffer_GetMinDistance(p,a)            (p)->GetMinDistance(a)
 9396#define IDirectSound3DBuffer_GetMaxDistance(p,a)            (p)->GetMaxDistance(a)
 9397#define IDirectSound3DBuffer_GetMode(p,a)                   (p)->GetMode(a)
 9398#define IDirectSound3DBuffer_GetVelocity(p,a)               (p)->GetVelocity(a)
 9399#define IDirectSound3DBuffer_SetAllParameters(p,a,b)        (p)->SetAllParameters(a,b)
 9400#define IDirectSound3DBuffer_SetConeAngles(p,a,b,c)         (p)->SetConeAngles(a,b,c)
 9401#define IDirectSound3DBuffer_SetConeOrientation(p,a,b,c,d)  (p)->SetConeOrientation(a,b,c,d)
 9402#define IDirectSound3DBuffer_SetConeOutsideVolume(p,a,b)    (p)->SetConeOutsideVolume(a,b)
 9403#define IDirectSound3DBuffer_SetPosition(p,a,b,c,d)         (p)->SetPosition(a,b,c,d)
 9404#define IDirectSound3DBuffer_SetMinDistance(p,a,b)          (p)->SetMinDistance(a,b)
 9405#define IDirectSound3DBuffer_SetMaxDistance(p,a,b)          (p)->SetMaxDistance(a,b)
 9406#define IDirectSound3DBuffer_SetMode(p,a,b)                 (p)->SetMode(a,b)
 9407#define IDirectSound3DBuffer_SetVelocity(p,a,b,c,d)         (p)->SetVelocity(a,b,c,d)
 9408#endif
 9409
 9410DEFINE_GUID(IID_IDirectSoundCapture, 0xb0210781, 0x89cd, 0x11d0, 0xaf, 0x8, 0x0, 0xa0, 0xc9, 0x25, 0xcd, 0x16);
 9411
 9412#undef INTERFACE
 9413#define INTERFACE IDirectSoundCapture
 9414
 9415DECLARE_INTERFACE_(IDirectSoundCapture, IUnknown)
 9416{
 9417
 9418    STDMETHOD(QueryInterface)       (THIS_ REFIID, LPVOID *) PURE;
 9419    STDMETHOD_(ULONG,AddRef)        (THIS) PURE;
 9420    STDMETHOD_(ULONG,Release)       (THIS) PURE;
 9421
 9422    STDMETHOD(CreateCaptureBuffer)  (THIS_ LPCDSCBUFFERDESC pcDSCBufferDesc, LPDIRECTSOUNDCAPTUREBUFFER *ppDSCBuffer, LPUNKNOWN pUnkOuter) PURE;
 9423    STDMETHOD(GetCaps)              (THIS_ LPDSCCAPS pDSCCaps) PURE;
 9424    STDMETHOD(Initialize)           (THIS_ LPCGUID pcGuidDevice) PURE;
 9425};
 9426
 9427#define IDirectSoundCapture_QueryInterface(p,a,b)           IUnknown_QueryInterface(p,a,b)
 9428#define IDirectSoundCapture_AddRef(p)                       IUnknown_AddRef(p)
 9429#define IDirectSoundCapture_Release(p)                      IUnknown_Release(p)
 9430
 9431#if !defined(__cplusplus) || defined(CINTERFACE)
 9432#define IDirectSoundCapture_CreateCaptureBuffer(p,a,b,c)    (p)->lpVtbl->CreateCaptureBuffer(p,a,b,c)
 9433#define IDirectSoundCapture_GetCaps(p,a)                    (p)->lpVtbl->GetCaps(p,a)
 9434#define IDirectSoundCapture_Initialize(p,a)                 (p)->lpVtbl->Initialize(p,a)
 9435#else
 9436#define IDirectSoundCapture_CreateCaptureBuffer(p,a,b,c)    (p)->CreateCaptureBuffer(a,b,c)
 9437#define IDirectSoundCapture_GetCaps(p,a)                    (p)->GetCaps(a)
 9438#define IDirectSoundCapture_Initialize(p,a)                 (p)->Initialize(a)
 9439#endif
 9440
 9441DEFINE_GUID(IID_IDirectSoundCaptureBuffer, 0xb0210782, 0x89cd, 0x11d0, 0xaf, 0x8, 0x0, 0xa0, 0xc9, 0x25, 0xcd, 0x16);
 9442
 9443#undef INTERFACE
 9444#define INTERFACE IDirectSoundCaptureBuffer
 9445
 9446DECLARE_INTERFACE_(IDirectSoundCaptureBuffer, IUnknown)
 9447{
 9448
 9449    STDMETHOD(QueryInterface)       (THIS_ REFIID, LPVOID *) PURE;
 9450    STDMETHOD_(ULONG,AddRef)        (THIS) PURE;
 9451    STDMETHOD_(ULONG,Release)       (THIS) PURE;
 9452
 9453    STDMETHOD(GetCaps)              (THIS_ LPDSCBCAPS pDSCBCaps) PURE;
 9454    STDMETHOD(GetCurrentPosition)   (THIS_ LPDWORD pdwCapturePosition, LPDWORD pdwReadPosition) PURE;
 9455    STDMETHOD(GetFormat)            (THIS_ LPWAVEFORMATEX pwfxFormat, DWORD dwSizeAllocated, LPDWORD pdwSizeWritten) PURE;
 9456    STDMETHOD(GetStatus)            (THIS_ LPDWORD pdwStatus) PURE;
 9457    STDMETHOD(Initialize)           (THIS_ LPDIRECTSOUNDCAPTURE pDirectSoundCapture, LPCDSCBUFFERDESC pcDSCBufferDesc) PURE;
 9458    STDMETHOD(Lock)                 (THIS_ DWORD dwOffset, DWORD dwBytes, LPVOID *ppvAudioPtr1, LPDWORD pdwAudioBytes1,
 9459                                           LPVOID *ppvAudioPtr2, LPDWORD pdwAudioBytes2, DWORD dwFlags) PURE;
 9460    STDMETHOD(Start)                (THIS_ DWORD dwFlags) PURE;
 9461    STDMETHOD(Stop)                 (THIS) PURE;
 9462    STDMETHOD(Unlock)               (THIS_ LPVOID pvAudioPtr1, DWORD dwAudioBytes1, LPVOID pvAudioPtr2, DWORD dwAudioBytes2) PURE;
 9463};
 9464
 9465#define IDirectSoundCaptureBuffer_QueryInterface(p,a,b)         IUnknown_QueryInterface(p,a,b)
 9466#define IDirectSoundCaptureBuffer_AddRef(p)                     IUnknown_AddRef(p)
 9467#define IDirectSoundCaptureBuffer_Release(p)                    IUnknown_Release(p)
 9468
 9469#if !defined(__cplusplus) || defined(CINTERFACE)
 9470#define IDirectSoundCaptureBuffer_GetCaps(p,a)                  (p)->lpVtbl->GetCaps(p,a)
 9471#define IDirectSoundCaptureBuffer_GetCurrentPosition(p,a,b)     (p)->lpVtbl->GetCurrentPosition(p,a,b)
 9472#define IDirectSoundCaptureBuffer_GetFormat(p,a,b,c)            (p)->lpVtbl->GetFormat(p,a,b,c)
 9473#define IDirectSoundCaptureBuffer_GetStatus(p,a)                (p)->lpVtbl->GetStatus(p,a)
 9474#define IDirectSoundCaptureBuffer_Initialize(p,a,b)             (p)->lpVtbl->Initialize(p,a,b)
 9475#define IDirectSoundCaptureBuffer_Lock(p,a,b,c,d,e,f,g)         (p)->lpVtbl->Lock(p,a,b,c,d,e,f,g)
 9476#define IDirectSoundCaptureBuffer_Start(p,a)                    (p)->lpVtbl->Start(p,a)
 9477#define IDirectSoundCaptureBuffer_Stop(p)                       (p)->lpVtbl->Stop(p)
 9478#define IDirectSoundCaptureBuffer_Unlock(p,a,b,c,d)             (p)->lpVtbl->Unlock(p,a,b,c,d)
 9479#else
 9480#define IDirectSoundCaptureBuffer_GetCaps(p,a)                  (p)->GetCaps(a)
 9481#define IDirectSoundCaptureBuffer_GetCurrentPosition(p,a,b)     (p)->GetCurrentPosition(a,b)
 9482#define IDirectSoundCaptureBuffer_GetFormat(p,a,b,c)            (p)->GetFormat(a,b,c)
 9483#define IDirectSoundCaptureBuffer_GetStatus(p,a)                (p)->GetStatus(a)
 9484#define IDirectSoundCaptureBuffer_Initialize(p,a,b)             (p)->Initialize(a,b)
 9485#define IDirectSoundCaptureBuffer_Lock(p,a,b,c,d,e,f,g)         (p)->Lock(a,b,c,d,e,f,g)
 9486#define IDirectSoundCaptureBuffer_Start(p,a)                    (p)->Start(a)
 9487#define IDirectSoundCaptureBuffer_Stop(p)                       (p)->Stop()
 9488#define IDirectSoundCaptureBuffer_Unlock(p,a,b,c,d)             (p)->Unlock(a,b,c,d)
 9489#endif
 9490
 9491#if DIRECTSOUND_VERSION >= 0x0800
 9492
 9493DEFINE_GUID(IID_IDirectSoundCaptureBuffer8, 0x990df4, 0xdbb, 0x4872, 0x83, 0x3e, 0x6d, 0x30, 0x3e, 0x80, 0xae, 0xb6);
 9494
 9495#undef INTERFACE
 9496#define INTERFACE IDirectSoundCaptureBuffer8
 9497
 9498DECLARE_INTERFACE_(IDirectSoundCaptureBuffer8, IDirectSoundCaptureBuffer)
 9499{
 9500
 9501    STDMETHOD(QueryInterface)       (THIS_ REFIID, LPVOID *) PURE;
 9502    STDMETHOD_(ULONG,AddRef)        (THIS) PURE;
 9503    STDMETHOD_(ULONG,Release)       (THIS) PURE;
 9504
 9505    STDMETHOD(GetCaps)              (THIS_ LPDSCBCAPS pDSCBCaps) PURE;
 9506    STDMETHOD(GetCurrentPosition)   (THIS_ LPDWORD pdwCapturePosition, LPDWORD pdwReadPosition) PURE;
 9507    STDMETHOD(GetFormat)            (THIS_ LPWAVEFORMATEX pwfxFormat, DWORD dwSizeAllocated, LPDWORD pdwSizeWritten) PURE;
 9508    STDMETHOD(GetStatus)            (THIS_ LPDWORD pdwStatus) PURE;
 9509    STDMETHOD(Initialize)           (THIS_ LPDIRECTSOUNDCAPTURE pDirectSoundCapture, LPCDSCBUFFERDESC pcDSCBufferDesc) PURE;
 9510    STDMETHOD(Lock)                 (THIS_ DWORD dwOffset, DWORD dwBytes, LPVOID *ppvAudioPtr1, LPDWORD pdwAudioBytes1,
 9511                                           LPVOID *ppvAudioPtr2, LPDWORD pdwAudioBytes2, DWORD dwFlags) PURE;
 9512    STDMETHOD(Start)                (THIS_ DWORD dwFlags) PURE;
 9513    STDMETHOD(Stop)                 (THIS) PURE;
 9514    STDMETHOD(Unlock)               (THIS_ LPVOID pvAudioPtr1, DWORD dwAudioBytes1, LPVOID pvAudioPtr2, DWORD dwAudioBytes2) PURE;
 9515
 9516    STDMETHOD(GetObjectInPath)      (THIS_ REFGUID rguidObject, DWORD dwIndex, REFGUID rguidInterface, LPVOID *ppObject) PURE;
 9517    STDMETHOD(GetFXStatus)          (DWORD dwFXCount, LPDWORD pdwFXStatus) PURE;
 9518};
 9519
 9520#define IDirectSoundCaptureBuffer8_QueryInterface(p,a,b)            IUnknown_QueryInterface(p,a,b)
 9521#define IDirectSoundCaptureBuffer8_AddRef(p)                        IUnknown_AddRef(p)
 9522#define IDirectSoundCaptureBuffer8_Release(p)                       IUnknown_Release(p)
 9523
 9524#define IDirectSoundCaptureBuffer8_GetCaps(p,a)                     IDirectSoundCaptureBuffer_GetCaps(p,a)
 9525#define IDirectSoundCaptureBuffer8_GetCurrentPosition(p,a,b)        IDirectSoundCaptureBuffer_GetCurrentPosition(p,a,b)
 9526#define IDirectSoundCaptureBuffer8_GetFormat(p,a,b,c)               IDirectSoundCaptureBuffer_GetFormat(p,a,b,c)
 9527#define IDirectSoundCaptureBuffer8_GetStatus(p,a)                   IDirectSoundCaptureBuffer_GetStatus(p,a)
 9528#define IDirectSoundCaptureBuffer8_Initialize(p,a,b)                IDirectSoundCaptureBuffer_Initialize(p,a,b)
 9529#define IDirectSoundCaptureBuffer8_Lock(p,a,b,c,d,e,f,g)            IDirectSoundCaptureBuffer_Lock(p,a,b,c,d,e,f,g)
 9530#define IDirectSoundCaptureBuffer8_Start(p,a)                       IDirectSoundCaptureBuffer_Start(p,a)
 9531#define IDirectSoundCaptureBuffer8_Stop(p)                          IDirectSoundCaptureBuffer_Stop(p))
 9532#define IDirectSoundCaptureBuffer8_Unlock(p,a,b,c,d)                IDirectSoundCaptureBuffer_Unlock(p,a,b,c,d)
 9533
 9534#if !defined(__cplusplus) || defined(CINTERFACE)
 9535#define IDirectSoundCaptureBuffer8_GetObjectInPath(p,a,b,c,d)       (p)->lpVtbl->GetObjectInPath(p,a,b,c,d)
 9536#define IDirectSoundCaptureBuffer8_GetFXStatus(p,a,b)               (p)->lpVtbl->GetFXStatus(p,a,b)
 9537#else
 9538#define IDirectSoundCaptureBuffer8_GetObjectInPath(p,a,b,c,d)       (p)->GetObjectInPath(a,b,c,d)
 9539#define IDirectSoundCaptureBuffer8_GetFXStatus(p,a,b)               (p)->GetFXStatus(a,b)
 9540#endif
 9541
 9542#endif
 9543
 9544DEFINE_GUID(IID_IDirectSoundNotify, 0xb0210783, 0x89cd, 0x11d0, 0xaf, 0x8, 0x0, 0xa0, 0xc9, 0x25, 0xcd, 0x16);
 9545
 9546#undef INTERFACE
 9547#define INTERFACE IDirectSoundNotify
 9548
 9549DECLARE_INTERFACE_(IDirectSoundNotify, IUnknown)
 9550{
 9551
 9552    STDMETHOD(QueryInterface)           (THIS_ REFIID, LPVOID *) PURE;
 9553    STDMETHOD_(ULONG,AddRef)            (THIS) PURE;
 9554    STDMETHOD_(ULONG,Release)           (THIS) PURE;
 9555
 9556    STDMETHOD(SetNotificationPositions) (THIS_ DWORD dwPositionNotifies, LPCDSBPOSITIONNOTIFY pcPositionNotifies) PURE;
 9557};
 9558
 9559#define IDirectSoundNotify_QueryInterface(p,a,b)            IUnknown_QueryInterface(p,a,b)
 9560#define IDirectSoundNotify_AddRef(p)                        IUnknown_AddRef(p)
 9561#define IDirectSoundNotify_Release(p)                       IUnknown_Release(p)
 9562
 9563#if !defined(__cplusplus) || defined(CINTERFACE)
 9564#define IDirectSoundNotify_SetNotificationPositions(p,a,b)  (p)->lpVtbl->SetNotificationPositions(p,a,b)
 9565#else
 9566#define IDirectSoundNotify_SetNotificationPositions(p,a,b)  (p)->SetNotificationPositions(a,b)
 9567#endif
 9568
 9569#ifndef _IKsPropertySet_
 9570#define _IKsPropertySet_
 9571
 9572#ifdef __cplusplus
 9573
 9574struct IKsPropertySet;
 9575#endif
 9576
 9577typedef struct IKsPropertySet *LPKSPROPERTYSET;
 9578
 9579#define KSPROPERTY_SUPPORT_GET  0x00000001
 9580#define KSPROPERTY_SUPPORT_SET  0x00000002
 9581
 9582DEFINE_GUID(IID_IKsPropertySet, 0x31efac30, 0x515c, 0x11d0, 0xa9, 0xaa, 0x00, 0xaa, 0x00, 0x61, 0xbe, 0x93);
 9583
 9584#undef INTERFACE
 9585#define INTERFACE IKsPropertySet
 9586
 9587DECLARE_INTERFACE_(IKsPropertySet, IUnknown)
 9588{
 9589
 9590    STDMETHOD(QueryInterface)   (THIS_ REFIID, LPVOID *) PURE;
 9591    STDMETHOD_(ULONG,AddRef)    (THIS) PURE;
 9592    STDMETHOD_(ULONG,Release)   (THIS) PURE;
 9593
 9594    STDMETHOD(Get)              (THIS_ REFGUID rguidPropSet, ULONG ulId, LPVOID pInstanceData, ULONG ulInstanceLength,
 9595                                       LPVOID pPropertyData, ULONG ulDataLength, PULONG pulBytesReturned) PURE;
 9596    STDMETHOD(Set)              (THIS_ REFGUID rguidPropSet, ULONG ulId, LPVOID pInstanceData, ULONG ulInstanceLength,
 9597                                       LPVOID pPropertyData, ULONG ulDataLength) PURE;
 9598    STDMETHOD(QuerySupport)     (THIS_ REFGUID rguidPropSet, ULONG ulId, PULONG pulTypeSupport) PURE;
 9599};
 9600
 9601#define IKsPropertySet_QueryInterface(p,a,b)       IUnknown_QueryInterface(p,a,b)
 9602#define IKsPropertySet_AddRef(p)                   IUnknown_AddRef(p)
 9603#define IKsPropertySet_Release(p)                  IUnknown_Release(p)
 9604
 9605#if !defined(__cplusplus) || defined(CINTERFACE)
 9606#define IKsPropertySet_Get(p,a,b,c,d,e,f,g)        (p)->lpVtbl->Get(p,a,b,c,d,e,f,g)
 9607#define IKsPropertySet_Set(p,a,b,c,d,e,f)          (p)->lpVtbl->Set(p,a,b,c,d,e,f)
 9608#define IKsPropertySet_QuerySupport(p,a,b,c)       (p)->lpVtbl->QuerySupport(p,a,b,c)
 9609#else
 9610#define IKsPropertySet_Get(p,a,b,c,d,e,f,g)        (p)->Get(a,b,c,d,e,f,g)
 9611#define IKsPropertySet_Set(p,a,b,c,d,e,f)          (p)->Set(a,b,c,d,e,f)
 9612#define IKsPropertySet_QuerySupport(p,a,b,c)       (p)->QuerySupport(a,b,c)
 9613#endif
 9614
 9615#endif
 9616
 9617#if DIRECTSOUND_VERSION >= 0x0800
 9618
 9619DEFINE_GUID(IID_IDirectSoundFXGargle, 0xd616f352, 0xd622, 0x11ce, 0xaa, 0xc5, 0x00, 0x20, 0xaf, 0x0b, 0x99, 0xa3);
 9620
 9621typedef struct _DSFXGargle
 9622{
 9623    DWORD       dwRateHz;
 9624    DWORD       dwWaveShape;
 9625} DSFXGargle, *LPDSFXGargle;
 9626
 9627#define DSFXGARGLE_WAVE_TRIANGLE        0
 9628#define DSFXGARGLE_WAVE_SQUARE          1
 9629
 9630typedef const DSFXGargle *LPCDSFXGargle;
 9631
 9632#define DSFXGARGLE_RATEHZ_MIN           1
 9633#define DSFXGARGLE_RATEHZ_MAX           1000
 9634
 9635#undef INTERFACE
 9636#define INTERFACE IDirectSoundFXGargle
 9637
 9638DECLARE_INTERFACE_(IDirectSoundFXGargle, IUnknown)
 9639{
 9640
 9641    STDMETHOD(QueryInterface)       (THIS_ REFIID, LPVOID *) PURE;
 9642    STDMETHOD_(ULONG,AddRef)        (THIS) PURE;
 9643    STDMETHOD_(ULONG,Release)       (THIS) PURE;
 9644
 9645    STDMETHOD(SetAllParameters)     (THIS_ LPCDSFXGargle pcDsFxGargle) PURE;
 9646    STDMETHOD(GetAllParameters)     (THIS_ LPDSFXGargle pDsFxGargle) PURE;
 9647};
 9648
 9649#define IDirectSoundFXGargle_QueryInterface(p,a,b)          IUnknown_QueryInterface(p,a,b)
 9650#define IDirectSoundFXGargle_AddRef(p)                      IUnknown_AddRef(p)
 9651#define IDirectSoundFXGargle_Release(p)                     IUnknown_Release(p)
 9652
 9653#if !defined(__cplusplus) || defined(CINTERFACE)
 9654#define IDirectSoundFXGargle_SetAllParameters(p,a)          (p)->lpVtbl->SetAllParameters(p,a)
 9655#define IDirectSoundFXGargle_GetAllParameters(p,a)          (p)->lpVtbl->GetAllParameters(p,a)
 9656#else
 9657#define IDirectSoundFXGargle_SetAllParameters(p,a)          (p)->SetAllParameters(a)
 9658#define IDirectSoundFXGargle_GetAllParameters(p,a)          (p)->GetAllParameters(a)
 9659#endif
 9660
 9661DEFINE_GUID(IID_IDirectSoundFXChorus, 0x880842e3, 0x145f, 0x43e6, 0xa9, 0x34, 0xa7, 0x18, 0x06, 0xe5, 0x05, 0x47);
 9662
 9663typedef struct _DSFXChorus
 9664{
 9665    FLOAT       fWetDryMix;
 9666    FLOAT       fDepth;
 9667    FLOAT       fFeedback;
 9668    FLOAT       fFrequency;
 9669    LONG        lWaveform;
 9670    FLOAT       fDelay;
 9671    LONG        lPhase;
 9672} DSFXChorus, *LPDSFXChorus;
 9673
 9674typedef const DSFXChorus *LPCDSFXChorus;
 9675
 9676#define DSFXCHORUS_WAVE_TRIANGLE        0
 9677#define DSFXCHORUS_WAVE_SIN             1
 9678
 9679#define DSFXCHORUS_WETDRYMIX_MIN        0.0f
 9680#define DSFXCHORUS_WETDRYMIX_MAX        100.0f
 9681#define DSFXCHORUS_DEPTH_MIN            0.0f
 9682#define DSFXCHORUS_DEPTH_MAX            100.0f
 9683#define DSFXCHORUS_FEEDBACK_MIN         -99.0f
 9684#define DSFXCHORUS_FEEDBACK_MAX         99.0f
 9685#define DSFXCHORUS_FREQUENCY_MIN        0.0f
 9686#define DSFXCHORUS_FREQUENCY_MAX        10.0f
 9687#define DSFXCHORUS_DELAY_MIN            0.0f
 9688#define DSFXCHORUS_DELAY_MAX            20.0f
 9689#define DSFXCHORUS_PHASE_MIN            0
 9690#define DSFXCHORUS_PHASE_MAX            4
 9691
 9692#define DSFXCHORUS_PHASE_NEG_180        0
 9693#define DSFXCHORUS_PHASE_NEG_90         1
 9694#define DSFXCHORUS_PHASE_ZERO           2
 9695#define DSFXCHORUS_PHASE_90             3
 9696#define DSFXCHORUS_PHASE_180            4
 9697
 9698#undef INTERFACE
 9699#define INTERFACE IDirectSoundFXChorus
 9700
 9701DECLARE_INTERFACE_(IDirectSoundFXChorus, IUnknown)
 9702{
 9703
 9704    STDMETHOD(QueryInterface)       (THIS_ REFIID, LPVOID *) PURE;
 9705    STDMETHOD_(ULONG,AddRef)        (THIS) PURE;
 9706    STDMETHOD_(ULONG,Release)       (THIS) PURE;
 9707
 9708    STDMETHOD(SetAllParameters)     (THIS_ LPCDSFXChorus pcDsFxChorus) PURE;
 9709    STDMETHOD(GetAllParameters)     (THIS_ LPDSFXChorus pDsFxChorus) PURE;
 9710};
 9711
 9712#define IDirectSoundFXChorus_QueryInterface(p,a,b)          IUnknown_QueryInterface(p,a,b)
 9713#define IDirectSoundFXChorus_AddRef(p)                      IUnknown_AddRef(p)
 9714#define IDirectSoundFXChorus_Release(p)                     IUnknown_Release(p)
 9715
 9716#if !defined(__cplusplus) || defined(CINTERFACE)
 9717#define IDirectSoundFXChorus_SetAllParameters(p,a)          (p)->lpVtbl->SetAllParameters(p,a)
 9718#define IDirectSoundFXChorus_GetAllParameters(p,a)          (p)->lpVtbl->GetAllParameters(p,a)
 9719#else
 9720#define IDirectSoundFXChorus_SetAllParameters(p,a)          (p)->SetAllParameters(a)
 9721#define IDirectSoundFXChorus_GetAllParameters(p,a)          (p)->GetAllParameters(a)
 9722#endif
 9723
 9724DEFINE_GUID(IID_IDirectSoundFXFlanger, 0x903e9878, 0x2c92, 0x4072, 0x9b, 0x2c, 0xea, 0x68, 0xf5, 0x39, 0x67, 0x83);
 9725
 9726typedef struct _DSFXFlanger
 9727{
 9728    FLOAT       fWetDryMix;
 9729    FLOAT       fDepth;
 9730    FLOAT       fFeedback;
 9731    FLOAT       fFrequency;
 9732    LONG        lWaveform;
 9733    FLOAT       fDelay;
 9734    LONG        lPhase;
 9735} DSFXFlanger, *LPDSFXFlanger;
 9736
 9737typedef const DSFXFlanger *LPCDSFXFlanger;
 9738
 9739#define DSFXFLANGER_WAVE_TRIANGLE       0
 9740#define DSFXFLANGER_WAVE_SIN            1
 9741
 9742#define DSFXFLANGER_WETDRYMIX_MIN       0.0f
 9743#define DSFXFLANGER_WETDRYMIX_MAX       100.0f
 9744#define DSFXFLANGER_FREQUENCY_MIN       0.0f
 9745#define DSFXFLANGER_FREQUENCY_MAX       10.0f
 9746#define DSFXFLANGER_DEPTH_MIN           0.0f
 9747#define DSFXFLANGER_DEPTH_MAX           100.0f
 9748#define DSFXFLANGER_PHASE_MIN           0
 9749#define DSFXFLANGER_PHASE_MAX           4
 9750#define DSFXFLANGER_FEEDBACK_MIN        -99.0f
 9751#define DSFXFLANGER_FEEDBACK_MAX        99.0f
 9752#define DSFXFLANGER_DELAY_MIN           0.0f
 9753#define DSFXFLANGER_DELAY_MAX           4.0f
 9754
 9755#define DSFXFLANGER_PHASE_NEG_180       0
 9756#define DSFXFLANGER_PHASE_NEG_90        1
 9757#define DSFXFLANGER_PHASE_ZERO          2
 9758#define DSFXFLANGER_PHASE_90            3
 9759#define DSFXFLANGER_PHASE_180           4
 9760
 9761#undef INTERFACE
 9762#define INTERFACE IDirectSoundFXFlanger
 9763
 9764DECLARE_INTERFACE_(IDirectSoundFXFlanger, IUnknown)
 9765{
 9766
 9767    STDMETHOD(QueryInterface)       (THIS_ REFIID, LPVOID *) PURE;
 9768    STDMETHOD_(ULONG,AddRef)        (THIS) PURE;
 9769    STDMETHOD_(ULONG,Release)       (THIS) PURE;
 9770
 9771    STDMETHOD(SetAllParameters)     (THIS_ LPCDSFXFlanger pcDsFxFlanger) PURE;
 9772    STDMETHOD(GetAllParameters)     (THIS_ LPDSFXFlanger pDsFxFlanger) PURE;
 9773};
 9774
 9775#define IDirectSoundFXFlanger_QueryInterface(p,a,b)         IUnknown_QueryInterface(p,a,b)
 9776#define IDirectSoundFXFlanger_AddRef(p)                     IUnknown_AddRef(p)
 9777#define IDirectSoundFXFlanger_Release(p)                    IUnknown_Release(p)
 9778
 9779#if !defined(__cplusplus) || defined(CINTERFACE)
 9780#define IDirectSoundFXFlanger_SetAllParameters(p,a)         (p)->lpVtbl->SetAllParameters(p,a)
 9781#define IDirectSoundFXFlanger_GetAllParameters(p,a)         (p)->lpVtbl->GetAllParameters(p,a)
 9782#else
 9783#define IDirectSoundFXFlanger_SetAllParameters(p,a)         (p)->SetAllParameters(a)
 9784#define IDirectSoundFXFlanger_GetAllParameters(p,a)         (p)->GetAllParameters(a)
 9785#endif
 9786
 9787DEFINE_GUID(IID_IDirectSoundFXEcho, 0x8bd28edf, 0x50db, 0x4e92, 0xa2, 0xbd, 0x44, 0x54, 0x88, 0xd1, 0xed, 0x42);
 9788
 9789typedef struct _DSFXEcho
 9790{
 9791    FLOAT   fWetDryMix;
 9792    FLOAT   fFeedback;
 9793    FLOAT   fLeftDelay;
 9794    FLOAT   fRightDelay;
 9795    LONG    lPanDelay;
 9796} DSFXEcho, *LPDSFXEcho;
 9797
 9798typedef const DSFXEcho *LPCDSFXEcho;
 9799
 9800#define DSFXECHO_WETDRYMIX_MIN      0.0f
 9801#define DSFXECHO_WETDRYMIX_MAX      100.0f
 9802#define DSFXECHO_FEEDBACK_MIN       0.0f
 9803#define DSFXECHO_FEEDBACK_MAX       100.0f
 9804#define DSFXECHO_LEFTDELAY_MIN      1.0f
 9805#define DSFXECHO_LEFTDELAY_MAX      2000.0f
 9806#define DSFXECHO_RIGHTDELAY_MIN     1.0f
 9807#define DSFXECHO_RIGHTDELAY_MAX     2000.0f
 9808#define DSFXECHO_PANDELAY_MIN       0
 9809#define DSFXECHO_PANDELAY_MAX       1
 9810
 9811#undef INTERFACE
 9812#define INTERFACE IDirectSoundFXEcho
 9813
 9814DECLARE_INTERFACE_(IDirectSoundFXEcho, IUnknown)
 9815{
 9816
 9817    STDMETHOD(QueryInterface)       (THIS_ REFIID, LPVOID *) PURE;
 9818    STDMETHOD_(ULONG,AddRef)        (THIS) PURE;
 9819    STDMETHOD_(ULONG,Release)       (THIS) PURE;
 9820
 9821    STDMETHOD(SetAllParameters)     (THIS_ LPCDSFXEcho pcDsFxEcho) PURE;
 9822    STDMETHOD(GetAllParameters)     (THIS_ LPDSFXEcho pDsFxEcho) PURE;
 9823};
 9824
 9825#define IDirectSoundFXEcho_QueryInterface(p,a,b)            IUnknown_QueryInterface(p,a,b)
 9826#define IDirectSoundFXEcho_AddRef(p)                        IUnknown_AddRef(p)
 9827#define IDirectSoundFXEcho_Release(p)                       IUnknown_Release(p)
 9828
 9829#if !defined(__cplusplus) || defined(CINTERFACE)
 9830#define IDirectSoundFXEcho_SetAllParameters(p,a)            (p)->lpVtbl->SetAllParameters(p,a)
 9831#define IDirectSoundFXEcho_GetAllParameters(p,a)            (p)->lpVtbl->GetAllParameters(p,a)
 9832#else
 9833#define IDirectSoundFXEcho_SetAllParameters(p,a)            (p)->SetAllParameters(a)
 9834#define IDirectSoundFXEcho_GetAllParameters(p,a)            (p)->GetAllParameters(a)
 9835#endif
 9836
 9837DEFINE_GUID(IID_IDirectSoundFXDistortion, 0x8ecf4326, 0x455f, 0x4d8b, 0xbd, 0xa9, 0x8d, 0x5d, 0x3e, 0x9e, 0x3e, 0x0b);
 9838
 9839typedef struct _DSFXDistortion
 9840{
 9841    FLOAT   fGain;
 9842    FLOAT   fEdge;
 9843    FLOAT   fPostEQCenterFrequency;
 9844    FLOAT   fPostEQBandwidth;
 9845    FLOAT   fPreLowpassCutoff;
 9846} DSFXDistortion, *LPDSFXDistortion;
 9847
 9848typedef const DSFXDistortion *LPCDSFXDistortion;
 9849
 9850#define DSFXDISTORTION_GAIN_MIN                     -60.0f
 9851#define DSFXDISTORTION_GAIN_MAX                     0.0f
 9852#define DSFXDISTORTION_EDGE_MIN                     0.0f
 9853#define DSFXDISTORTION_EDGE_MAX                     100.0f
 9854#define DSFXDISTORTION_POSTEQCENTERFREQUENCY_MIN    100.0f
 9855#define DSFXDISTORTION_POSTEQCENTERFREQUENCY_MAX    8000.0f
 9856#define DSFXDISTORTION_POSTEQBANDWIDTH_MIN          100.0f
 9857#define DSFXDISTORTION_POSTEQBANDWIDTH_MAX          8000.0f
 9858#define DSFXDISTORTION_PRELOWPASSCUTOFF_MIN         100.0f
 9859#define DSFXDISTORTION_PRELOWPASSCUTOFF_MAX         8000.0f
 9860
 9861#undef INTERFACE
 9862#define INTERFACE IDirectSoundFXDistortion
 9863
 9864DECLARE_INTERFACE_(IDirectSoundFXDistortion, IUnknown)
 9865{
 9866
 9867    STDMETHOD(QueryInterface)       (THIS_ REFIID, LPVOID *) PURE;
 9868    STDMETHOD_(ULONG,AddRef)        (THIS) PURE;
 9869    STDMETHOD_(ULONG,Release)       (THIS) PURE;
 9870
 9871    STDMETHOD(SetAllParameters)     (THIS_ LPCDSFXDistortion pcDsFxDistortion) PURE;
 9872    STDMETHOD(GetAllParameters)     (THIS_ LPDSFXDistortion pDsFxDistortion) PURE;
 9873};
 9874
 9875#define IDirectSoundFXDistortion_QueryInterface(p,a,b)      IUnknown_QueryInterface(p,a,b)
 9876#define IDirectSoundFXDistortion_AddRef(p)                  IUnknown_AddRef(p)
 9877#define IDirectSoundFXDistortion_Release(p)                 IUnknown_Release(p)
 9878
 9879#if !defined(__cplusplus) || defined(CINTERFACE)
 9880#define IDirectSoundFXDistortion_SetAllParameters(p,a)      (p)->lpVtbl->SetAllParameters(p,a)
 9881#define IDirectSoundFXDistortion_GetAllParameters(p,a)      (p)->lpVtbl->GetAllParameters(p,a)
 9882#else
 9883#define IDirectSoundFXDistortion_SetAllParameters(p,a)      (p)->SetAllParameters(a)
 9884#define IDirectSoundFXDistortion_GetAllParameters(p,a)      (p)->GetAllParameters(a)
 9885#endif
 9886
 9887DEFINE_GUID(IID_IDirectSoundFXCompressor, 0x4bbd1154, 0x62f6, 0x4e2c, 0xa1, 0x5c, 0xd3, 0xb6, 0xc4, 0x17, 0xf7, 0xa0);
 9888
 9889typedef struct _DSFXCompressor
 9890{
 9891    FLOAT   fGain;
 9892    FLOAT   fAttack;
 9893    FLOAT   fRelease;
 9894    FLOAT   fThreshold;
 9895    FLOAT   fRatio;
 9896    FLOAT   fPredelay;
 9897} DSFXCompressor, *LPDSFXCompressor;
 9898
 9899typedef const DSFXCompressor *LPCDSFXCompressor;
 9900
 9901#define DSFXCOMPRESSOR_GAIN_MIN             -60.0f
 9902#define DSFXCOMPRESSOR_GAIN_MAX             60.0f
 9903#define DSFXCOMPRESSOR_ATTACK_MIN           0.01f
 9904#define DSFXCOMPRESSOR_ATTACK_MAX           500.0f
 9905#define DSFXCOMPRESSOR_RELEASE_MIN          50.0f
 9906#define DSFXCOMPRESSOR_RELEASE_MAX          3000.0f
 9907#define DSFXCOMPRESSOR_THRESHOLD_MIN        -60.0f
 9908#define DSFXCOMPRESSOR_THRESHOLD_MAX        0.0f
 9909#define DSFXCOMPRESSOR_RATIO_MIN            1.0f
 9910#define DSFXCOMPRESSOR_RATIO_MAX            100.0f
 9911#define DSFXCOMPRESSOR_PREDELAY_MIN         0.0f
 9912#define DSFXCOMPRESSOR_PREDELAY_MAX         4.0f
 9913
 9914#undef INTERFACE
 9915#define INTERFACE IDirectSoundFXCompressor
 9916
 9917DECLARE_INTERFACE_(IDirectSoundFXCompressor, IUnknown)
 9918{
 9919
 9920    STDMETHOD(QueryInterface)       (THIS_ REFIID, LPVOID *) PURE;
 9921    STDMETHOD_(ULONG,AddRef)        (THIS) PURE;
 9922    STDMETHOD_(ULONG,Release)       (THIS) PURE;
 9923
 9924    STDMETHOD(SetAllParameters)     (THIS_ LPCDSFXCompressor pcDsFxCompressor) PURE;
 9925    STDMETHOD(GetAllParameters)     (THIS_ LPDSFXCompressor pDsFxCompressor) PURE;
 9926};
 9927
 9928#define IDirectSoundFXCompressor_QueryInterface(p,a,b)      IUnknown_QueryInterface(p,a,b)
 9929#define IDirectSoundFXCompressor_AddRef(p)                  IUnknown_AddRef(p)
 9930#define IDirectSoundFXCompressor_Release(p)                 IUnknown_Release(p)
 9931
 9932#if !defined(__cplusplus) || defined(CINTERFACE)
 9933#define IDirectSoundFXCompressor_SetAllParameters(p,a)      (p)->lpVtbl->SetAllParameters(p,a)
 9934#define IDirectSoundFXCompressor_GetAllParameters(p,a)      (p)->lpVtbl->GetAllParameters(p,a)
 9935#else
 9936#define IDirectSoundFXCompressor_SetAllParameters(p,a)      (p)->SetAllParameters(a)
 9937#define IDirectSoundFXCompressor_GetAllParameters(p,a)      (p)->GetAllParameters(a)
 9938#endif
 9939
 9940DEFINE_GUID(IID_IDirectSoundFXParamEq, 0xc03ca9fe, 0xfe90, 0x4204, 0x80, 0x78, 0x82, 0x33, 0x4c, 0xd1, 0x77, 0xda);
 9941
 9942typedef struct _DSFXParamEq
 9943{
 9944    FLOAT   fCenter;
 9945    FLOAT   fBandwidth;
 9946    FLOAT   fGain;
 9947} DSFXParamEq, *LPDSFXParamEq;
 9948
 9949typedef const DSFXParamEq *LPCDSFXParamEq;
 9950
 9951#define DSFXPARAMEQ_CENTER_MIN      80.0f
 9952#define DSFXPARAMEQ_CENTER_MAX      16000.0f
 9953#define DSFXPARAMEQ_BANDWIDTH_MIN   1.0f
 9954#define DSFXPARAMEQ_BANDWIDTH_MAX   36.0f
 9955#define DSFXPARAMEQ_GAIN_MIN        -15.0f
 9956#define DSFXPARAMEQ_GAIN_MAX        15.0f
 9957
 9958#undef INTERFACE
 9959#define INTERFACE IDirectSoundFXParamEq
 9960
 9961DECLARE_INTERFACE_(IDirectSoundFXParamEq, IUnknown)
 9962{
 9963
 9964    STDMETHOD(QueryInterface)       (THIS_ REFIID, LPVOID *) PURE;
 9965    STDMETHOD_(ULONG,AddRef)        (THIS) PURE;
 9966    STDMETHOD_(ULONG,Release)       (THIS) PURE;
 9967
 9968    STDMETHOD(SetAllParameters)     (THIS_ LPCDSFXParamEq pcDsFxParamEq) PURE;
 9969    STDMETHOD(GetAllParameters)     (THIS_ LPDSFXParamEq pDsFxParamEq) PURE;
 9970};
 9971
 9972#define IDirectSoundFXParamEq_QueryInterface(p,a,b)      IUnknown_QueryInterface(p,a,b)
 9973#define IDirectSoundFXParamEq_AddRef(p)                  IUnknown_AddRef(p)
 9974#define IDirectSoundFXParamEq_Release(p)                 IUnknown_Release(p)
 9975
 9976#if !defined(__cplusplus) || defined(CINTERFACE)
 9977#define IDirectSoundFXParamEq_SetAllParameters(p,a)      (p)->lpVtbl->SetAllParameters(p,a)
 9978#define IDirectSoundFXParamEq_GetAllParameters(p,a)      (p)->lpVtbl->GetAllParameters(p,a)
 9979#else
 9980#define IDirectSoundFXParamEq_SetAllParameters(p,a)      (p)->SetAllParameters(a)
 9981#define IDirectSoundFXParamEq_GetAllParameters(p,a)      (p)->GetAllParameters(a)
 9982#endif
 9983
 9984DEFINE_GUID(IID_IDirectSoundFXI3DL2Reverb, 0x4b166a6a, 0x0d66, 0x43f3, 0x80, 0xe3, 0xee, 0x62, 0x80, 0xde, 0xe1, 0xa4);
 9985
 9986typedef struct _DSFXI3DL2Reverb
 9987{
 9988    LONG    lRoom;
 9989    LONG    lRoomHF;
 9990    FLOAT   flRoomRolloffFactor;
 9991    FLOAT   flDecayTime;
 9992    FLOAT   flDecayHFRatio;
 9993    LONG    lReflections;
 9994    FLOAT   flReflectionsDelay;
 9995    LONG    lReverb;
 9996    FLOAT   flReverbDelay;
 9997    FLOAT   flDiffusion;
 9998    FLOAT   flDensity;
 9999    FLOAT   flHFReference;
10000} DSFXI3DL2Reverb, *LPDSFXI3DL2Reverb;
10001
10002typedef const DSFXI3DL2Reverb *LPCDSFXI3DL2Reverb;
10003
10004#define DSFX_I3DL2REVERB_ROOM_MIN                   (-10000)
10005#define DSFX_I3DL2REVERB_ROOM_MAX                   0
10006#define DSFX_I3DL2REVERB_ROOM_DEFAULT               (-1000)
10007
10008#define DSFX_I3DL2REVERB_ROOMHF_MIN                 (-10000)
10009#define DSFX_I3DL2REVERB_ROOMHF_MAX                 0
10010#define DSFX_I3DL2REVERB_ROOMHF_DEFAULT             (-100)
10011
10012#define DSFX_I3DL2REVERB_ROOMROLLOFFFACTOR_MIN      0.0f
10013#define DSFX_I3DL2REVERB_ROOMROLLOFFFACTOR_MAX      10.0f
10014#define DSFX_I3DL2REVERB_ROOMROLLOFFFACTOR_DEFAULT  0.0f
10015
10016#define DSFX_I3DL2REVERB_DECAYTIME_MIN              0.1f
10017#define DSFX_I3DL2REVERB_DECAYTIME_MAX              20.0f
10018#define DSFX_I3DL2REVERB_DECAYTIME_DEFAULT          1.49f
10019
10020#define DSFX_I3DL2REVERB_DECAYHFRATIO_MIN           0.1f
10021#define DSFX_I3DL2REVERB_DECAYHFRATIO_MAX           2.0f
10022#define DSFX_I3DL2REVERB_DECAYHFRATIO_DEFAULT       0.83f
10023
10024#define DSFX_I3DL2REVERB_REFLECTIONS_MIN            (-10000)
10025#define DSFX_I3DL2REVERB_REFLECTIONS_MAX            1000
10026#define DSFX_I3DL2REVERB_REFLECTIONS_DEFAULT        (-2602)
10027
10028#define DSFX_I3DL2REVERB_REFLECTIONSDELAY_MIN       0.0f
10029#define DSFX_I3DL2REVERB_REFLECTIONSDELAY_MAX       0.3f
10030#define DSFX_I3DL2REVERB_REFLECTIONSDELAY_DEFAULT   0.007f
10031
10032#define DSFX_I3DL2REVERB_REVERB_MIN                 (-10000)
10033#define DSFX_I3DL2REVERB_REVERB_MAX                 2000
10034#define DSFX_I3DL2REVERB_REVERB_DEFAULT             (200)
10035
10036#define DSFX_I3DL2REVERB_REVERBDELAY_MIN            0.0f
10037#define DSFX_I3DL2REVERB_REVERBDELAY_MAX            0.1f
10038#define DSFX_I3DL2REVERB_REVERBDELAY_DEFAULT        0.011f
10039
10040#define DSFX_I3DL2REVERB_DIFFUSION_MIN              0.0f
10041#define DSFX_I3DL2REVERB_DIFFUSION_MAX              100.0f
10042#define DSFX_I3DL2REVERB_DIFFUSION_DEFAULT          100.0f
10043
10044#define DSFX_I3DL2REVERB_DENSITY_MIN                0.0f
10045#define DSFX_I3DL2REVERB_DENSITY_MAX                100.0f
10046#define DSFX_I3DL2REVERB_DENSITY_DEFAULT            100.0f
10047
10048#define DSFX_I3DL2REVERB_HFREFERENCE_MIN            20.0f
10049#define DSFX_I3DL2REVERB_HFREFERENCE_MAX            20000.0f
10050#define DSFX_I3DL2REVERB_HFREFERENCE_DEFAULT        5000.0f
10051
10052#define DSFX_I3DL2REVERB_QUALITY_MIN                0
10053#define DSFX_I3DL2REVERB_QUALITY_MAX                3
10054#define DSFX_I3DL2REVERB_QUALITY_DEFAULT            2
10055
10056#undef INTERFACE
10057#define INTERFACE IDirectSoundFXI3DL2Reverb
10058
10059DECLARE_INTERFACE_(IDirectSoundFXI3DL2Reverb, IUnknown)
10060{
10061
10062    STDMETHOD(QueryInterface)       (THIS_ REFIID, LPVOID *) PURE;
10063    STDMETHOD_(ULONG,AddRef)        (THIS) PURE;
10064    STDMETHOD_(ULONG,Release)       (THIS) PURE;
10065
10066    STDMETHOD(SetAllParameters)     (THIS_ LPCDSFXI3DL2Reverb pcDsFxI3DL2Reverb) PURE;
10067    STDMETHOD(GetAllParameters)     (THIS_ LPDSFXI3DL2Reverb pDsFxI3DL2Reverb) PURE;
10068    STDMETHOD(SetPreset)            (THIS_ DWORD dwPreset) PURE;
10069    STDMETHOD(GetPreset)            (THIS_ LPDWORD pdwPreset) PURE;
10070    STDMETHOD(SetQuality)           (THIS_ LONG lQuality) PURE;
10071    STDMETHOD(GetQuality)           (THIS_ LONG *plQuality) PURE;
10072};
10073
10074#define IDirectSoundFXI3DL2Reverb_QueryInterface(p,a,b)     IUnknown_QueryInterface(p,a,b)
10075#define IDirectSoundFXI3DL2Reverb_AddRef(p)                 IUnknown_AddRef(p)
10076#define IDirectSoundFXI3DL2Reverb_Release(p)                IUnknown_Release(p)
10077
10078#if !defined(__cplusplus) || defined(CINTERFACE)
10079#define IDirectSoundFXI3DL2Reverb_SetAllParameters(p,a)     (p)->lpVtbl->SetAllParameters(p,a)
10080#define IDirectSoundFXI3DL2Reverb_GetAllParameters(p,a)     (p)->lpVtbl->GetAllParameters(p,a)
10081#define IDirectSoundFXI3DL2Reverb_SetPreset(p,a)            (p)->lpVtbl->SetPreset(p,a)
10082#define IDirectSoundFXI3DL2Reverb_GetPreset(p,a)            (p)->lpVtbl->GetPreset(p,a)
10083#else
10084#define IDirectSoundFXI3DL2Reverb_SetAllParameters(p,a)     (p)->SetAllParameters(a)
10085#define IDirectSoundFXI3DL2Reverb_GetAllParameters(p,a)     (p)->GetAllParameters(a)
10086#define IDirectSoundFXI3DL2Reverb_SetPreset(p,a)            (p)->SetPreset(a)
10087#define IDirectSoundFXI3DL2Reverb_GetPreset(p,a)            (p)->GetPreset(a)
10088#endif
10089
10090DEFINE_GUID(IID_IDirectSoundFXWavesReverb,0x46858c3a,0x0dc6,0x45e3,0xb7,0x60,0xd4,0xee,0xf1,0x6c,0xb3,0x25);
10091
10092typedef struct _DSFXWavesReverb
10093{
10094    FLOAT   fInGain;
10095    FLOAT   fReverbMix;
10096    FLOAT   fReverbTime;
10097    FLOAT   fHighFreqRTRatio;
10098} DSFXWavesReverb, *LPDSFXWavesReverb;
10099
10100typedef const DSFXWavesReverb *LPCDSFXWavesReverb;
10101
10102#define DSFX_WAVESREVERB_INGAIN_MIN                 -96.0f
10103#define DSFX_WAVESREVERB_INGAIN_MAX                 0.0f
10104#define DSFX_WAVESREVERB_INGAIN_DEFAULT             0.0f
10105#define DSFX_WAVESREVERB_REVERBMIX_MIN              -96.0f
10106#define DSFX_WAVESREVERB_REVERBMIX_MAX              0.0f
10107#define DSFX_WAVESREVERB_REVERBMIX_DEFAULT          0.0f
10108#define DSFX_WAVESREVERB_REVERBTIME_MIN             0.001f
10109#define DSFX_WAVESREVERB_REVERBTIME_MAX             3000.0f
10110#define DSFX_WAVESREVERB_REVERBTIME_DEFAULT         1000.0f
10111#define DSFX_WAVESREVERB_HIGHFREQRTRATIO_MIN        0.001f
10112#define DSFX_WAVESREVERB_HIGHFREQRTRATIO_MAX        0.999f
10113#define DSFX_WAVESREVERB_HIGHFREQRTRATIO_DEFAULT    0.001f
10114
10115#undef INTERFACE
10116#define INTERFACE IDirectSoundFXWavesReverb
10117
10118DECLARE_INTERFACE_(IDirectSoundFXWavesReverb, IUnknown)
10119{
10120
10121    STDMETHOD(QueryInterface)       (THIS_ REFIID, LPVOID *) PURE;
10122    STDMETHOD_(ULONG,AddRef)        (THIS) PURE;
10123    STDMETHOD_(ULONG,Release)       (THIS) PURE;
10124
10125    STDMETHOD(SetAllParameters)     (THIS_ LPCDSFXWavesReverb pcDsFxWavesReverb) PURE;
10126    STDMETHOD(GetAllParameters)     (THIS_ LPDSFXWavesReverb pDsFxWavesReverb) PURE;
10127};
10128
10129#define IDirectSoundFXWavesReverb_QueryInterface(p,a,b)     IUnknown_QueryInterface(p,a,b)
10130#define IDirectSoundFXWavesReverb_AddRef(p)                 IUnknown_AddRef(p)
10131#define IDirectSoundFXWavesReverb_Release(p)                IUnknown_Release(p)
10132
10133#if !defined(__cplusplus) || defined(CINTERFACE)
10134#define IDirectSoundFXWavesReverb_SetAllParameters(p,a)     (p)->lpVtbl->SetAllParameters(p,a)
10135#define IDirectSoundFXWavesReverb_GetAllParameters(p,a)     (p)->lpVtbl->GetAllParameters(p,a)
10136#else
10137#define IDirectSoundFXWavesReverb_SetAllParameters(p,a)     (p)->SetAllParameters(a)
10138#define IDirectSoundFXWavesReverb_GetAllParameters(p,a)     (p)->GetAllParameters(a)
10139#endif
10140
10141DEFINE_GUID(IID_IDirectSoundCaptureFXAec, 0x174d3eb9, 0x6696, 0x4fac, 0xa4, 0x6c, 0xa0, 0xac, 0x7b, 0xc9, 0xe2, 0xf);
10142
10143typedef struct _DSCFXAec
10144{
10145    BOOL    fEnable;
10146    BOOL    fReset;
10147} DSCFXAec, *LPDSCFXAec;
10148
10149typedef const DSCFXAec *LPCDSCFXAec;
10150
10151#undef INTERFACE
10152#define INTERFACE IDirectSoundCaptureFXAec
10153
10154DECLARE_INTERFACE_(IDirectSoundCaptureFXAec, IUnknown)
10155{
10156
10157    STDMETHOD(QueryInterface)       (THIS_ REFIID, LPVOID *) PURE;
10158    STDMETHOD_(ULONG,AddRef)        (THIS) PURE;
10159    STDMETHOD_(ULONG,Release)       (THIS) PURE;
10160
10161    STDMETHOD(SetAllParameters)     (THIS_ LPCDSCFXAec pDscFxAec) PURE;
10162    STDMETHOD(GetAllParameters)     (THIS_ LPDSCFXAec pDscFxAec) PURE;
10163};
10164
10165#define IDirectSoundCaptureFXAec_QueryInterface(p,a,b)     IUnknown_QueryInterface(p,a,b)
10166#define IDirectSoundCaptureFXAec_AddRef(p)                 IUnknown_AddRef(p)
10167#define IDirectSoundCaptureFXAec_Release(p)                IUnknown_Release(p)
10168
10169#if !defined(__cplusplus) || defined(CINTERFACE)
10170#define IDirectSoundCaptureFXAec_SetAllParameters(p,a)     (p)->lpVtbl->SetAllParameters(p,a)
10171#define IDirectSoundCaptureFXAec_GetAllParameters(p,a)     (p)->lpVtbl->GetAllParameters(p,a)
10172#else
10173#define IDirectSoundCaptureFXAec_SetAllParameters(p,a)     (p)->SetAllParameters(a)
10174#define IDirectSoundCaptureFXAec_GetAllParameters(p,a)     (p)->GetAllParameters(a)
10175#endif
10176
10177DEFINE_GUID(IID_IDirectSoundCaptureFXNoiseSuppress, 0xed311e41, 0xfbae, 0x4175, 0x96, 0x25, 0xcd, 0x8, 0x54, 0xf6, 0x93, 0xca);
10178
10179typedef struct _DSCFXNoiseSuppress
10180{
10181    BOOL    fEnable;
10182    BOOL    fReset;
10183} DSCFXNoiseSuppress, *LPDSCFXNoiseSuppress;
10184
10185typedef const DSCFXNoiseSuppress *LPCDSCFXNoiseSuppress;
10186
10187#undef INTERFACE
10188#define INTERFACE IDirectSoundCaptureFXNoiseSuppress
10189
10190DECLARE_INTERFACE_(IDirectSoundCaptureFXNoiseSuppress, IUnknown)
10191{
10192
10193    STDMETHOD(QueryInterface)       (THIS_ REFIID, LPVOID *) PURE;
10194    STDMETHOD_(ULONG,AddRef)        (THIS) PURE;
10195    STDMETHOD_(ULONG,Release)       (THIS) PURE;
10196
10197    STDMETHOD(SetAllParameters)     (THIS_ LPCDSCFXNoiseSuppress pcDscFxNoiseSuppress) PURE;
10198    STDMETHOD(GetAllParameters)     (THIS_ LPDSCFXNoiseSuppress pDscFxNoiseSuppress) PURE;
10199};
10200
10201#define IDirectSoundCaptureFXNoiseSuppress_QueryInterface(p,a,b)     IUnknown_QueryInterface(p,a,b)
10202#define IDirectSoundCaptureFXNoiseSuppress_AddRef(p)                 IUnknown_AddRef(p)
10203#define IDirectSoundCaptureFXNoiseSuppress_Release(p)                IUnknown_Release(p)
10204
10205#if !defined(__cplusplus) || defined(CINTERFACE)
10206#define IDirectSoundCaptureFXNoiseSuppress_SetAllParameters(p,a)     (p)->lpVtbl->SetAllParameters(p,a)
10207#define IDirectSoundCaptureFXNoiseSuppress_GetAllParameters(p,a)     (p)->lpVtbl->GetAllParameters(p,a)
10208#else
10209#define IDirectSoundCaptureFXNoiseSuppress_SetAllParameters(p,a)     (p)->SetAllParameters(a)
10210#define IDirectSoundCaptureFXNoiseSuppress_GetAllParameters(p,a)     (p)->GetAllParameters(a)
10211#endif
10212
10213#ifndef _IDirectSoundFullDuplex_
10214#define _IDirectSoundFullDuplex_
10215
10216#ifdef __cplusplus
10217
10218struct IDirectSoundFullDuplex;
10219#endif
10220
10221typedef struct IDirectSoundFullDuplex *LPDIRECTSOUNDFULLDUPLEX;
10222
10223DEFINE_GUID(IID_IDirectSoundFullDuplex, 0xedcb4c7a, 0xdaab, 0x4216, 0xa4, 0x2e, 0x6c, 0x50, 0x59, 0x6d, 0xdc, 0x1d);
10224
10225#undef INTERFACE
10226#define INTERFACE IDirectSoundFullDuplex
10227
10228DECLARE_INTERFACE_(IDirectSoundFullDuplex, IUnknown)
10229{
10230
10231    STDMETHOD(QueryInterface)   (THIS_ REFIID, LPVOID *) PURE;
10232    STDMETHOD_(ULONG,AddRef)    (THIS) PURE;
10233    STDMETHOD_(ULONG,Release)   (THIS) PURE;
10234
10235    STDMETHOD(Initialize)     (THIS_ LPCGUID pCaptureGuid, LPCGUID pRenderGuid, LPCDSCBUFFERDESC lpDscBufferDesc, LPCDSBUFFERDESC lpDsBufferDesc, HWND hWnd, DWORD dwLevel, LPLPDIRECTSOUNDCAPTUREBUFFER8 lplpDirectSoundCaptureBuffer8, LPLPDIRECTSOUNDBUFFER8 lplpDirectSoundBuffer8) PURE;
10236};
10237
10238#define IDirectSoundFullDuplex_QueryInterface(p,a,b)    IUnknown_QueryInterface(p,a,b)
10239#define IDirectSoundFullDuplex_AddRef(p)                IUnknown_AddRef(p)
10240#define IDirectSoundFullDuplex_Release(p)               IUnknown_Release(p)
10241
10242#if !defined(__cplusplus) || defined(CINTERFACE)
10243#define IDirectSoundFullDuplex_Initialize(p,a,b,c,d,e,f,g,h)     (p)->lpVtbl->Initialize(p,a,b,c,d,e,f,g,h)
10244#else
10245#define IDirectSoundFullDuplex_Initialize(p,a,b,c,d,e,f,g,h)     (p)->Initialize(a,b,c,d,e,f,g,h)
10246#endif
10247
10248#endif
10249
10250#endif
10251
10252#define DS_OK                           S_OK
10253
10254#define DS_NO_VIRTUALIZATION            MAKE_HRESULT(0, _FACDS, 10)
10255
10256#define DS_INCOMPLETE                   MAKE_HRESULT(0, _FACDS, 20)
10257
10258#define DSERR_ALLOCATED                 MAKE_DSHRESULT(10)
10259
10260#define DSERR_CONTROLUNAVAIL            MAKE_DSHRESULT(30)
10261
10262#define DSERR_INVALIDPARAM              E_INVALIDARG
10263
10264#define DSERR_INVALIDCALL               MAKE_DSHRESULT(50)
10265
10266#define DSERR_GENERIC                   E_FAIL
10267
10268#define DSERR_PRIOLEVELNEEDED           MAKE_DSHRESULT(70)
10269
10270#define DSERR_OUTOFMEMORY               E_OUTOFMEMORY
10271
10272#define DSERR_BADFORMAT                 MAKE_DSHRESULT(100)
10273
10274#define DSERR_UNSUPPORTED               E_NOTIMPL
10275
10276#define DSERR_NODRIVER                  MAKE_DSHRESULT(120)
10277
10278#define DSERR_ALREADYINITIALIZED        MAKE_DSHRESULT(130)
10279
10280#define DSERR_NOAGGREGATION             CLASS_E_NOAGGREGATION
10281
10282#define DSERR_BUFFERLOST                MAKE_DSHRESULT(150)
10283
10284#define DSERR_OTHERAPPHASPRIO           MAKE_DSHRESULT(160)
10285
10286#define DSERR_UNINITIALIZED             MAKE_DSHRESULT(170)
10287
10288#define DSERR_NOINTERFACE               E_NOINTERFACE
10289
10290#define DSERR_ACCESSDENIED              E_ACCESSDENIED
10291
10292#define DSERR_BUFFERTOOSMALL            MAKE_DSHRESULT(180)
10293
10294#define DSERR_DS8_REQUIRED              MAKE_DSHRESULT(190)
10295
10296#define DSERR_SENDLOOP                  MAKE_DSHRESULT(200)
10297
10298#define DSERR_BADSENDBUFFERGUID         MAKE_DSHRESULT(210)
10299
10300#define DSERR_OBJECTNOTFOUND            MAKE_DSHRESULT(4449)
10301
10302#define DSCAPS_PRIMARYMONO          0x00000001
10303#define DSCAPS_PRIMARYSTEREO        0x00000002
10304#define DSCAPS_PRIMARY8BIT          0x00000004
10305#define DSCAPS_PRIMARY16BIT         0x00000008
10306#define DSCAPS_CONTINUOUSRATE       0x00000010
10307#define DSCAPS_EMULDRIVER           0x00000020
10308#define DSCAPS_CERTIFIED            0x00000040
10309#define DSCAPS_SECONDARYMONO        0x00000100
10310#define DSCAPS_SECONDARYSTEREO      0x00000200
10311#define DSCAPS_SECONDARY8BIT        0x00000400
10312#define DSCAPS_SECONDARY16BIT       0x00000800
10313
10314#define DSSCL_NORMAL                0x00000001
10315#define DSSCL_PRIORITY              0x00000002
10316#define DSSCL_EXCLUSIVE             0x00000003
10317#define DSSCL_WRITEPRIMARY          0x00000004
10318
10319#define DSSPEAKER_HEADPHONE         0x00000001
10320#define DSSPEAKER_MONO              0x00000002
10321#define DSSPEAKER_QUAD              0x00000003
10322#define DSSPEAKER_STEREO            0x00000004
10323#define DSSPEAKER_SURROUND          0x00000005
10324#define DSSPEAKER_5POINT1           0x00000006
10325
10326#define DSSPEAKER_GEOMETRY_MIN      0x00000005
10327#define DSSPEAKER_GEOMETRY_NARROW   0x0000000A
10328#define DSSPEAKER_GEOMETRY_WIDE     0x00000014
10329#define DSSPEAKER_GEOMETRY_MAX      0x000000B4
10330
10331#define DSSPEAKER_COMBINED(c, g)    ((DWORD)(((BYTE)(c)) | ((DWORD)((BYTE)(g))) << 16))
10332#define DSSPEAKER_CONFIG(a)         ((BYTE)(a))
10333#define DSSPEAKER_GEOMETRY(a)       ((BYTE)(((DWORD)(a) >> 16) & 0x00FF))
10334
10335#define DSBCAPS_PRIMARYBUFFER       0x00000001
10336#define DSBCAPS_STATIC              0x00000002
10337#define DSBCAPS_LOCHARDWARE         0x00000004
10338#define DSBCAPS_LOCSOFTWARE         0x00000008
10339#define DSBCAPS_CTRL3D              0x00000010
10340#define DSBCAPS_CTRLFREQUENCY       0x00000020
10341#define DSBCAPS_CTRLPAN             0x00000040
10342#define DSBCAPS_CTRLVOLUME          0x00000080
10343#define DSBCAPS_CTRLPOSITIONNOTIFY  0x00000100
10344#define DSBCAPS_CTRLFX              0x00000200
10345#define DSBCAPS_STICKYFOCUS         0x00004000
10346#define DSBCAPS_GLOBALFOCUS         0x00008000
10347#define DSBCAPS_GETCURRENTPOSITION2 0x00010000
10348#define DSBCAPS_MUTE3DATMAXDISTANCE 0x00020000
10349#define DSBCAPS_LOCDEFER            0x00040000
10350
10351#define DSBPLAY_LOOPING             0x00000001
10352#define DSBPLAY_LOCHARDWARE         0x00000002
10353#define DSBPLAY_LOCSOFTWARE         0x00000004
10354#define DSBPLAY_TERMINATEBY_TIME    0x00000008
10355#define DSBPLAY_TERMINATEBY_DISTANCE    0x000000010
10356#define DSBPLAY_TERMINATEBY_PRIORITY    0x000000020
10357
10358#define DSBSTATUS_PLAYING           0x00000001
10359#define DSBSTATUS_BUFFERLOST        0x00000002
10360#define DSBSTATUS_LOOPING           0x00000004
10361#define DSBSTATUS_LOCHARDWARE       0x00000008
10362#define DSBSTATUS_LOCSOFTWARE       0x00000010
10363#define DSBSTATUS_TERMINATED        0x00000020
10364
10365#define DSBLOCK_FROMWRITECURSOR     0x00000001
10366#define DSBLOCK_ENTIREBUFFER        0x00000002
10367
10368#define DSBFREQUENCY_MIN            100
10369#define DSBFREQUENCY_MAX            100000
10370#define DSBFREQUENCY_ORIGINAL       0
10371
10372#define DSBPAN_LEFT                 -10000
10373#define DSBPAN_CENTER               0
10374#define DSBPAN_RIGHT                10000
10375
10376#define DSBVOLUME_MIN               -10000
10377#define DSBVOLUME_MAX               0
10378
10379#define DSBSIZE_MIN                 4
10380#define DSBSIZE_MAX                 0x0FFFFFFF
10381#define DSBSIZE_FX_MIN              150
10382
10383#define DS3DMODE_NORMAL             0x00000000
10384#define DS3DMODE_HEADRELATIVE       0x00000001
10385#define DS3DMODE_DISABLE            0x00000002
10386
10387#define DS3D_IMMEDIATE              0x00000000
10388#define DS3D_DEFERRED               0x00000001
10389
10390#define DS3D_MINDISTANCEFACTOR      FLT_MIN
10391#define DS3D_MAXDISTANCEFACTOR      FLT_MAX
10392#define DS3D_DEFAULTDISTANCEFACTOR  1.0f
10393
10394#define DS3D_MINROLLOFFFACTOR       0.0f
10395#define DS3D_MAXROLLOFFFACTOR       10.0f
10396#define DS3D_DEFAULTROLLOFFFACTOR   1.0f
10397
10398#define DS3D_MINDOPPLERFACTOR       0.0f
10399#define DS3D_MAXDOPPLERFACTOR       10.0f
10400#define DS3D_DEFAULTDOPPLERFACTOR   1.0f
10401
10402#define DS3D_DEFAULTMINDISTANCE     1.0f
10403#define DS3D_DEFAULTMAXDISTANCE     1000000000.0f
10404
10405#define DS3D_MINCONEANGLE           0
10406#define DS3D_MAXCONEANGLE           360
10407#define DS3D_DEFAULTCONEANGLE       360
10408
10409#define DS3D_DEFAULTCONEOUTSIDEVOLUME DSBVOLUME_MAX
10410
10411#define DSCCAPS_EMULDRIVER          DSCAPS_EMULDRIVER
10412#define DSCCAPS_CERTIFIED           DSCAPS_CERTIFIED
10413
10414#define DSCBCAPS_WAVEMAPPED         0x80000000
10415
10416#if DIRECTSOUND_VERSION >= 0x0800
10417#define DSCBCAPS_CTRLFX             0x00000200
10418#endif
10419
10420#define DSCBLOCK_ENTIREBUFFER       0x00000001
10421
10422#define DSCBSTATUS_CAPTURING        0x00000001
10423#define DSCBSTATUS_LOOPING          0x00000002
10424
10425#define DSCBSTART_LOOPING           0x00000001
10426
10427#define DSBPN_OFFSETSTOP            0xFFFFFFFF
10428
10429#define DS_CERTIFIED                0x00000000
10430#define DS_UNCERTIFIED              0x00000001
10431
10432#define DS_SYSTEM_RESOURCES_NO_HOST_RESOURCES  0x00000000
10433#define DS_SYSTEM_RESOURCES_ALL_HOST_RESOURCES 0x7FFFFFFF
10434#define DS_SYSTEM_RESOURCES_UNDEFINED          0x80000000
10435
10436enum
10437{
10438    DSFX_I3DL2_MATERIAL_PRESET_SINGLEWINDOW,
10439    DSFX_I3DL2_MATERIAL_PRESET_DOUBLEWINDOW,
10440    DSFX_I3DL2_MATERIAL_PRESET_THINDOOR,
10441    DSFX_I3DL2_MATERIAL_PRESET_THICKDOOR,
10442    DSFX_I3DL2_MATERIAL_PRESET_WOODWALL,
10443    DSFX_I3DL2_MATERIAL_PRESET_BRICKWALL,
10444    DSFX_I3DL2_MATERIAL_PRESET_STONEWALL,
10445    DSFX_I3DL2_MATERIAL_PRESET_CURTAIN
10446};
10447
10448#define I3DL2_MATERIAL_PRESET_SINGLEWINDOW    -2800,0.71f
10449#define I3DL2_MATERIAL_PRESET_DOUBLEWINDOW    -5000,0.40f
10450#define I3DL2_MATERIAL_PRESET_THINDOOR        -1800,0.66f
10451#define I3DL2_MATERIAL_PRESET_THICKDOOR       -4400,0.64f
10452#define I3DL2_MATERIAL_PRESET_WOODWALL        -4000,0.50f
10453#define I3DL2_MATERIAL_PRESET_BRICKWALL       -5000,0.60f
10454#define I3DL2_MATERIAL_PRESET_STONEWALL       -6000,0.68f
10455#define I3DL2_MATERIAL_PRESET_CURTAIN         -1200,0.15f
10456
10457enum
10458{
10459    DSFX_I3DL2_ENVIRONMENT_PRESET_DEFAULT,
10460    DSFX_I3DL2_ENVIRONMENT_PRESET_GENERIC,
10461    DSFX_I3DL2_ENVIRONMENT_PRESET_PADDEDCELL,
10462    DSFX_I3DL2_ENVIRONMENT_PRESET_ROOM,
10463    DSFX_I3DL2_ENVIRONMENT_PRESET_BATHROOM,
10464    DSFX_I3DL2_ENVIRONMENT_PRESET_LIVINGROOM,
10465    DSFX_I3DL2_ENVIRONMENT_PRESET_STONEROOM,
10466    DSFX_I3DL2_ENVIRONMENT_PRESET_AUDITORIUM,
10467    DSFX_I3DL2_ENVIRONMENT_PRESET_CONCERTHALL,
10468    DSFX_I3DL2_ENVIRONMENT_PRESET_CAVE,
10469    DSFX_I3DL2_ENVIRONMENT_PRESET_ARENA,
10470    DSFX_I3DL2_ENVIRONMENT_PRESET_HANGAR,
10471    DSFX_I3DL2_ENVIRONMENT_PRESET_CARPETEDHALLWAY,
10472    DSFX_I3DL2_ENVIRONMENT_PRESET_HALLWAY,
10473    DSFX_I3DL2_ENVIRONMENT_PRESET_STONECORRIDOR,
10474    DSFX_I3DL2_ENVIRONMENT_PRESET_ALLEY,
10475    DSFX_I3DL2_ENVIRONMENT_PRESET_FOREST,
10476    DSFX_I3DL2_ENVIRONMENT_PRESET_CITY,
10477    DSFX_I3DL2_ENVIRONMENT_PRESET_MOUNTAINS,
10478    DSFX_I3DL2_ENVIRONMENT_PRESET_QUARRY,
10479    DSFX_I3DL2_ENVIRONMENT_PRESET_PLAIN,
10480    DSFX_I3DL2_ENVIRONMENT_PRESET_PARKINGLOT,
10481    DSFX_I3DL2_ENVIRONMENT_PRESET_SEWERPIPE,
10482    DSFX_I3DL2_ENVIRONMENT_PRESET_UNDERWATER,
10483    DSFX_I3DL2_ENVIRONMENT_PRESET_SMALLROOM,
10484    DSFX_I3DL2_ENVIRONMENT_PRESET_MEDIUMROOM,
10485    DSFX_I3DL2_ENVIRONMENT_PRESET_LARGEROOM,
10486    DSFX_I3DL2_ENVIRONMENT_PRESET_MEDIUMHALL,
10487    DSFX_I3DL2_ENVIRONMENT_PRESET_LARGEHALL,
10488    DSFX_I3DL2_ENVIRONMENT_PRESET_PLATE
10489};
10490
10491#define I3DL2_ENVIRONMENT_PRESET_DEFAULT         -1000, -100, 0.0f, 1.49f, 0.83f, -2602, 0.007f,   200, 0.011f, 100.0f, 100.0f, 5000.0f
10492#define I3DL2_ENVIRONMENT_PRESET_GENERIC         -1000, -100, 0.0f, 1.49f, 0.83f, -2602, 0.007f,   200, 0.011f, 100.0f, 100.0f, 5000.0f
10493#define I3DL2_ENVIRONMENT_PRESET_PADDEDCELL      -1000,-6000, 0.0f, 0.17f, 0.10f, -1204, 0.001f,   207, 0.002f, 100.0f, 100.0f, 5000.0f
10494#define I3DL2_ENVIRONMENT_PRESET_ROOM            -1000, -454, 0.0f, 0.40f, 0.83f, -1646, 0.002f,    53, 0.003f, 100.0f, 100.0f, 5000.0f
10495#define I3DL2_ENVIRONMENT_PRESET_BATHROOM        -1000,-1200, 0.0f, 1.49f, 0.54f,  -370, 0.007f,  1030, 0.011f, 100.0f,  60.0f, 5000.0f
10496#define I3DL2_ENVIRONMENT_PRESET_LIVINGROOM      -1000,-6000, 0.0f, 0.50f, 0.10f, -1376, 0.003f, -1104, 0.004f, 100.0f, 100.0f, 5000.0f
10497#define I3DL2_ENVIRONMENT_PRESET_STONEROOM       -1000, -300, 0.0f, 2.31f, 0.64f,  -711, 0.012f,    83, 0.017f, 100.0f, 100.0f, 5000.0f
10498#define I3DL2_ENVIRONMENT_PRESET_AUDITORIUM      -1000, -476, 0.0f, 4.32f, 0.59f,  -789, 0.020f,  -289, 0.030f, 100.0f, 100.0f, 5000.0f
10499#define I3DL2_ENVIRONMENT_PRESET_CONCERTHALL     -1000, -500, 0.0f, 3.92f, 0.70f, -1230, 0.020f,    -2, 0.029f, 100.0f, 100.0f, 5000.0f
10500#define I3DL2_ENVIRONMENT_PRESET_CAVE            -1000,    0, 0.0f, 2.91f, 1.30f,  -602, 0.015f,  -302, 0.022f, 100.0f, 100.0f, 5000.0f
10501#define I3DL2_ENVIRONMENT_PRESET_ARENA           -1000, -698, 0.0f, 7.24f, 0.33f, -1166, 0.020f,    16, 0.030f, 100.0f, 100.0f, 5000.0f
10502#define I3DL2_ENVIRONMENT_PRESET_HANGAR          -1000,-1000, 0.0f,10.05f, 0.23f,  -602, 0.020f,   198, 0.030f, 100.0f, 100.0f, 5000.0f
10503#define I3DL2_ENVIRONMENT_PRESET_CARPETEDHALLWAY -1000,-4000, 0.0f, 0.30f, 0.10f, -1831, 0.002f, -1630, 0.030f, 100.0f, 100.0f, 5000.0f
10504#define I3DL2_ENVIRONMENT_PRESET_HALLWAY         -1000, -300, 0.0f, 1.49f, 0.59f, -1219, 0.007f,   441, 0.011f, 100.0f, 100.0f, 5000.0f
10505#define I3DL2_ENVIRONMENT_PRESET_STONECORRIDOR   -1000, -237, 0.0f, 2.70f, 0.79f, -1214, 0.013f,   395, 0.020f, 100.0f, 100.0f, 5000.0f
10506#define I3DL2_ENVIRONMENT_PRESET_ALLEY           -1000, -270, 0.0f, 1.49f, 0.86f, -1204, 0.007f,    -4, 0.011f, 100.0f, 100.0f, 5000.0f
10507#define I3DL2_ENVIRONMENT_PRESET_FOREST          -1000,-3300, 0.0f, 1.49f, 0.54f, -2560, 0.162f,  -613, 0.088f,  79.0f, 100.0f, 5000.0f
10508#define I3DL2_ENVIRONMENT_PRESET_CITY            -1000, -800, 0.0f, 1.49f, 0.67f, -2273, 0.007f, -2217, 0.011f,  50.0f, 100.0f, 5000.0f
10509#define I3DL2_ENVIRONMENT_PRESET_MOUNTAINS       -1000,-2500, 0.0f, 1.49f, 0.21f, -2780, 0.300f, -2014, 0.100f,  27.0f, 100.0f, 5000.0f
10510#define I3DL2_ENVIRONMENT_PRESET_QUARRY          -1000,-1000, 0.0f, 1.49f, 0.83f,-10000, 0.061f,   500, 0.025f, 100.0f, 100.0f, 5000.0f
10511#define I3DL2_ENVIRONMENT_PRESET_PLAIN           -1000,-2000, 0.0f, 1.49f, 0.50f, -2466, 0.179f, -2514, 0.100f,  21.0f, 100.0f, 5000.0f
10512#define I3DL2_ENVIRONMENT_PRESET_PARKINGLOT      -1000,    0, 0.0f, 1.65f, 1.50f, -1363, 0.008f, -1153, 0.012f, 100.0f, 100.0f, 5000.0f
10513#define I3DL2_ENVIRONMENT_PRESET_SEWERPIPE       -1000,-1000, 0.0f, 2.81f, 0.14f,   429, 0.014f,   648, 0.021f,  80.0f,  60.0f, 5000.0f
10514#define I3DL2_ENVIRONMENT_PRESET_UNDERWATER      -1000,-4000, 0.0f, 1.49f, 0.10f,  -449, 0.007f,  1700, 0.011f, 100.0f, 100.0f, 5000.0f
10515
10516#define I3DL2_ENVIRONMENT_PRESET_SMALLROOM       -1000, -600, 0.0f, 1.10f, 0.83f,  -400, 0.005f,   500, 0.010f, 100.0f, 100.0f, 5000.0f
10517#define I3DL2_ENVIRONMENT_PRESET_MEDIUMROOM      -1000, -600, 0.0f, 1.30f, 0.83f, -1000, 0.010f,  -200, 0.020f, 100.0f, 100.0f, 5000.0f
10518#define I3DL2_ENVIRONMENT_PRESET_LARGEROOM       -1000, -600, 0.0f, 1.50f, 0.83f, -1600, 0.020f, -1000, 0.040f, 100.0f, 100.0f, 5000.0f
10519#define I3DL2_ENVIRONMENT_PRESET_MEDIUMHALL      -1000, -600, 0.0f, 1.80f, 0.70f, -1300, 0.015f,  -800, 0.030f, 100.0f, 100.0f, 5000.0f
10520#define I3DL2_ENVIRONMENT_PRESET_LARGEHALL       -1000, -600, 0.0f, 1.80f, 0.70f, -2000, 0.030f, -1400, 0.060f, 100.0f, 100.0f, 5000.0f
10521#define I3DL2_ENVIRONMENT_PRESET_PLATE           -1000, -200, 0.0f, 1.30f, 0.90f,     0, 0.002f,     0, 0.010f, 100.0f,  75.0f, 5000.0f
10522
10523#define DS3DALG_DEFAULT GUID_NULL
10524
10525DEFINE_GUID(DS3DALG_NO_VIRTUALIZATION, 0xc241333f, 0x1c1b, 0x11d2, 0x94, 0xf5, 0x0, 0xc0, 0x4f, 0xc2, 0x8a, 0xca);
10526
10527DEFINE_GUID(DS3DALG_HRTF_FULL, 0xc2413340, 0x1c1b, 0x11d2, 0x94, 0xf5, 0x0, 0xc0, 0x4f, 0xc2, 0x8a, 0xca);
10528
10529DEFINE_GUID(DS3DALG_HRTF_LIGHT, 0xc2413342, 0x1c1b, 0x11d2, 0x94, 0xf5, 0x0, 0xc0, 0x4f, 0xc2, 0x8a, 0xca);
10530
10531#if DIRECTSOUND_VERSION >= 0x0800
10532
10533DEFINE_GUID(GUID_DSFX_STANDARD_GARGLE, 0xdafd8210, 0x5711, 0x4b91, 0x9f, 0xe3, 0xf7, 0x5b, 0x7a, 0xe2, 0x79, 0xbf);
10534
10535DEFINE_GUID(GUID_DSFX_STANDARD_CHORUS, 0xefe6629c, 0x81f7, 0x4281, 0xbd, 0x91, 0xc9, 0xd6, 0x04, 0xa9, 0x5a, 0xf6);
10536
10537DEFINE_GUID(GUID_DSFX_STANDARD_FLANGER, 0xefca3d92, 0xdfd8, 0x4672, 0xa6, 0x03, 0x74, 0x20, 0x89, 0x4b, 0xad, 0x98);
10538
10539DEFINE_GUID(GUID_DSFX_STANDARD_ECHO, 0xef3e932c, 0xd40b, 0x4f51, 0x8c, 0xcf, 0x3f, 0x98, 0xf1, 0xb2, 0x9d, 0x5d);
10540
10541DEFINE_GUID(GUID_DSFX_STANDARD_DISTORTION, 0xef114c90, 0xcd1d, 0x484e, 0x96, 0xe5, 0x09, 0xcf, 0xaf, 0x91, 0x2a, 0x21);
10542
10543DEFINE_GUID(GUID_DSFX_STANDARD_COMPRESSOR, 0xef011f79, 0x4000, 0x406d, 0x87, 0xaf, 0xbf, 0xfb, 0x3f, 0xc3, 0x9d, 0x57);
10544
10545DEFINE_GUID(GUID_DSFX_STANDARD_PARAMEQ, 0x120ced89, 0x3bf4, 0x4173, 0xa1, 0x32, 0x3c, 0xb4, 0x06, 0xcf, 0x32, 0x31);
10546
10547DEFINE_GUID(GUID_DSFX_STANDARD_I3DL2REVERB, 0xef985e71, 0xd5c7, 0x42d4, 0xba, 0x4d, 0x2d, 0x07, 0x3e, 0x2e, 0x96, 0xf4);
10548
10549DEFINE_GUID(GUID_DSFX_WAVES_REVERB, 0x87fc0268, 0x9a55, 0x4360, 0x95, 0xaa, 0x00, 0x4a, 0x1d, 0x9d, 0xe2, 0x6c);
10550
10551DEFINE_GUID(GUID_DSCFX_CLASS_AEC, 0xBF963D80L, 0xC559, 0x11D0, 0x8A, 0x2B, 0x00, 0xA0, 0xC9, 0x25, 0x5A, 0xC1);
10552
10553DEFINE_GUID(GUID_DSCFX_MS_AEC, 0xcdebb919, 0x379a, 0x488a, 0x87, 0x65, 0xf5, 0x3c, 0xfd, 0x36, 0xde, 0x40);
10554
10555DEFINE_GUID(GUID_DSCFX_SYSTEM_AEC, 0x1c22c56d, 0x9879, 0x4f5b, 0xa3, 0x89, 0x27, 0x99, 0x6d, 0xdc, 0x28, 0x10);
10556
10557DEFINE_GUID(GUID_DSCFX_CLASS_NS, 0xe07f903f, 0x62fd, 0x4e60, 0x8c, 0xdd, 0xde, 0xa7, 0x23, 0x66, 0x65, 0xb5);
10558
10559DEFINE_GUID(GUID_DSCFX_MS_NS, 0x11c5c73b, 0x66e9, 0x4ba1, 0xa0, 0xba, 0xe8, 0x14, 0xc6, 0xee, 0xd9, 0x2d);
10560
10561DEFINE_GUID(GUID_DSCFX_SYSTEM_NS, 0x5ab0882e, 0x7274, 0x4516, 0x87, 0x7d, 0x4e, 0xee, 0x99, 0xba, 0x4f, 0xd0);
10562
10563#endif
10564
10565#endif
10566
10567#ifdef __cplusplus
10568};
10569#endif
10570#ifndef __DINPUT_INCLUDED__
10571#define __DINPUT_INCLUDED__
10572
10573#ifndef DIJ_RINGZERO
10574
10575#ifdef _WIN32
10576#define COM_NO_WINDOWS_H
10577#include <objbase.h>
10578#endif
10579
10580#endif
10581
10582#ifdef __cplusplus
10583extern "C" {
10584#endif
10585
10586#define DIRECTINPUT_HEADER_VERSION  0x0800
10587#ifndef DIRECTINPUT_VERSION
10588#define DIRECTINPUT_VERSION         DIRECTINPUT_HEADER_VERSION
10589#endif
10590
10591#ifndef DIJ_RINGZERO
10592
10593DEFINE_GUID(CLSID_DirectInput,       0x25E609E0,0xB259,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
10594DEFINE_GUID(CLSID_DirectInputDevice, 0x25E609E1,0xB259,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
10595
10596DEFINE_GUID(CLSID_DirectInput8,      0x25E609E4,0xB259,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
10597DEFINE_GUID(CLSID_DirectInputDevice8,0x25E609E5,0xB259,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
10598
10599DEFINE_GUID(IID_IDirectInputA,     0x89521360,0xAA8A,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
10600DEFINE_GUID(IID_IDirectInputW,     0x89521361,0xAA8A,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
10601DEFINE_GUID(IID_IDirectInput2A,    0x5944E662,0xAA8A,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
10602DEFINE_GUID(IID_IDirectInput2W,    0x5944E663,0xAA8A,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
10603DEFINE_GUID(IID_IDirectInput7A,    0x9A4CB684,0x236D,0x11D3,0x8E,0x9D,0x00,0xC0,0x4F,0x68,0x44,0xAE);
10604DEFINE_GUID(IID_IDirectInput7W,    0x9A4CB685,0x236D,0x11D3,0x8E,0x9D,0x00,0xC0,0x4F,0x68,0x44,0xAE);
10605DEFINE_GUID(IID_IDirectInput8A,    0xBF798030,0x483A,0x4DA2,0xAA,0x99,0x5D,0x64,0xED,0x36,0x97,0x00);
10606DEFINE_GUID(IID_IDirectInput8W,    0xBF798031,0x483A,0x4DA2,0xAA,0x99,0x5D,0x64,0xED,0x36,0x97,0x00);
10607DEFINE_GUID(IID_IDirectInputDeviceA, 0x5944E680,0xC92E,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
10608DEFINE_GUID(IID_IDirectInputDeviceW, 0x5944E681,0xC92E,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
10609DEFINE_GUID(IID_IDirectInputDevice2A,0x5944E682,0xC92E,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
10610DEFINE_GUID(IID_IDirectInputDevice2W,0x5944E683,0xC92E,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
10611DEFINE_GUID(IID_IDirectInputDevice7A,0x57D7C6BC,0x2356,0x11D3,0x8E,0x9D,0x00,0xC0,0x4F,0x68,0x44,0xAE);
10612DEFINE_GUID(IID_IDirectInputDevice7W,0x57D7C6BD,0x2356,0x11D3,0x8E,0x9D,0x00,0xC0,0x4F,0x68,0x44,0xAE);
10613DEFINE_GUID(IID_IDirectInputDevice8A,0x54D41080,0xDC15,0x4833,0xA4,0x1B,0x74,0x8F,0x73,0xA3,0x81,0x79);
10614DEFINE_GUID(IID_IDirectInputDevice8W,0x54D41081,0xDC15,0x4833,0xA4,0x1B,0x74,0x8F,0x73,0xA3,0x81,0x79);
10615DEFINE_GUID(IID_IDirectInputEffect,  0xE7E1F7C0,0x88D2,0x11D0,0x9A,0xD0,0x00,0xA0,0xC9,0xA0,0x6E,0x35);
10616
10617DEFINE_GUID(GUID_XAxis,   0xA36D02E0,0xC9F3,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
10618DEFINE_GUID(GUID_YAxis,   0xA36D02E1,0xC9F3,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
10619DEFINE_GUID(GUID_ZAxis,   0xA36D02E2,0xC9F3,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
10620DEFINE_GUID(GUID_RxAxis,  0xA36D02F4,0xC9F3,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
10621DEFINE_GUID(GUID_RyAxis,  0xA36D02F5,0xC9F3,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
10622DEFINE_GUID(GUID_RzAxis,  0xA36D02E3,0xC9F3,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
10623DEFINE_GUID(GUID_Slider,  0xA36D02E4,0xC9F3,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
10624
10625DEFINE_GUID(GUID_Button,  0xA36D02F0,0xC9F3,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
10626DEFINE_GUID(GUID_Key,     0x55728220,0xD33C,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
10627
10628DEFINE_GUID(GUID_POV,     0xA36D02F2,0xC9F3,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
10629
10630DEFINE_GUID(GUID_Unknown, 0xA36D02F3,0xC9F3,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
10631
10632DEFINE_GUID(GUID_SysMouse,   0x6F1D2B60,0xD5A0,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
10633DEFINE_GUID(GUID_SysKeyboard,0x6F1D2B61,0xD5A0,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
10634DEFINE_GUID(GUID_Joystick   ,0x6F1D2B70,0xD5A0,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
10635DEFINE_GUID(GUID_SysMouseEm, 0x6F1D2B80,0xD5A0,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
10636DEFINE_GUID(GUID_SysMouseEm2,0x6F1D2B81,0xD5A0,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
10637DEFINE_GUID(GUID_SysKeyboardEm, 0x6F1D2B82,0xD5A0,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
10638DEFINE_GUID(GUID_SysKeyboardEm2,0x6F1D2B83,0xD5A0,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
10639
10640DEFINE_GUID(GUID_ConstantForce, 0x13541C20,0x8E33,0x11D0,0x9A,0xD0,0x00,0xA0,0xC9,0xA0,0x6E,0x35);
10641DEFINE_GUID(GUID_RampForce,     0x13541C21,0x8E33,0x11D0,0x9A,0xD0,0x00,0xA0,0xC9,0xA0,0x6E,0x35);
10642DEFINE_GUID(GUID_Square,        0x13541C22,0x8E33,0x11D0,0x9A,0xD0,0x00,0xA0,0xC9,0xA0,0x6E,0x35);
10643DEFINE_GUID(GUID_Sine,          0x13541C23,0x8E33,0x11D0,0x9A,0xD0,0x00,0xA0,0xC9,0xA0,0x6E,0x35);
10644DEFINE_GUID(GUID_Triangle,      0x13541C24,0x8E33,0x11D0,0x9A,0xD0,0x00,0xA0,0xC9,0xA0,0x6E,0x35);
10645DEFINE_GUID(GUID_SawtoothUp,    0x13541C25,0x8E33,0x11D0,0x9A,0xD0,0x00,0xA0,0xC9,0xA0,0x6E,0x35);
10646DEFINE_GUID(GUID_SawtoothDown,  0x13541C26,0x8E33,0x11D0,0x9A,0xD0,0x00,0xA0,0xC9,0xA0,0x6E,0x35);
10647DEFINE_GUID(GUID_Spring,        0x13541C27,0x8E33,0x11D0,0x9A,0xD0,0x00,0xA0,0xC9,0xA0,0x6E,0x35);
10648DEFINE_GUID(GUID_Damper,        0x13541C28,0x8E33,0x11D0,0x9A,0xD0,0x00,0xA0,0xC9,0xA0,0x6E,0x35);
10649DEFINE_GUID(GUID_Inertia,       0x13541C29,0x8E33,0x11D0,0x9A,0xD0,0x00,0xA0,0xC9,0xA0,0x6E,0x35);
10650DEFINE_GUID(GUID_Friction,      0x13541C2A,0x8E33,0x11D0,0x9A,0xD0,0x00,0xA0,0xC9,0xA0,0x6E,0x35);
10651DEFINE_GUID(GUID_CustomForce,   0x13541C2B,0x8E33,0x11D0,0x9A,0xD0,0x00,0xA0,0xC9,0xA0,0x6E,0x35);
10652
10653#endif
10654
10655#if(DIRECTINPUT_VERSION >= 0x0500)
10656
10657#define DIEFT_ALL                   0x00000000
10658
10659#define DIEFT_CONSTANTFORCE         0x00000001
10660#define DIEFT_RAMPFORCE             0x00000002
10661#define DIEFT_PERIODIC              0x00000003
10662#define DIEFT_CONDITION             0x00000004
10663#define DIEFT_CUSTOMFORCE           0x00000005
10664#define DIEFT_HARDWARE              0x000000FF
10665#define DIEFT_FFATTACK              0x00000200
10666#define DIEFT_FFFADE                0x00000400
10667#define DIEFT_SATURATION            0x00000800
10668#define DIEFT_POSNEGCOEFFICIENTS    0x00001000
10669#define DIEFT_POSNEGSATURATION      0x00002000
10670#define DIEFT_DEADBAND              0x00004000
10671#define DIEFT_STARTDELAY            0x00008000
10672#define DIEFT_GETTYPE(n)            LOBYTE(n)
10673
10674#define DI_DEGREES                  100
10675#define DI_FFNOMINALMAX             10000
10676#define DI_SECONDS                  1000000
10677
10678typedef struct DICONSTANTFORCE {
10679    LONG  lMagnitude;
10680} DICONSTANTFORCE, *LPDICONSTANTFORCE;
10681typedef const DICONSTANTFORCE *LPCDICONSTANTFORCE;
10682
10683typedef struct DIRAMPFORCE {
10684    LONG  lStart;
10685    LONG  lEnd;
10686} DIRAMPFORCE, *LPDIRAMPFORCE;
10687typedef const DIRAMPFORCE *LPCDIRAMPFORCE;
10688
10689typedef struct DIPERIODIC {
10690    DWORD dwMagnitude;
10691    LONG  lOffset;
10692    DWORD dwPhase;
10693    DWORD dwPeriod;
10694} DIPERIODIC, *LPDIPERIODIC;
10695typedef const DIPERIODIC *LPCDIPERIODIC;
10696
10697typedef struct DICONDITION {
10698    LONG  lOffset;
10699    LONG  lPositiveCoefficient;
10700    LONG  lNegativeCoefficient;
10701    DWORD dwPositiveSaturation;
10702    DWORD dwNegativeSaturation;
10703    LONG  lDeadBand;
10704} DICONDITION, *LPDICONDITION;
10705typedef const DICONDITION *LPCDICONDITION;
10706
10707typedef struct DICUSTOMFORCE {
10708    DWORD cChannels;
10709    DWORD dwSamplePeriod;
10710    DWORD cSamples;
10711    LPLONG rglForceData;
10712} DICUSTOMFORCE, *LPDICUSTOMFORCE;
10713typedef const DICUSTOMFORCE *LPCDICUSTOMFORCE;
10714
10715typedef struct DIENVELOPE {
10716    DWORD dwSize;
10717    DWORD dwAttackLevel;
10718    DWORD dwAttackTime;
10719    DWORD dwFadeLevel;
10720    DWORD dwFadeTime;
10721} DIENVELOPE, *LPDIENVELOPE;
10722typedef const DIENVELOPE *LPCDIENVELOPE;
10723
10724typedef struct DIEFFECT_DX5 {
10725    DWORD dwSize;
10726    DWORD dwFlags;
10727    DWORD dwDuration;
10728    DWORD dwSamplePeriod;
10729    DWORD dwGain;
10730    DWORD dwTriggerButton;
10731    DWORD dwTriggerRepeatInterval;
10732    DWORD cAxes;
10733    LPDWORD rgdwAxes;
10734    LPLONG rglDirection;
10735    LPDIENVELOPE lpEnvelope;
10736    DWORD cbTypeSpecificParams;
10737    LPVOID lpvTypeSpecificParams;
10738} DIEFFECT_DX5, *LPDIEFFECT_DX5;
10739typedef const DIEFFECT_DX5 *LPCDIEFFECT_DX5;
10740
10741typedef struct DIEFFECT {
10742    DWORD dwSize;
10743    DWORD dwFlags;
10744    DWORD dwDuration;
10745    DWORD dwSamplePeriod;
10746    DWORD dwGain;
10747    DWORD dwTriggerButton;
10748    DWORD dwTriggerRepeatInterval;
10749    DWORD cAxes;
10750    LPDWORD rgdwAxes;
10751    LPLONG rglDirection;
10752    LPDIENVELOPE lpEnvelope;
10753    DWORD cbTypeSpecificParams;
10754    LPVOID lpvTypeSpecificParams;
10755#if(DIRECTINPUT_VERSION >= 0x0600)
10756    DWORD  dwStartDelay;
10757#endif
10758} DIEFFECT, *LPDIEFFECT;
10759typedef DIEFFECT DIEFFECT_DX6;
10760typedef LPDIEFFECT LPDIEFFECT_DX6;
10761typedef const DIEFFECT *LPCDIEFFECT;
10762
10763#if(DIRECTINPUT_VERSION >= 0x0700)
10764#ifndef DIJ_RINGZERO
10765typedef struct DIFILEEFFECT{
10766    DWORD       dwSize;
10767    GUID        GuidEffect;
10768    LPCDIEFFECT lpDiEffect;
10769    CHAR        szFriendlyName[MAX_PATH];
10770}DIFILEEFFECT, *LPDIFILEEFFECT;
10771typedef const DIFILEEFFECT *LPCDIFILEEFFECT;
10772typedef BOOL (FAR PASCAL * LPDIENUMEFFECTSINFILECALLBACK)(LPCDIFILEEFFECT , LPVOID);
10773#endif
10774#endif
10775
10776#define DIEFF_OBJECTIDS             0x00000001
10777#define DIEFF_OBJECTOFFSETS         0x00000002
10778#define DIEFF_CARTESIAN             0x00000010
10779#define DIEFF_POLAR                 0x00000020
10780#define DIEFF_SPHERICAL             0x00000040
10781
10782#define DIEP_DURATION               0x00000001
10783#define DIEP_SAMPLEPERIOD           0x00000002
10784#define DIEP_GAIN                   0x00000004
10785#define DIEP_TRIGGERBUTTON          0x00000008
10786#define DIEP_TRIGGERREPEATINTERVAL  0x00000010
10787#define DIEP_AXES                   0x00000020
10788#define DIEP_DIRECTION              0x00000040
10789#define DIEP_ENVELOPE               0x00000080
10790#define DIEP_TYPESPECIFICPARAMS     0x00000100
10791#if(DIRECTINPUT_VERSION >= 0x0600)
10792#define DIEP_STARTDELAY             0x00000200
10793#define DIEP_ALLPARAMS_DX5          0x000001FF
10794#define DIEP_ALLPARAMS              0x000003FF
10795#else
10796#define DIEP_ALLPARAMS              0x000001FF
10797#endif
10798#define DIEP_START                  0x20000000
10799#define DIEP_NORESTART              0x40000000
10800#define DIEP_NODOWNLOAD             0x80000000
10801#define DIEB_NOTRIGGER              0xFFFFFFFF
10802
10803#define DIES_SOLO                   0x00000001
10804#define DIES_NODOWNLOAD             0x80000000
10805
10806#define DIEGES_PLAYING              0x00000001
10807#define DIEGES_EMULATED             0x00000002
10808
10809typedef struct DIEFFESCAPE {
10810    DWORD   dwSize;
10811    DWORD   dwCommand;
10812    LPVOID  lpvInBuffer;
10813    DWORD   cbInBuffer;
10814    LPVOID  lpvOutBuffer;
10815    DWORD   cbOutBuffer;
10816} DIEFFESCAPE, *LPDIEFFESCAPE;
10817
10818#ifndef DIJ_RINGZERO
10819
10820#undef INTERFACE
10821#define INTERFACE IDirectInputEffect
10822
10823DECLARE_INTERFACE_(IDirectInputEffect, IUnknown)
10824{
10825
10826    STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
10827    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
10828    STDMETHOD_(ULONG,Release)(THIS) PURE;
10829
10830    STDMETHOD(Initialize)(THIS_ HINSTANCE,DWORD,REFGUID) PURE;
10831    STDMETHOD(GetEffectGuid)(THIS_ LPGUID) PURE;
10832    STDMETHOD(GetParameters)(THIS_ LPDIEFFECT,DWORD) PURE;
10833    STDMETHOD(SetParameters)(THIS_ LPCDIEFFECT,DWORD) PURE;
10834    STDMETHOD(Start)(THIS_ DWORD,DWORD) PURE;
10835    STDMETHOD(Stop)(THIS) PURE;
10836    STDMETHOD(GetEffectStatus)(THIS_ LPDWORD) PURE;
10837    STDMETHOD(Download)(THIS) PURE;
10838    STDMETHOD(Unload)(THIS) PURE;
10839    STDMETHOD(Escape)(THIS_ LPDIEFFESCAPE) PURE;
10840};
10841
10842typedef struct IDirectInputEffect *LPDIRECTINPUTEFFECT;
10843
10844#if !defined(__cplusplus) || defined(CINTERFACE)
10845#define IDirectInputEffect_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
10846#define IDirectInputEffect_AddRef(p) (p)->lpVtbl->AddRef(p)
10847#define IDirectInputEffect_Release(p) (p)->lpVtbl->Release(p)
10848#define IDirectInputEffect_Initialize(p,a,b,c) (p)->lpVtbl->Initialize(p,a,b,c)
10849#define IDirectInputEffect_GetEffectGuid(p,a) (p)->lpVtbl->GetEffectGuid(p,a)
10850#define IDirectInputEffect_GetParameters(p,a,b) (p)->lpVtbl->GetParameters(p,a,b)
10851#define IDirectInputEffect_SetParameters(p,a,b) (p)->lpVtbl->SetParameters(p,a,b)
10852#define IDirectInputEffect_Start(p,a,b) (p)->lpVtbl->Start(p,a,b)
10853#define IDirectInputEffect_Stop(p) (p)->lpVtbl->Stop(p)
10854#define IDirectInputEffect_GetEffectStatus(p,a) (p)->lpVtbl->GetEffectStatus(p,a)
10855#define IDirectInputEffect_Download(p) (p)->lpVtbl->Download(p)
10856#define IDirectInputEffect_Unload(p) (p)->lpVtbl->Unload(p)
10857#define IDirectInputEffect_Escape(p,a) (p)->lpVtbl->Escape(p,a)
10858#else
10859#define IDirectInputEffect_QueryInterface(p,a,b) (p)->QueryInterface(a,b)
10860#define IDirectInputEffect_AddRef(p) (p)->AddRef()
10861#define IDirectInputEffect_Release(p) (p)->Release()
10862#define IDirectInputEffect_Initialize(p,a,b,c) (p)->Initialize(a,b,c)
10863#define IDirectInputEffect_GetEffectGuid(p,a) (p)->GetEffectGuid(a)
10864#define IDirectInputEffect_GetParameters(p,a,b) (p)->GetParameters(a,b)
10865#define IDirectInputEffect_SetParameters(p,a,b) (p)->SetParameters(a,b)
10866#define IDirectInputEffect_Start(p,a,b) (p)->Start(a,b)
10867#define IDirectInputEffect_Stop(p) (p)->Stop()
10868#define IDirectInputEffect_GetEffectStatus(p,a) (p)->GetEffectStatus(a)
10869#define IDirectInputEffect_Download(p) (p)->Download()
10870#define IDirectInputEffect_Unload(p) (p)->Unload()
10871#define IDirectInputEffect_Escape(p,a) (p)->Escape(a)
10872#endif
10873
10874#endif
10875
10876#endif
10877
10878#if DIRECTINPUT_VERSION <= 0x700
10879#define DIDEVTYPE_DEVICE        1
10880#define DIDEVTYPE_MOUSE         2
10881#define DIDEVTYPE_KEYBOARD      3
10882#define DIDEVTYPE_JOYSTICK      4
10883
10884#else
10885#define DI8DEVCLASS_ALL             0
10886#define DI8DEVCLASS_DEVICE          1
10887#define DI8DEVCLASS_POINTER         2
10888#define DI8DEVCLASS_KEYBOARD        3
10889#define DI8DEVCLASS_GAMECTRL        4
10890
10891#define DI8DEVTYPE_DEVICE           0x11
10892#define DI8DEVTYPE_MOUSE            0x12
10893#define DI8DEVTYPE_KEYBOARD         0x13
10894#define DI8DEVTYPE_JOYSTICK         0x14
10895#define DI8DEVTYPE_GAMEPAD          0x15
10896#define DI8DEVTYPE_DRIVING          0x16
10897#define DI8DEVTYPE_FLIGHT           0x17
10898#define DI8DEVTYPE_1STPERSON        0x18
10899#define DI8DEVTYPE_DEVICECTRL       0x19
10900#define DI8DEVTYPE_SCREENPOINTER    0x1A
10901#define DI8DEVTYPE_REMOTE           0x1B
10902#define DI8DEVTYPE_SUPPLEMENTAL     0x1C
10903#endif
10904
10905#define DIDEVTYPE_HID           0x00010000
10906
10907#if DIRECTINPUT_VERSION <= 0x700
10908#define DIDEVTYPEMOUSE_UNKNOWN          1
10909#define DIDEVTYPEMOUSE_TRADITIONAL      2
10910#define DIDEVTYPEMOUSE_FINGERSTICK      3
10911#define DIDEVTYPEMOUSE_TOUCHPAD         4
10912#define DIDEVTYPEMOUSE_TRACKBALL        5
10913
10914#define DIDEVTYPEKEYBOARD_UNKNOWN       0
10915#define DIDEVTYPEKEYBOARD_PCXT          1
10916#define DIDEVTYPEKEYBOARD_OLIVETTI      2
10917#define DIDEVTYPEKEYBOARD_PCAT          3
10918#define DIDEVTYPEKEYBOARD_PCENH         4
10919#define DIDEVTYPEKEYBOARD_NOKIA1050     5
10920#define DIDEVTYPEKEYBOARD_NOKIA9140     6
10921#define DIDEVTYPEKEYBOARD_NEC98         7
10922#define DIDEVTYPEKEYBOARD_NEC98LAPTOP   8
10923#define DIDEVTYPEKEYBOARD_NEC98106      9
10924#define DIDEVTYPEKEYBOARD_JAPAN106     10
10925#define DIDEVTYPEKEYBOARD_JAPANAX      11
10926#define DIDEVTYPEKEYBOARD_J3100        12
10927
10928#define DIDEVTYPEJOYSTICK_UNKNOWN       1
10929#define DIDEVTYPEJOYSTICK_TRADITIONAL   2
10930#define DIDEVTYPEJOYSTICK_FLIGHTSTICK   3
10931#define DIDEVTYPEJOYSTICK_GAMEPAD       4
10932#define DIDEVTYPEJOYSTICK_RUDDER        5
10933#define DIDEVTYPEJOYSTICK_WHEEL         6
10934#define DIDEVTYPEJOYSTICK_HEADTRACKER   7
10935
10936#else
10937#define DI8DEVTYPEMOUSE_UNKNOWN                     1
10938#define DI8DEVTYPEMOUSE_TRADITIONAL                 2
10939#define DI8DEVTYPEMOUSE_FINGERSTICK                 3
10940#define DI8DEVTYPEMOUSE_TOUCHPAD                    4
10941#define DI8DEVTYPEMOUSE_TRACKBALL                   5
10942#define DI8DEVTYPEMOUSE_ABSOLUTE                    6
10943
10944#define DI8DEVTYPEKEYBOARD_UNKNOWN                  0
10945#define DI8DEVTYPEKEYBOARD_PCXT                     1
10946#define DI8DEVTYPEKEYBOARD_OLIVETTI                 2
10947#define DI8DEVTYPEKEYBOARD_PCAT                     3
10948#define DI8DEVTYPEKEYBOARD_PCENH                    4
10949#define DI8DEVTYPEKEYBOARD_NOKIA1050                5
10950#define DI8DEVTYPEKEYBOARD_NOKIA9140                6
10951#define DI8DEVTYPEKEYBOARD_NEC98                    7
10952#define DI8DEVTYPEKEYBOARD_NEC98LAPTOP              8
10953#define DI8DEVTYPEKEYBOARD_NEC98106                 9
10954#define DI8DEVTYPEKEYBOARD_JAPAN106                10
10955#define DI8DEVTYPEKEYBOARD_JAPANAX                 11
10956#define DI8DEVTYPEKEYBOARD_J3100                   12
10957
10958#define DI8DEVTYPE_LIMITEDGAMESUBTYPE               1
10959
10960#define DI8DEVTYPEJOYSTICK_LIMITED                  DI8DEVTYPE_LIMITEDGAMESUBTYPE
10961#define DI8DEVTYPEJOYSTICK_STANDARD                 2
10962
10963#define DI8DEVTYPEGAMEPAD_LIMITED                   DI8DEVTYPE_LIMITEDGAMESUBTYPE
10964#define DI8DEVTYPEGAMEPAD_STANDARD                  2
10965#define DI8DEVTYPEGAMEPAD_TILT                      3
10966
10967#define DI8DEVTYPEDRIVING_LIMITED                   DI8DEVTYPE_LIMITEDGAMESUBTYPE
10968#define DI8DEVTYPEDRIVING_COMBINEDPEDALS            2
10969#define DI8DEVTYPEDRIVING_DUALPEDALS                3
10970#define DI8DEVTYPEDRIVING_THREEPEDALS               4
10971#define DI8DEVTYPEDRIVING_HANDHELD                  5
10972
10973#define DI8DEVTYPEFLIGHT_LIMITED                    DI8DEVTYPE_LIMITEDGAMESUBTYPE
10974#define DI8DEVTYPEFLIGHT_STICK                      2
10975#define DI8DEVTYPEFLIGHT_YOKE                       3
10976#define DI8DEVTYPEFLIGHT_RC                         4
10977
10978#define DI8DEVTYPE1STPERSON_LIMITED                 DI8DEVTYPE_LIMITEDGAMESUBTYPE
10979#define DI8DEVTYPE1STPERSON_UNKNOWN                 2
10980#define DI8DEVTYPE1STPERSON_SIXDOF                  3
10981#define DI8DEVTYPE1STPERSON_SHOOTER                 4
10982
10983#define DI8DEVTYPESCREENPTR_UNKNOWN                 2
10984#define DI8DEVTYPESCREENPTR_LIGHTGUN                3
10985#define DI8DEVTYPESCREENPTR_LIGHTPEN                4
10986#define DI8DEVTYPESCREENPTR_TOUCH                   5
10987
10988#define DI8DEVTYPEREMOTE_UNKNOWN                    2
10989
10990#define DI8DEVTYPEDEVICECTRL_UNKNOWN                2
10991#define DI8DEVTYPEDEVICECTRL_COMMSSELECTION         3
10992#define DI8DEVTYPEDEVICECTRL_COMMSSELECTION_HARDWIRED 4
10993
10994#define DI8DEVTYPESUPPLEMENTAL_UNKNOWN              2
10995#define DI8DEVTYPESUPPLEMENTAL_2NDHANDCONTROLLER    3
10996#define DI8DEVTYPESUPPLEMENTAL_HEADTRACKER          4
10997#define DI8DEVTYPESUPPLEMENTAL_HANDTRACKER          5
10998#define DI8DEVTYPESUPPLEMENTAL_SHIFTSTICKGATE       6
10999#define DI8DEVTYPESUPPLEMENTAL_SHIFTER              7
11000#define DI8DEVTYPESUPPLEMENTAL_THROTTLE             8
11001#define DI8DEVTYPESUPPLEMENTAL_SPLITTHROTTLE        9
11002#define DI8DEVTYPESUPPLEMENTAL_COMBINEDPEDALS      10
11003#define DI8DEVTYPESUPPLEMENTAL_DUALPEDALS          11
11004#define DI8DEVTYPESUPPLEMENTAL_THREEPEDALS         12
11005#define DI8DEVTYPESUPPLEMENTAL_RUDDERPEDALS        13
11006#endif
11007
11008#define GET_DIDEVICE_TYPE(dwDevType)    LOBYTE(dwDevType)
11009#define GET_DIDEVICE_SUBTYPE(dwDevType) HIBYTE(dwDevType)
11010
11011#if(DIRECTINPUT_VERSION >= 0x0500)
11012
11013typedef struct DIDEVCAPS_DX3 {
11014    DWORD   dwSize;
11015    DWORD   dwFlags;
11016    DWORD   dwDevType;
11017    DWORD   dwAxes;
11018    DWORD   dwButtons;
11019    DWORD   dwPOVs;
11020} DIDEVCAPS_DX3, *LPDIDEVCAPS_DX3;
11021#endif
11022
11023typedef struct DIDEVCAPS {
11024    DWORD   dwSize;
11025    DWORD   dwFlags;
11026    DWORD   dwDevType;
11027    DWORD   dwAxes;
11028    DWORD   dwButtons;
11029    DWORD   dwPOVs;
11030#if(DIRECTINPUT_VERSION >= 0x0500)
11031    DWORD   dwFFSamplePeriod;
11032    DWORD   dwFFMinTimeResolution;
11033    DWORD   dwFirmwareRevision;
11034    DWORD   dwHardwareRevision;
11035    DWORD   dwFFDriverVersion;
11036#endif
11037} DIDEVCAPS, *LPDIDEVCAPS;
11038
11039#define DIDC_ATTACHED           0x00000001
11040#define DIDC_POLLEDDEVICE       0x00000002
11041#define DIDC_EMULATED           0x00000004
11042#define DIDC_POLLEDDATAFORMAT   0x00000008
11043#if(DIRECTINPUT_VERSION >= 0x0500)
11044#define DIDC_FORCEFEEDBACK      0x00000100
11045#define DIDC_FFATTACK           0x00000200
11046#define DIDC_FFFADE             0x00000400
11047#define DIDC_SATURATION         0x00000800
11048#define DIDC_POSNEGCOEFFICIENTS 0x00001000
11049#define DIDC_POSNEGSATURATION   0x00002000
11050#define DIDC_DEADBAND           0x00004000
11051#endif
11052#define DIDC_STARTDELAY         0x00008000
11053#if(DIRECTINPUT_VERSION >= 0x050a)
11054#define DIDC_ALIAS              0x00010000
11055#define DIDC_PHANTOM            0x00020000
11056#endif
11057#if(DIRECTINPUT_VERSION >= 0x0800)
11058#define DIDC_HIDDEN             0x00040000
11059#endif
11060
11061#define DIDFT_ALL           0x00000000
11062
11063#define DIDFT_RELAXIS       0x00000001
11064#define DIDFT_ABSAXIS       0x00000002
11065#define DIDFT_AXIS          0x00000003
11066
11067#define DIDFT_PSHBUTTON     0x00000004
11068#define DIDFT_TGLBUTTON     0x00000008
11069#define DIDFT_BUTTON        0x0000000C
11070
11071#define DIDFT_POV           0x00000010
11072#define DIDFT_COLLECTION    0x00000040
11073#define DIDFT_NODATA        0x00000080
11074
11075#define DIDFT_ANYINSTANCE   0x00FFFF00
11076#define DIDFT_INSTANCEMASK  DIDFT_ANYINSTANCE
11077#define DIDFT_MAKEINSTANCE(n) ((WORD)(n) << 8)
11078#define DIDFT_GETTYPE(n)     LOBYTE(n)
11079#define DIDFT_GETINSTANCE(n) LOWORD((n) >> 8)
11080#define DIDFT_FFACTUATOR        0x01000000
11081#define DIDFT_FFEFFECTTRIGGER   0x02000000
11082#if(DIRECTINPUT_VERSION >= 0x050a)
11083#define DIDFT_OUTPUT            0x10000000
11084#define DIDFT_VENDORDEFINED     0x04000000
11085#define DIDFT_ALIAS             0x08000000
11086#endif
11087
11088#define DIDFT_ENUMCOLLECTION(n) ((WORD)(n) << 8)
11089#define DIDFT_NOCOLLECTION      0x00FFFF00
11090
11091#ifndef DIJ_RINGZERO
11092
11093typedef struct _DIOBJECTDATAFORMAT {
11094    const GUID *pguid;
11095    DWORD   dwOfs;
11096    DWORD   dwType;
11097    DWORD   dwFlags;
11098} DIOBJECTDATAFORMAT, *LPDIOBJECTDATAFORMAT;
11099typedef const DIOBJECTDATAFORMAT *LPCDIOBJECTDATAFORMAT;
11100
11101typedef struct _DIDATAFORMAT {
11102    DWORD   dwSize;
11103    DWORD   dwObjSize;
11104    DWORD   dwFlags;
11105    DWORD   dwDataSize;
11106    DWORD   dwNumObjs;
11107    LPDIOBJECTDATAFORMAT rgodf;
11108} DIDATAFORMAT, *LPDIDATAFORMAT;
11109typedef const DIDATAFORMAT *LPCDIDATAFORMAT;
11110
11111#define DIDF_ABSAXIS            0x00000001
11112#define DIDF_RELAXIS            0x00000002
11113
11114#ifdef __cplusplus
11115extern "C" {
11116#endif
11117extern const DIDATAFORMAT c_dfDIMouse;
11118
11119#if(DIRECTINPUT_VERSION >= 0x0700)
11120extern const DIDATAFORMAT c_dfDIMouse2;
11121#endif
11122
11123extern const DIDATAFORMAT c_dfDIKeyboard;
11124
11125#if(DIRECTINPUT_VERSION >= 0x0500)
11126extern const DIDATAFORMAT c_dfDIJoystick;
11127extern const DIDATAFORMAT c_dfDIJoystick2;
11128#endif
11129
11130#ifdef __cplusplus
11131};
11132#endif
11133
11134#if DIRECTINPUT_VERSION > 0x0700
11135
11136typedef struct _DIACTIONA {
11137                UINT_PTR    uAppData;
11138                DWORD       dwSemantic;
11139    OPTIONAL    DWORD       dwFlags;
11140    OPTIONAL    union {
11141                    LPCSTR      lptszActionName;
11142                    UINT        uResIdString;
11143                };
11144    OPTIONAL    GUID        guidInstance;
11145    OPTIONAL    DWORD       dwObjID;
11146    OPTIONAL    DWORD       dwHow;
11147} DIACTIONA, *LPDIACTIONA ;
11148typedef struct _DIACTIONW {
11149                UINT_PTR    uAppData;
11150                DWORD       dwSemantic;
11151    OPTIONAL    DWORD       dwFlags;
11152    OPTIONAL    union {
11153                    LPCWSTR     lptszActionName;
11154                    UINT        uResIdString;
11155                };
11156    OPTIONAL    GUID        guidInstance;
11157    OPTIONAL    DWORD       dwObjID;
11158    OPTIONAL    DWORD       dwHow;
11159} DIACTIONW, *LPDIACTIONW ;
11160#ifdef UNICODE
11161typedef DIACTIONW DIACTION;
11162typedef LPDIACTIONW LPDIACTION;
11163#else
11164typedef DIACTIONA DIACTION;
11165typedef LPDIACTIONA LPDIACTION;
11166#endif
11167
11168typedef const DIACTIONA *LPCDIACTIONA;
11169typedef const DIACTIONW *LPCDIACTIONW;
11170#ifdef UNICODE
11171typedef DIACTIONW DIACTION;
11172typedef LPCDIACTIONW LPCDIACTION;
11173#else
11174typedef DIACTIONA DIACTION;
11175typedef LPCDIACTIONA LPCDIACTION;
11176#endif
11177typedef const DIACTION *LPCDIACTION;
11178
11179#define DIA_FORCEFEEDBACK       0x00000001
11180#define DIA_APPMAPPED           0x00000002
11181#define DIA_APPNOMAP            0x00000004
11182#define DIA_NORANGE             0x00000008
11183#define DIA_APPFIXED            0x00000010
11184
11185#define DIAH_UNMAPPED           0x00000000
11186#define DIAH_USERCONFIG         0x00000001
11187#define DIAH_APPREQUESTED       0x00000002
11188#define DIAH_HWAPP              0x00000004
11189#define DIAH_HWDEFAULT          0x00000008
11190#define DIAH_DEFAULT            0x00000020
11191#define DIAH_ERROR              0x80000000
11192
11193typedef struct _DIACTIONFORMATA {
11194                DWORD       dwSize;
11195                DWORD       dwActionSize;
11196                DWORD       dwDataSize;
11197                DWORD       dwNumActions;
11198                LPDIACTIONA rgoAction;
11199                GUID        guidActionMap;
11200                DWORD       dwGenre;
11201                DWORD       dwBufferSize;
11202    OPTIONAL    LONG        lAxisMin;
11203    OPTIONAL    LONG        lAxisMax;
11204    OPTIONAL    HINSTANCE   hInstString;
11205                FILETIME    ftTimeStamp;
11206                DWORD       dwCRC;
11207                CHAR        tszActionMap[MAX_PATH];
11208} DIACTIONFORMATA, *LPDIACTIONFORMATA;
11209typedef struct _DIACTIONFORMATW {
11210                DWORD       dwSize;
11211                DWORD       dwActionSize;
11212                DWORD       dwDataSize;
11213                DWORD       dwNumActions;
11214                LPDIACTIONW rgoAction;
11215                GUID        guidActionMap;
11216                DWORD       dwGenre;
11217                DWORD       dwBufferSize;
11218    OPTIONAL    LONG        lAxisMin;
11219    OPTIONAL    LONG        lAxisMax;
11220    OPTIONAL    HINSTANCE   hInstString;
11221                FILETIME    ftTimeStamp;
11222                DWORD       dwCRC;
11223                WCHAR       tszActionMap[MAX_PATH];
11224} DIACTIONFORMATW, *LPDIACTIONFORMATW;
11225#ifdef UNICODE
11226typedef DIACTIONFORMATW DIACTIONFORMAT;
11227typedef LPDIACTIONFORMATW LPDIACTIONFORMAT;
11228#else
11229typedef DIACTIONFORMATA DIACTIONFORMAT;
11230typedef LPDIACTIONFORMATA LPDIACTIONFORMAT;
11231#endif
11232typedef const DIACTIONFORMATA *LPCDIACTIONFORMATA;
11233typedef const DIACTIONFORMATW *LPCDIACTIONFORMATW;
11234#ifdef UNICODE
11235typedef DIACTIONFORMATW DIACTIONFORMAT;
11236typedef LPCDIACTIONFORMATW LPCDIACTIONFORMAT;
11237#else
11238typedef DIACTIONFORMATA DIACTIONFORMAT;
11239typedef LPCDIACTIONFORMATA LPCDIACTIONFORMAT;
11240#endif
11241typedef const DIACTIONFORMAT *LPCDIACTIONFORMAT;
11242
11243#define DIAFTS_NEWDEVICELOW     0xFFFFFFFF
11244#define DIAFTS_NEWDEVICEHIGH    0xFFFFFFFF
11245#define DIAFTS_UNUSEDDEVICELOW  0x00000000
11246#define DIAFTS_UNUSEDDEVICEHIGH 0x00000000
11247
11248#define DIDBAM_DEFAULT          0x00000000
11249#define DIDBAM_PRESERVE         0x00000001
11250#define DIDBAM_INITIALIZE       0x00000002
11251#define DIDBAM_HWDEFAULTS       0x00000004
11252
11253#define DIDSAM_DEFAULT          0x00000000
11254#define DIDSAM_NOUSER           0x00000001
11255#define DIDSAM_FORCESAVE        0x00000002
11256
11257#define DICD_DEFAULT            0x00000000
11258#define DICD_EDIT               0x00000001
11259
11260#ifndef D3DCOLOR_DEFINED
11261typedef DWORD D3DCOLOR;
11262#define D3DCOLOR_DEFINED
11263#endif
11264
11265typedef struct _DICOLORSET{
11266    DWORD dwSize;
11267    D3DCOLOR cTextFore;
11268    D3DCOLOR cTextHighlight;
11269    D3DCOLOR cCalloutLine;
11270    D3DCOLOR cCalloutHighlight;
11271    D3DCOLOR cBorder;
11272    D3DCOLOR cControlFill;
11273    D3DCOLOR cHighlightFill;
11274    D3DCOLOR cAreaFill;
11275} DICOLORSET, *LPDICOLORSET;
11276typedef const DICOLORSET *LPCDICOLORSET;
11277
11278typedef struct _DICONFIGUREDEVICESPARAMSA{
11279     DWORD             dwSize;
11280     DWORD             dwcUsers;
11281     LPSTR             lptszUserNames;
11282     DWORD             dwcFormats;
11283     LPDIACTIONFORMATA lprgFormats;
11284     HWND              hwnd;
11285     DICOLORSET        dics;
11286     IUnknown FAR *    lpUnkDDSTarget;
11287} DICONFIGUREDEVICESPARAMSA, *LPDICONFIGUREDEVICESPARAMSA;
11288typedef struct _DICONFIGUREDEVICESPARAMSW{
11289     DWORD             dwSize;
11290     DWORD             dwcUsers;
11291     LPWSTR            lptszUserNames;
11292     DWORD             dwcFormats;
11293     LPDIACTIONFORMATW lprgFormats;
11294     HWND              hwnd;
11295     DICOLORSET        dics;
11296     IUnknown FAR *    lpUnkDDSTarget;
11297} DICONFIGUREDEVICESPARAMSW, *LPDICONFIGUREDEVICESPARAMSW;
11298#ifdef UNICODE
11299typedef DICONFIGUREDEVICESPARAMSW DICONFIGUREDEVICESPARAMS;
11300typedef LPDICONFIGUREDEVICESPARAMSW LPDICONFIGUREDEVICESPARAMS;
11301#else
11302typedef DICONFIGUREDEVICESPARAMSA DICONFIGUREDEVICESPARAMS;
11303typedef LPDICONFIGUREDEVICESPARAMSA LPDICONFIGUREDEVICESPARAMS;
11304#endif
11305typedef const DICONFIGUREDEVICESPARAMSA *LPCDICONFIGUREDEVICESPARAMSA;
11306typedef const DICONFIGUREDEVICESPARAMSW *LPCDICONFIGUREDEVICESPARAMSW;
11307#ifdef UNICODE
11308typedef DICONFIGUREDEVICESPARAMSW DICONFIGUREDEVICESPARAMS;
11309typedef LPCDICONFIGUREDEVICESPARAMSW LPCDICONFIGUREDEVICESPARAMS;
11310#else
11311typedef DICONFIGUREDEVICESPARAMSA DICONFIGUREDEVICESPARAMS;
11312typedef LPCDICONFIGUREDEVICESPARAMSA LPCDICONFIGUREDEVICESPARAMS;
11313#endif
11314typedef const DICONFIGUREDEVICESPARAMS *LPCDICONFIGUREDEVICESPARAMS;
11315
11316#define DIDIFT_CONFIGURATION    0x00000001
11317#define DIDIFT_OVERLAY          0x00000002
11318
11319#define DIDAL_CENTERED      0x00000000
11320#define DIDAL_LEFTALIGNED   0x00000001
11321#define DIDAL_RIGHTALIGNED  0x00000002
11322#define DIDAL_MIDDLE        0x00000000
11323#define DIDAL_TOPALIGNED    0x00000004
11324#define DIDAL_BOTTOMALIGNED 0x00000008
11325
11326typedef struct _DIDEVICEIMAGEINFOA {
11327    CHAR        tszImagePath[MAX_PATH];
11328    DWORD       dwFlags;
11329
11330    DWORD       dwViewID;
11331    RECT        rcOverlay;
11332    DWORD       dwObjID;
11333    DWORD       dwcValidPts;
11334    POINT       rgptCalloutLine[5];
11335    RECT        rcCalloutRect;
11336    DWORD       dwTextAlign;
11337} DIDEVICEIMAGEINFOA, *LPDIDEVICEIMAGEINFOA;
11338typedef struct _DIDEVICEIMAGEINFOW {
11339    WCHAR       tszImagePath[MAX_PATH];
11340    DWORD       dwFlags;
11341
11342    DWORD       dwViewID;
11343    RECT        rcOverlay;
11344    DWORD       dwObjID;
11345    DWORD       dwcValidPts;
11346    POINT       rgptCalloutLine[5];
11347    RECT        rcCalloutRect;
11348    DWORD       dwTextAlign;
11349} DIDEVICEIMAGEINFOW, *LPDIDEVICEIMAGEINFOW;
11350#ifdef UNICODE
11351typedef DIDEVICEIMAGEINFOW DIDEVICEIMAGEINFO;
11352typedef LPDIDEVICEIMAGEINFOW LPDIDEVICEIMAGEINFO;
11353#else
11354typedef DIDEVICEIMAGEINFOA DIDEVICEIMAGEINFO;
11355typedef LPDIDEVICEIMAGEINFOA LPDIDEVICEIMAGEINFO;
11356#endif
11357typedef const DIDEVICEIMAGEINFOA *LPCDIDEVICEIMAGEINFOA;
11358typedef const DIDEVICEIMAGEINFOW *LPCDIDEVICEIMAGEINFOW;
11359#ifdef UNICODE
11360typedef DIDEVICEIMAGEINFOW DIDEVICEIMAGEINFO;
11361typedef LPCDIDEVICEIMAGEINFOW LPCDIDEVICEIMAGEINFO;
11362#else
11363typedef DIDEVICEIMAGEINFOA DIDEVICEIMAGEINFO;
11364typedef LPCDIDEVICEIMAGEINFOA LPCDIDEVICEIMAGEINFO;
11365#endif
11366typedef const DIDEVICEIMAGEINFO *LPCDIDEVICEIMAGEINFO;
11367
11368typedef struct _DIDEVICEIMAGEINFOHEADERA {
11369    DWORD       dwSize;
11370    DWORD       dwSizeImageInfo;
11371    DWORD       dwcViews;
11372    DWORD       dwcButtons;
11373    DWORD       dwcAxes;
11374    DWORD       dwcPOVs;
11375    DWORD       dwBufferSize;
11376    DWORD       dwBufferUsed;
11377    LPDIDEVICEIMAGEINFOA lprgImageInfoArray;
11378} DIDEVICEIMAGEINFOHEADERA, *LPDIDEVICEIMAGEINFOHEADERA;
11379typedef struct _DIDEVICEIMAGEINFOHEADERW {
11380    DWORD       dwSize;
11381    DWORD       dwSizeImageInfo;
11382    DWORD       dwcViews;
11383    DWORD       dwcButtons;
11384    DWORD       dwcAxes;
11385    DWORD       dwcPOVs;
11386    DWORD       dwBufferSize;
11387    DWORD       dwBufferUsed;
11388    LPDIDEVICEIMAGEINFOW lprgImageInfoArray;
11389} DIDEVICEIMAGEINFOHEADERW, *LPDIDEVICEIMAGEINFOHEADERW;
11390#ifdef UNICODE
11391typedef DIDEVICEIMAGEINFOHEADERW DIDEVICEIMAGEINFOHEADER;
11392typedef LPDIDEVICEIMAGEINFOHEADERW LPDIDEVICEIMAGEINFOHEADER;
11393#else
11394typedef DIDEVICEIMAGEINFOHEADERA DIDEVICEIMAGEINFOHEADER;
11395typedef LPDIDEVICEIMAGEINFOHEADERA LPDIDEVICEIMAGEINFOHEADER;
11396#endif
11397typedef const DIDEVICEIMAGEINFOHEADERA *LPCDIDEVICEIMAGEINFOHEADERA;
11398typedef const DIDEVICEIMAGEINFOHEADERW *LPCDIDEVICEIMAGEINFOHEADERW;
11399#ifdef UNICODE
11400typedef DIDEVICEIMAGEINFOHEADERW DIDEVICEIMAGEINFOHEADER;
11401typedef LPCDIDEVICEIMAGEINFOHEADERW LPCDIDEVICEIMAGEINFOHEADER;
11402#else
11403typedef DIDEVICEIMAGEINFOHEADERA DIDEVICEIMAGEINFOHEADER;
11404typedef LPCDIDEVICEIMAGEINFOHEADERA LPCDIDEVICEIMAGEINFOHEADER;
11405#endif
11406typedef const DIDEVICEIMAGEINFOHEADER *LPCDIDEVICEIMAGEINFOHEADER;
11407
11408#endif
11409
11410#if(DIRECTINPUT_VERSION >= 0x0500)
11411
11412typedef struct DIDEVICEOBJECTINSTANCE_DX3A {
11413    DWORD   dwSize;
11414    GUID    guidType;
11415    DWORD   dwOfs;
11416    DWORD   dwType;
11417    DWORD   dwFlags;
11418    CHAR    tszName[MAX_PATH];
11419} DIDEVICEOBJECTINSTANCE_DX3A, *LPDIDEVICEOBJECTINSTANCE_DX3A;
11420typedef struct DIDEVICEOBJECTINSTANCE_DX3W {
11421    DWORD   dwSize;
11422    GUID    guidType;
11423    DWORD   dwOfs;
11424    DWORD   dwType;
11425    DWORD   dwFlags;
11426    WCHAR   tszName[MAX_PATH];
11427} DIDEVICEOBJECTINSTANCE_DX3W, *LPDIDEVICEOBJECTINSTANCE_DX3W;
11428#ifdef UNICODE
11429typedef DIDEVICEOBJECTINSTANCE_DX3W DIDEVICEOBJECTINSTANCE_DX3;
11430typedef LPDIDEVICEOBJECTINSTANCE_DX3W LPDIDEVICEOBJECTINSTANCE_DX3;
11431#else
11432typedef DIDEVICEOBJECTINSTANCE_DX3A DIDEVICEOBJECTINSTANCE_DX3;
11433typedef LPDIDEVICEOBJECTINSTANCE_DX3A LPDIDEVICEOBJECTINSTANCE_DX3;
11434#endif
11435typedef const DIDEVICEOBJECTINSTANCE_DX3A *LPCDIDEVICEOBJECTINSTANCE_DX3A;
11436typedef const DIDEVICEOBJECTINSTANCE_DX3W *LPCDIDEVICEOBJECTINSTANCE_DX3W;
11437typedef const DIDEVICEOBJECTINSTANCE_DX3  *LPCDIDEVICEOBJECTINSTANCE_DX3;
11438#endif
11439
11440typedef struct DIDEVICEOBJECTINSTANCEA {
11441    DWORD   dwSize;
11442    GUID    guidType;
11443    DWORD   dwOfs;
11444    DWORD   dwType;
11445    DWORD   dwFlags;
11446    CHAR    tszName[MAX_PATH];
11447#if(DIRECTINPUT_VERSION >= 0x0500)
11448    DWORD   dwFFMaxForce;
11449    DWORD   dwFFForceResolution;
11450    WORD    wCollectionNumber;
11451    WORD    wDesignatorIndex;
11452    WORD    wUsagePage;
11453    WORD    wUsage;
11454    DWORD   dwDimension;
11455    WORD    wExponent;
11456    WORD    wReportId;
11457#endif
11458} DIDEVICEOBJECTINSTANCEA, *LPDIDEVICEOBJECTINSTANCEA;
11459typedef struct DIDEVICEOBJECTINSTANCEW {
11460    DWORD   dwSize;
11461    GUID    guidType;
11462    DWORD   dwOfs;
11463    DWORD   dwType;
11464    DWORD   dwFlags;
11465    WCHAR   tszName[MAX_PATH];
11466#if(DIRECTINPUT_VERSION >= 0x0500)
11467    DWORD   dwFFMaxForce;
11468    DWORD   dwFFForceResolution;
11469    WORD    wCollectionNumber;
11470    WORD    wDesignatorIndex;
11471    WORD    wUsagePage;
11472    WORD    wUsage;
11473    DWORD   dwDimension;
11474    WORD    wExponent;
11475    WORD    wReportId;
11476#endif
11477} DIDEVICEOBJECTINSTANCEW, *LPDIDEVICEOBJECTINSTANCEW;
11478#ifdef UNICODE
11479typedef DIDEVICEOBJECTINSTANCEW DIDEVICEOBJECTINSTANCE;
11480typedef LPDIDEVICEOBJECTINSTANCEW LPDIDEVICEOBJECTINSTANCE;
11481#else
11482typedef DIDEVICEOBJECTINSTANCEA DIDEVICEOBJECTINSTANCE;
11483typedef LPDIDEVICEOBJECTINSTANCEA LPDIDEVICEOBJECTINSTANCE;
11484#endif
11485typedef const DIDEVICEOBJECTINSTANCEA *LPCDIDEVICEOBJECTINSTANCEA;
11486typedef const DIDEVICEOBJECTINSTANCEW *LPCDIDEVICEOBJECTINSTANCEW;
11487typedef const DIDEVICEOBJECTINSTANCE  *LPCDIDEVICEOBJECTINSTANCE;
11488
11489typedef BOOL (FAR PASCAL * LPDIENUMDEVICEOBJECTSCALLBACKA)(LPCDIDEVICEOBJECTINSTANCEA, LPVOID);
11490typedef BOOL (FAR PASCAL * LPDIENUMDEVICEOBJECTSCALLBACKW)(LPCDIDEVICEOBJECTINSTANCEW, LPVOID);
11491#ifdef UNICODE
11492#define LPDIENUMDEVICEOBJECTSCALLBACK  LPDIENUMDEVICEOBJECTSCALLBACKW
11493#else
11494#define LPDIENUMDEVICEOBJECTSCALLBACK  LPDIENUMDEVICEOBJECTSCALLBACKA
11495#endif
11496
11497#if(DIRECTINPUT_VERSION >= 0x0500)
11498#define DIDOI_FFACTUATOR        0x00000001
11499#define DIDOI_FFEFFECTTRIGGER   0x00000002
11500#define DIDOI_POLLED            0x00008000
11501#define DIDOI_ASPECTPOSITION    0x00000100
11502#define DIDOI_ASPECTVELOCITY    0x00000200
11503#define DIDOI_ASPECTACCEL       0x00000300
11504#define DIDOI_ASPECTFORCE       0x00000400
11505#define DIDOI_ASPECTMASK        0x00000F00
11506#endif
11507#if(DIRECTINPUT_VERSION >= 0x050a)
11508#define DIDOI_GUIDISUSAGE       0x00010000
11509#endif
11510
11511typedef struct DIPROPHEADER {
11512    DWORD   dwSize;
11513    DWORD   dwHeaderSize;
11514    DWORD   dwObj;
11515    DWORD   dwHow;
11516} DIPROPHEADER, *LPDIPROPHEADER;
11517typedef const DIPROPHEADER *LPCDIPROPHEADER;
11518
11519#define DIPH_DEVICE             0
11520#define DIPH_BYOFFSET           1
11521#define DIPH_BYID               2
11522#if(DIRECTINPUT_VERSION >= 0x050a)
11523#define DIPH_BYUSAGE            3
11524
11525#define DIMAKEUSAGEDWORD(UsagePage, Usage) \
11526                                (DWORD)MAKELONG(Usage, UsagePage)
11527#endif
11528
11529typedef struct DIPROPDWORD {
11530    DIPROPHEADER diph;
11531    DWORD   dwData;
11532} DIPROPDWORD, *LPDIPROPDWORD;
11533typedef const DIPROPDWORD *LPCDIPROPDWORD;
11534
11535#if(DIRECTINPUT_VERSION >= 0x0800)
11536typedef struct DIPROPPOINTER {
11537    DIPROPHEADER diph;
11538    UINT_PTR uData;
11539} DIPROPPOINTER, *LPDIPROPPOINTER;
11540typedef const DIPROPPOINTER *LPCDIPROPPOINTER;
11541#endif
11542
11543typedef struct DIPROPRANGE {
11544    DIPROPHEADER diph;
11545    LONG    lMin;
11546    LONG    lMax;
11547} DIPROPRANGE, *LPDIPROPRANGE;
11548typedef const DIPROPRANGE *LPCDIPROPRANGE;
11549
11550#define DIPROPRANGE_NOMIN       ((LONG)0x80000000)
11551#define DIPROPRANGE_NOMAX       ((LONG)0x7FFFFFFF)
11552
11553#if(DIRECTINPUT_VERSION >= 0x050a)
11554typedef struct DIPROPCAL {
11555    DIPROPHEADER diph;
11556    LONG    lMin;
11557    LONG    lCenter;
11558    LONG    lMax;
11559} DIPROPCAL, *LPDIPROPCAL;
11560typedef const DIPROPCAL *LPCDIPROPCAL;
11561
11562typedef struct DIPROPGUIDANDPATH {
11563    DIPROPHEADER diph;
11564    GUID    guidClass;
11565    WCHAR   wszPath[MAX_PATH];
11566} DIPROPGUIDANDPATH, *LPDIPROPGUIDANDPATH;
11567typedef const DIPROPGUIDANDPATH *LPCDIPROPGUIDANDPATH;
11568
11569typedef struct DIPROPSTRING {
11570    DIPROPHEADER diph;
11571    WCHAR   wsz[MAX_PATH];
11572} DIPROPSTRING, *LPDIPROPSTRING;
11573typedef const DIPROPSTRING *LPCDIPROPSTRING;
11574
11575#endif
11576
11577#if(DIRECTINPUT_VERSION >= 0x0800)
11578#define MAXCPOINTSNUM          8
11579
11580typedef struct _CPOINT
11581{
11582    LONG  lP;
11583    DWORD dwLog;
11584} CPOINT, *PCPOINT;
11585
11586typedef struct DIPROPCPOINTS {
11587    DIPROPHEADER diph;
11588    DWORD  dwCPointsNum;
11589    CPOINT cp[MAXCPOINTSNUM];
11590} DIPROPCPOINTS, *LPDIPROPCPOINTS;
11591typedef const DIPROPCPOINTS *LPCDIPROPCPOINTS;
11592#endif
11593
11594#ifdef __cplusplus
11595#define MAKEDIPROP(prop)    (*(const GUID *)(prop))
11596#else
11597#define MAKEDIPROP(prop)    ((REFGUID)(prop))
11598#endif
11599
11600#define DIPROP_BUFFERSIZE       MAKEDIPROP(1)
11601
11602#define DIPROP_AXISMODE         MAKEDIPROP(2)
11603
11604#define DIPROPAXISMODE_ABS      0
11605#define DIPROPAXISMODE_REL      1
11606
11607#define DIPROP_GRANULARITY      MAKEDIPROP(3)
11608
11609#define DIPROP_RANGE            MAKEDIPROP(4)
11610
11611#define DIPROP_DEADZONE         MAKEDIPROP(5)
11612
11613#define DIPROP_SATURATION       MAKEDIPROP(6)
11614
11615#define DIPROP_FFGAIN           MAKEDIPROP(7)
11616
11617#define DIPROP_FFLOAD           MAKEDIPROP(8)
11618
11619#define DIPROP_AUTOCENTER       MAKEDIPROP(9)
11620
11621#define DIPROPAUTOCENTER_OFF    0
11622#define DIPROPAUTOCENTER_ON     1
11623
11624#define DIPROP_CALIBRATIONMODE  MAKEDIPROP(10)
11625
11626#define DIPROPCALIBRATIONMODE_COOKED    0
11627#define DIPROPCALIBRATIONMODE_RAW       1
11628
11629#if(DIRECTINPUT_VERSION >= 0x050a)
11630#define DIPROP_CALIBRATION      MAKEDIPROP(11)
11631
11632#define DIPROP_GUIDANDPATH      MAKEDIPROP(12)
11633
11634#define DIPROP_INSTANCENAME     MAKEDIPROP(13)
11635
11636#define DIPROP_PRODUCTNAME      MAKEDIPROP(14)
11637#endif
11638
11639#if(DIRECTINPUT_VERSION >= 0x05b2)
11640#define DIPROP_JOYSTICKID       MAKEDIPROP(15)
11641
11642#define DIPROP_GETPORTDISPLAYNAME       MAKEDIPROP(16)
11643
11644#endif
11645
11646#if(DIRECTINPUT_VERSION >= 0x0700)
11647#define DIPROP_PHYSICALRANGE            MAKEDIPROP(18)
11648
11649#define DIPROP_LOGICALRANGE             MAKEDIPROP(19)
11650#endif
11651
11652#if(DIRECTINPUT_VERSION >= 0x0800)
11653#define DIPROP_KEYNAME                     MAKEDIPROP(20)
11654
11655#define DIPROP_CPOINTS                 MAKEDIPROP(21)
11656
11657#define DIPROP_APPDATA       MAKEDIPROP(22)
11658
11659#define DIPROP_SCANCODE      MAKEDIPROP(23)
11660
11661#define DIPROP_VIDPID           MAKEDIPROP(24)
11662
11663#define DIPROP_USERNAME         MAKEDIPROP(25)
11664
11665#define DIPROP_TYPENAME         MAKEDIPROP(26)
11666#endif
11667
11668typedef struct DIDEVICEOBJECTDATA_DX3 {
11669    DWORD       dwOfs;
11670    DWORD       dwData;
11671    DWORD       dwTimeStamp;
11672    DWORD       dwSequence;
11673} DIDEVICEOBJECTDATA_DX3, *LPDIDEVICEOBJECTDATA_DX3;
11674typedef const DIDEVICEOBJECTDATA_DX3 *LPCDIDEVICEOBJECTDATA_DX;
11675
11676typedef struct DIDEVICEOBJECTDATA {
11677    DWORD       dwOfs;
11678    DWORD       dwData;
11679    DWORD       dwTimeStamp;
11680    DWORD       dwSequence;
11681#if(DIRECTINPUT_VERSION >= 0x0800)
11682    UINT_PTR    uAppData;
11683#endif
11684} DIDEVICEOBJECTDATA, *LPDIDEVICEOBJECTDATA;
11685typedef const DIDEVICEOBJECTDATA *LPCDIDEVICEOBJECTDATA;
11686
11687#define DIGDD_PEEK          0x00000001
11688
11689#define DISEQUENCE_COMPARE(dwSequence1, cmp, dwSequence2) \
11690                        ((int)((dwSequence1) - (dwSequence2)) cmp 0)
11691#define DISCL_EXCLUSIVE     0x00000001
11692#define DISCL_NONEXCLUSIVE  0x00000002
11693#define DISCL_FOREGROUND    0x00000004
11694#define DISCL_BACKGROUND    0x00000008
11695#define DISCL_NOWINKEY      0x00000010
11696
11697#if(DIRECTINPUT_VERSION >= 0x0500)
11698
11699typedef struct DIDEVICEINSTANCE_DX3A {
11700    DWORD   dwSize;
11701    GUID    guidInstance;
11702    GUID    guidProduct;
11703    DWORD   dwDevType;
11704    CHAR    tszInstanceName[MAX_PATH];
11705    CHAR    tszProductName[MAX_PATH];
11706} DIDEVICEINSTANCE_DX3A, *LPDIDEVICEINSTANCE_DX3A;
11707typedef struct DIDEVICEINSTANCE_DX3W {
11708    DWORD   dwSize;
11709    GUID    guidInstance;
11710    GUID    guidProduct;
11711    DWORD   dwDevType;
11712    WCHAR   tszInstanceName[MAX_PATH];
11713    WCHAR   tszProductName[MAX_PATH];
11714} DIDEVICEINSTANCE_DX3W, *LPDIDEVICEINSTANCE_DX3W;
11715#ifdef UNICODE
11716typedef DIDEVICEINSTANCE_DX3W DIDEVICEINSTANCE_DX3;
11717typedef LPDIDEVICEINSTANCE_DX3W LPDIDEVICEINSTANCE_DX3;
11718#else
11719typedef DIDEVICEINSTANCE_DX3A DIDEVICEINSTANCE_DX3;
11720typedef LPDIDEVICEINSTANCE_DX3A LPDIDEVICEINSTANCE_DX3;
11721#endif
11722typedef const DIDEVICEINSTANCE_DX3A *LPCDIDEVICEINSTANCE_DX3A;
11723typedef const DIDEVICEINSTANCE_DX3W *LPCDIDEVICEINSTANCE_DX3W;
11724typedef const DIDEVICEINSTANCE_DX3  *LPCDIDEVICEINSTANCE_DX3;
11725#endif
11726
11727typedef struct DIDEVICEINSTANCEA {
11728    DWORD   dwSize;
11729    GUID    guidInstance;
11730    GUID    guidProduct;
11731    DWORD   dwDevType;
11732    CHAR    tszInstanceName[MAX_PATH];
11733    CHAR    tszProductName[MAX_PATH];
11734#if(DIRECTINPUT_VERSION >= 0x0500)
11735    GUID    guidFFDriver;
11736    WORD    wUsagePage;
11737    WORD    wUsage;
11738#endif
11739} DIDEVICEINSTANCEA, *LPDIDEVICEINSTANCEA;
11740typedef struct DIDEVICEINSTANCEW {
11741    DWORD   dwSize;
11742    GUID    guidInstance;
11743    GUID    guidProduct;
11744    DWORD   dwDevType;
11745    WCHAR   tszInstanceName[MAX_PATH];
11746    WCHAR   tszProductName[MAX_PATH];
11747#if(DIRECTINPUT_VERSION >= 0x0500)
11748    GUID    guidFFDriver;
11749    WORD    wUsagePage;
11750    WORD    wUsage;
11751#endif
11752} DIDEVICEINSTANCEW, *LPDIDEVICEINSTANCEW;
11753#ifdef UNICODE
11754typedef DIDEVICEINSTANCEW DIDEVICEINSTANCE;
11755typedef LPDIDEVICEINSTANCEW LPDIDEVICEINSTANCE;
11756#else
11757typedef DIDEVICEINSTANCEA DIDEVICEINSTANCE;
11758typedef LPDIDEVICEINSTANCEA LPDIDEVICEINSTANCE;
11759#endif
11760
11761typedef const DIDEVICEINSTANCEA *LPCDIDEVICEINSTANCEA;
11762typedef const DIDEVICEINSTANCEW *LPCDIDEVICEINSTANCEW;
11763#ifdef UNICODE
11764typedef DIDEVICEINSTANCEW DIDEVICEINSTANCE;
11765typedef LPCDIDEVICEINSTANCEW LPCDIDEVICEINSTANCE;
11766#else
11767typedef DIDEVICEINSTANCEA DIDEVICEINSTANCE;
11768typedef LPCDIDEVICEINSTANCEA LPCDIDEVICEINSTANCE;
11769#endif
11770typedef const DIDEVICEINSTANCE  *LPCDIDEVICEINSTANCE;
11771
11772#undef INTERFACE
11773#define INTERFACE IDirectInputDeviceW
11774
11775DECLARE_INTERFACE_(IDirectInputDeviceW, IUnknown)
11776{
11777
11778    STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
11779    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
11780    STDMETHOD_(ULONG,Release)(THIS) PURE;
11781
11782    STDMETHOD(GetCapabilities)(THIS_ LPDIDEVCAPS) PURE;
11783    STDMETHOD(EnumObjects)(THIS_ LPDIENUMDEVICEOBJECTSCALLBACKW,LPVOID,DWORD) PURE;
11784    STDMETHOD(GetProperty)(THIS_ REFGUID,LPDIPROPHEADER) PURE;
11785    STDMETHOD(SetProperty)(THIS_ REFGUID,LPCDIPROPHEADER) PURE;
11786    STDMETHOD(Acquire)(THIS) PURE;
11787    STDMETHOD(Unacquire)(THIS) PURE;
11788    STDMETHOD(GetDeviceState)(THIS_ DWORD,LPVOID) PURE;
11789    STDMETHOD(GetDeviceData)(THIS_ DWORD,LPDIDEVICEOBJECTDATA,LPDWORD,DWORD) PURE;
11790    STDMETHOD(SetDataFormat)(THIS_ LPCDIDATAFORMAT) PURE;
11791    STDMETHOD(SetEventNotification)(THIS_ HANDLE) PURE;
11792    STDMETHOD(SetCooperativeLevel)(THIS_ HWND,DWORD) PURE;
11793    STDMETHOD(GetObjectInfo)(THIS_ LPDIDEVICEOBJECTINSTANCEW,DWORD,DWORD) PURE;
11794    STDMETHOD(GetDeviceInfo)(THIS_ LPDIDEVICEINSTANCEW) PURE;
11795    STDMETHOD(RunControlPanel)(THIS_ HWND,DWORD) PURE;
11796    STDMETHOD(Initialize)(THIS_ HINSTANCE,DWORD,REFGUID) PURE;
11797};
11798
11799typedef struct IDirectInputDeviceW *LPDIRECTINPUTDEVICEW;
11800
11801#undef INTERFACE
11802#define INTERFACE IDirectInputDeviceA
11803
11804DECLARE_INTERFACE_(IDirectInputDeviceA, IUnknown)
11805{
11806
11807    STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
11808    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
11809    STDMETHOD_(ULONG,Release)(THIS) PURE;
11810
11811    STDMETHOD(GetCapabilities)(THIS_ LPDIDEVCAPS) PURE;
11812    STDMETHOD(EnumObjects)(THIS_ LPDIENUMDEVICEOBJECTSCALLBACKA,LPVOID,DWORD) PURE;
11813    STDMETHOD(GetProperty)(THIS_ REFGUID,LPDIPROPHEADER) PURE;
11814    STDMETHOD(SetProperty)(THIS_ REFGUID,LPCDIPROPHEADER) PURE;
11815    STDMETHOD(Acquire)(THIS) PURE;
11816    STDMETHOD(Unacquire)(THIS) PURE;
11817    STDMETHOD(GetDeviceState)(THIS_ DWORD,LPVOID) PURE;
11818    STDMETHOD(GetDeviceData)(THIS_ DWORD,LPDIDEVICEOBJECTDATA,LPDWORD,DWORD) PURE;
11819    STDMETHOD(SetDataFormat)(THIS_ LPCDIDATAFORMAT) PURE;
11820    STDMETHOD(SetEventNotification)(THIS_ HANDLE) PURE;
11821    STDMETHOD(SetCooperativeLevel)(THIS_ HWND,DWORD) PURE;
11822    STDMETHOD(GetObjectInfo)(THIS_ LPDIDEVICEOBJECTINSTANCEA,DWORD,DWORD) PURE;
11823    STDMETHOD(GetDeviceInfo)(THIS_ LPDIDEVICEINSTANCEA) PURE;
11824    STDMETHOD(RunControlPanel)(THIS_ HWND,DWORD) PURE;
11825    STDMETHOD(Initialize)(THIS_ HINSTANCE,DWORD,REFGUID) PURE;
11826};
11827
11828typedef struct IDirectInputDeviceA *LPDIRECTINPUTDEVICEA;
11829
11830#ifdef UNICODE
11831#define IID_IDirectInputDevice IID_IDirectInputDeviceW
11832#define IDirectInputDevice IDirectInputDeviceW
11833#define IDirectInputDeviceVtbl IDirectInputDeviceWVtbl
11834#else
11835#define IID_IDirectInputDevice IID_IDirectInputDeviceA
11836#define IDirectInputDevice IDirectInputDeviceA
11837#define IDirectInputDeviceVtbl IDirectInputDeviceAVtbl
11838#endif
11839typedef struct IDirectInputDevice *LPDIRECTINPUTDEVICE;
11840
11841#if !defined(__cplusplus) || defined(CINTERFACE)
11842#define IDirectInputDevice_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
11843#define IDirectInputDevice_AddRef(p) (p)->lpVtbl->AddRef(p)
11844#define IDirectInputDevice_Release(p) (p)->lpVtbl->Release(p)
11845#define IDirectInputDevice_GetCapabilities(p,a) (p)->lpVtbl->GetCapabilities(p,a)
11846#define IDirectInputDevice_EnumObjects(p,a,b,c) (p)->lpVtbl->EnumObjects(p,a,b,c)
11847#define IDirectInputDevice_GetProperty(p,a,b) (p)->lpVtbl->GetProperty(p,a,b)
11848#define IDirectInputDevice_SetProperty(p,a,b) (p)->lpVtbl->SetProperty(p,a,b)
11849#define IDirectInputDevice_Acquire(p) (p)->lpVtbl->Acquire(p)
11850#define IDirectInputDevice_Unacquire(p) (p)->lpVtbl->Unacquire(p)
11851#define IDirectInputDevice_GetDeviceState(p,a,b) (p)->lpVtbl->GetDeviceState(p,a,b)
11852#define IDirectInputDevice_GetDeviceData(p,a,b,c,d) (p)->lpVtbl->GetDeviceData(p,a,b,c,d)
11853#define IDirectInputDevice_SetDataFormat(p,a) (p)->lpVtbl->SetDataFormat(p,a)
11854#define IDirectInputDevice_SetEventNotification(p,a) (p)->lpVtbl->SetEventNotification(p,a)
11855#define IDirectInputDevice_SetCooperativeLevel(p,a,b) (p)->lpVtbl->SetCooperativeLevel(p,a,b)
11856#define IDirectInputDevice_GetObjectInfo(p,a,b,c) (p)->lpVtbl->GetObjectInfo(p,a,b,c)
11857#define IDirectInputDevice_GetDeviceInfo(p,a) (p)->lpVtbl->GetDeviceInfo(p,a)
11858#define IDirectInputDevice_RunControlPanel(p,a,b) (p)->lpVtbl->RunControlPanel(p,a,b)
11859#define IDirectInputDevice_Initialize(p,a,b,c) (p)->lpVtbl->Initialize(p,a,b,c)
11860#else
11861#define IDirectInputDevice_QueryInterface(p,a,b) (p)->QueryInterface(a,b)
11862#define IDirectInputDevice_AddRef(p) (p)->AddRef()
11863#define IDirectInputDevice_Release(p) (p)->Release()
11864#define IDirectInputDevice_GetCapabilities(p,a) (p)->GetCapabilities(a)
11865#define IDirectInputDevice_EnumObjects(p,a,b,c) (p)->EnumObjects(a,b,c)
11866#define IDirectInputDevice_GetProperty(p,a,b) (p)->GetProperty(a,b)
11867#define IDirectInputDevice_SetProperty(p,a,b) (p)->SetProperty(a,b)
11868#define IDirectInputDevice_Acquire(p) (p)->Acquire()
11869#define IDirectInputDevice_Unacquire(p) (p)->Unacquire()
11870#define IDirectInputDevice_GetDeviceState(p,a,b) (p)->GetDeviceState(a,b)
11871#define IDirectInputDevice_GetDeviceData(p,a,b,c,d) (p)->GetDeviceData(a,b,c,d)
11872#define IDirectInputDevice_SetDataFormat(p,a) (p)->SetDataFormat(a)
11873#define IDirectInputDevice_SetEventNotification(p,a) (p)->SetEventNotification(a)
11874#define IDirectInputDevice_SetCooperativeLevel(p,a,b) (p)->SetCooperativeLevel(a,b)
11875#define IDirectInputDevice_GetObjectInfo(p,a,b,c) (p)->GetObjectInfo(a,b,c)
11876#define IDirectInputDevice_GetDeviceInfo(p,a) (p)->GetDeviceInfo(a)
11877#define IDirectInputDevice_RunControlPanel(p,a,b) (p)->RunControlPanel(a,b)
11878#define IDirectInputDevice_Initialize(p,a,b,c) (p)->Initialize(a,b,c)
11879#endif
11880
11881#endif
11882
11883#if(DIRECTINPUT_VERSION >= 0x0500)
11884
11885#define DISFFC_RESET            0x00000001
11886#define DISFFC_STOPALL          0x00000002
11887#define DISFFC_PAUSE            0x00000004
11888#define DISFFC_CONTINUE         0x00000008
11889#define DISFFC_SETACTUATORSON   0x00000010
11890#define DISFFC_SETACTUATORSOFF  0x00000020
11891
11892#define DIGFFS_EMPTY            0x00000001
11893#define DIGFFS_STOPPED          0x00000002
11894#define DIGFFS_PAUSED           0x00000004
11895#define DIGFFS_ACTUATORSON      0x00000010
11896#define DIGFFS_ACTUATORSOFF     0x00000020
11897#define DIGFFS_POWERON          0x00000040
11898#define DIGFFS_POWEROFF         0x00000080
11899#define DIGFFS_SAFETYSWITCHON   0x00000100
11900#define DIGFFS_SAFETYSWITCHOFF  0x00000200
11901#define DIGFFS_USERFFSWITCHON   0x00000400
11902#define DIGFFS_USERFFSWITCHOFF  0x00000800
11903#define DIGFFS_DEVICELOST       0x80000000
11904
11905#ifndef DIJ_RINGZERO
11906
11907typedef struct DIEFFECTINFOA {
11908    DWORD   dwSize;
11909    GUID    guid;
11910    DWORD   dwEffType;
11911    DWORD   dwStaticParams;
11912    DWORD   dwDynamicParams;
11913    CHAR    tszName[MAX_PATH];
11914} DIEFFECTINFOA, *LPDIEFFECTINFOA;
11915typedef struct DIEFFECTINFOW {
11916    DWORD   dwSize;
11917    GUID    guid;
11918    DWORD   dwEffType;
11919    DWORD   dwStaticParams;
11920    DWORD   dwDynamicParams;
11921    WCHAR   tszName[MAX_PATH];
11922} DIEFFECTINFOW, *LPDIEFFECTINFOW;
11923#ifdef UNICODE
11924typedef DIEFFECTINFOW DIEFFECTINFO;
11925typedef LPDIEFFECTINFOW LPDIEFFECTINFO;
11926#else
11927typedef DIEFFECTINFOA DIEFFECTINFO;
11928typedef LPDIEFFECTINFOA LPDIEFFECTINFO;
11929#endif
11930typedef const DIEFFECTINFOA *LPCDIEFFECTINFOA;
11931typedef const DIEFFECTINFOW *LPCDIEFFECTINFOW;
11932typedef const DIEFFECTINFO  *LPCDIEFFECTINFO;
11933
11934#define DISDD_CONTINUE          0x00000001
11935
11936typedef BOOL (FAR PASCAL * LPDIENUMEFFECTSCALLBACKA)(LPCDIEFFECTINFOA, LPVOID);
11937typedef BOOL (FAR PASCAL * LPDIENUMEFFECTSCALLBACKW)(LPCDIEFFECTINFOW, LPVOID);
11938#ifdef UNICODE
11939#define LPDIENUMEFFECTSCALLBACK  LPDIENUMEFFECTSCALLBACKW
11940#else
11941#define LPDIENUMEFFECTSCALLBACK  LPDIENUMEFFECTSCALLBACKA
11942#endif
11943typedef BOOL (FAR PASCAL * LPDIENUMCREATEDEFFECTOBJECTSCALLBACK)(LPDIRECTINPUTEFFECT, LPVOID);
11944
11945#undef INTERFACE
11946#define INTERFACE IDirectInputDevice2W
11947
11948DECLARE_INTERFACE_(IDirectInputDevice2W, IDirectInputDeviceW)
11949{
11950
11951    STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
11952    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
11953    STDMETHOD_(ULONG,Release)(THIS) PURE;
11954
11955    STDMETHOD(GetCapabilities)(THIS_ LPDIDEVCAPS) PURE;
11956    STDMETHOD(EnumObjects)(THIS_ LPDIENUMDEVICEOBJECTSCALLBACKW,LPVOID,DWORD) PURE;
11957    STDMETHOD(GetProperty)(THIS_ REFGUID,LPDIPROPHEADER) PURE;
11958    STDMETHOD(SetProperty)(THIS_ REFGUID,LPCDIPROPHEADER) PURE;
11959    STDMETHOD(Acquire)(THIS) PURE;
11960    STDMETHOD(Unacquire)(THIS) PURE;
11961    STDMETHOD(GetDeviceState)(THIS_ DWORD,LPVOID) PURE;
11962    STDMETHOD(GetDeviceData)(THIS_ DWORD,LPDIDEVICEOBJECTDATA,LPDWORD,DWORD) PURE;
11963    STDMETHOD(SetDataFormat)(THIS_ LPCDIDATAFORMAT) PURE;
11964    STDMETHOD(SetEventNotification)(THIS_ HANDLE) PURE;
11965    STDMETHOD(SetCooperativeLevel)(THIS_ HWND,DWORD) PURE;
11966    STDMETHOD(GetObjectInfo)(THIS_ LPDIDEVICEOBJECTINSTANCEW,DWORD,DWORD) PURE;
11967    STDMETHOD(GetDeviceInfo)(THIS_ LPDIDEVICEINSTANCEW) PURE;
11968    STDMETHOD(RunControlPanel)(THIS_ HWND,DWORD) PURE;
11969    STDMETHOD(Initialize)(THIS_ HINSTANCE,DWORD,REFGUID) PURE;
11970
11971    STDMETHOD(CreateEffect)(THIS_ REFGUID,LPCDIEFFECT,LPDIRECTINPUTEFFECT *,LPUNKNOWN) PURE;
11972    STDMETHOD(EnumEffects)(THIS_ LPDIENUMEFFECTSCALLBACKW,LPVOID,DWORD) PURE;
11973    STDMETHOD(GetEffectInfo)(THIS_ LPDIEFFECTINFOW,REFGUID) PURE;
11974    STDMETHOD(GetForceFeedbackState)(THIS_ LPDWORD) PURE;
11975    STDMETHOD(SendForceFeedbackCommand)(THIS_ DWORD) PURE;
11976    STDMETHOD(EnumCreatedEffectObjects)(THIS_ LPDIENUMCREATEDEFFECTOBJECTSCALLBACK,LPVOID,DWORD) PURE;
11977    STDMETHOD(Escape)(THIS_ LPDIEFFESCAPE) PURE;
11978    STDMETHOD(Poll)(THIS) PURE;
11979    STDMETHOD(SendDeviceData)(THIS_ DWORD,LPCDIDEVICEOBJECTDATA,LPDWORD,DWORD) PURE;
11980};
11981
11982typedef struct IDirectInputDevice2W *LPDIRECTINPUTDEVICE2W;
11983
11984#undef INTERFACE
11985#define INTERFACE IDirectInputDevice2A
11986
11987DECLARE_INTERFACE_(IDirectInputDevice2A, IDirectInputDeviceA)
11988{
11989
11990    STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
11991    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
11992    STDMETHOD_(ULONG,Release)(THIS) PURE;
11993
11994    STDMETHOD(GetCapabilities)(THIS_ LPDIDEVCAPS) PURE;
11995    STDMETHOD(EnumObjects)(THIS_ LPDIENUMDEVICEOBJECTSCALLBACKA,LPVOID,DWORD) PURE;
11996    STDMETHOD(GetProperty)(THIS_ REFGUID,LPDIPROPHEADER) PURE;
11997    STDMETHOD(SetProperty)(THIS_ REFGUID,LPCDIPROPHEADER) PURE;
11998    STDMETHOD(Acquire)(THIS) PURE;
11999    STDMETHOD(Unacquire)(THIS) PURE;
12000    STDMETHOD(GetDeviceState)(THIS_ DWORD,LPVOID) PURE;
12001    STDMETHOD(GetDeviceData)(THIS_ DWORD,LPDIDEVICEOBJECTDATA,LPDWORD,DWORD) PURE;
12002    STDMETHOD(SetDataFormat)(THIS_ LPCDIDATAFORMAT) PURE;
12003    STDMETHOD(SetEventNotification)(THIS_ HANDLE) PURE;
12004    STDMETHOD(SetCooperativeLevel)(THIS_ HWND,DWORD) PURE;
12005    STDMETHOD(GetObjectInfo)(THIS_ LPDIDEVICEOBJECTINSTANCEA,DWORD,DWORD) PURE;
12006    STDMETHOD(GetDeviceInfo)(THIS_ LPDIDEVICEINSTANCEA) PURE;
12007    STDMETHOD(RunControlPanel)(THIS_ HWND,DWORD) PURE;
12008    STDMETHOD(Initialize)(THIS_ HINSTANCE,DWORD,REFGUID) PURE;
12009
12010    STDMETHOD(CreateEffect)(THIS_ REFGUID,LPCDIEFFECT,LPDIRECTINPUTEFFECT *,LPUNKNOWN) PURE;
12011    STDMETHOD(EnumEffects)(THIS_ LPDIENUMEFFECTSCALLBACKA,LPVOID,DWORD) PURE;
12012    STDMETHOD(GetEffectInfo)(THIS_ LPDIEFFECTINFOA,REFGUID) PURE;
12013    STDMETHOD(GetForceFeedbackState)(THIS_ LPDWORD) PURE;
12014    STDMETHOD(SendForceFeedbackCommand)(THIS_ DWORD) PURE;
12015    STDMETHOD(EnumCreatedEffectObjects)(THIS_ LPDIENUMCREATEDEFFECTOBJECTSCALLBACK,LPVOID,DWORD) PURE;
12016    STDMETHOD(Escape)(THIS_ LPDIEFFESCAPE) PURE;
12017    STDMETHOD(Poll)(THIS) PURE;
12018    STDMETHOD(SendDeviceData)(THIS_ DWORD,LPCDIDEVICEOBJECTDATA,LPDWORD,DWORD) PURE;
12019};
12020
12021typedef struct IDirectInputDevice2A *LPDIRECTINPUTDEVICE2A;
12022
12023#ifdef UNICODE
12024#define IID_IDirectInputDevice2 IID_IDirectInputDevice2W
12025#define IDirectInputDevice2 IDirectInputDevice2W
12026#define IDirectInputDevice2Vtbl IDirectInputDevice2WVtbl
12027#else
12028#define IID_IDirectInputDevice2 IID_IDirectInputDevice2A
12029#define IDirectInputDevice2 IDirectInputDevice2A
12030#define IDirectInputDevice2Vtbl IDirectInputDevice2AVtbl
12031#endif
12032typedef struct IDirectInputDevice2 *LPDIRECTINPUTDEVICE2;
12033
12034#if !defined(__cplusplus) || defined(CINTERFACE)
12035#define IDirectInputDevice2_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
12036#define IDirectInputDevice2_AddRef(p) (p)->lpVtbl->AddRef(p)
12037#define IDirectInputDevice2_Release(p) (p)->lpVtbl->Release(p)
12038#define IDirectInputDevice2_GetCapabilities(p,a) (p)->lpVtbl->GetCapabilities(p,a)
12039#define IDirectInputDevice2_EnumObjects(p,a,b,c) (p)->lpVtbl->EnumObjects(p,a,b,c)
12040#define IDirectInputDevice2_GetProperty(p,a,b) (p)->lpVtbl->GetProperty(p,a,b)
12041#define IDirectInputDevice2_SetProperty(p,a,b) (p)->lpVtbl->SetProperty(p,a,b)
12042#define IDirectInputDevice2_Acquire(p) (p)->lpVtbl->Acquire(p)
12043#define IDirectInputDevice2_Unacquire(p) (p)->lpVtbl->Unacquire(p)
12044#define IDirectInputDevice2_GetDeviceState(p,a,b) (p)->lpVtbl->GetDeviceState(p,a,b)
12045#define IDirectInputDevice2_GetDeviceData(p,a,b,c,d) (p)->lpVtbl->GetDeviceData(p,a,b,c,d)
12046#define IDirectInputDevice2_SetDataFormat(p,a) (p)->lpVtbl->SetDataFormat(p,a)
12047#define IDirectInputDevice2_SetEventNotification(p,a) (p)->lpVtbl->SetEventNotification(p,a)
12048#define IDirectInputDevice2_SetCooperativeLevel(p,a,b) (p)->lpVtbl->SetCooperativeLevel(p,a,b)
12049#define IDirectInputDevice2_GetObjectInfo(p,a,b,c) (p)->lpVtbl->GetObjectInfo(p,a,b,c)
12050#define IDirectInputDevice2_GetDeviceInfo(p,a) (p)->lpVtbl->GetDeviceInfo(p,a)
12051#define IDirectInputDevice2_RunControlPanel(p,a,b) (p)->lpVtbl->RunControlPanel(p,a,b)
12052#define IDirectInputDevice2_Initialize(p,a,b,c) (p)->lpVtbl->Initialize(p,a,b,c)
12053#define IDirectInputDevice2_CreateEffect(p,a,b,c,d) (p)->lpVtbl->CreateEffect(p,a,b,c,d)
12054#define IDirectInputDevice2_EnumEffects(p,a,b,c) (p)->lpVtbl->EnumEffects(p,a,b,c)
12055#define IDirectInputDevice2_GetEffectInfo(p,a,b) (p)->lpVtbl->GetEffectInfo(p,a,b)
12056#define IDirectInputDevice2_GetForceFeedbackState(p,a) (p)->lpVtbl->GetForceFeedbackState(p,a)
12057#define IDirectInputDevice2_SendForceFeedbackCommand(p,a) (p)->lpVtbl->SendForceFeedbackCommand(p,a)
12058#define IDirectInputDevice2_EnumCreatedEffectObjects(p,a,b,c) (p)->lpVtbl->EnumCreatedEffectObjects(p,a,b,c)
12059#define IDirectInputDevice2_Escape(p,a) (p)->lpVtbl->Escape(p,a)
12060#define IDirectInputDevice2_Poll(p) (p)->lpVtbl->Poll(p)
12061#define IDirectInputDevice2_SendDeviceData(p,a,b,c,d) (p)->lpVtbl->SendDeviceData(p,a,b,c,d)
12062#else
12063#define IDirectInputDevice2_QueryInterface(p,a,b) (p)->QueryInterface(a,b)
12064#define IDirectInputDevice2_AddRef(p) (p)->AddRef()
12065#define IDirectInputDevice2_Release(p) (p)->Release()
12066#define IDirectInputDevice2_GetCapabilities(p,a) (p)->GetCapabilities(a)
12067#define IDirectInputDevice2_EnumObjects(p,a,b,c) (p)->EnumObjects(a,b,c)
12068#define IDirectInputDevice2_GetProperty(p,a,b) (p)->GetProperty(a,b)
12069#define IDirectInputDevice2_SetProperty(p,a,b) (p)->SetProperty(a,b)
12070#define IDirectInputDevice2_Acquire(p) (p)->Acquire()
12071#define IDirectInputDevice2_Unacquire(p) (p)->Unacquire()
12072#define IDirectInputDevice2_GetDeviceState(p,a,b) (p)->GetDeviceState(a,b)
12073#define IDirectInputDevice2_GetDeviceData(p,a,b,c,d) (p)->GetDeviceData(a,b,c,d)
12074#define IDirectInputDevice2_SetDataFormat(p,a) (p)->SetDataFormat(a)
12075#define IDirectInputDevice2_SetEventNotification(p,a) (p)->SetEventNotification(a)
12076#define IDirectInputDevice2_SetCooperativeLevel(p,a,b) (p)->SetCooperativeLevel(a,b)
12077#define IDirectInputDevice2_GetObjectInfo(p,a,b,c) (p)->GetObjectInfo(a,b,c)
12078#define IDirectInputDevice2_GetDeviceInfo(p,a) (p)->GetDeviceInfo(a)
12079#define IDirectInputDevice2_RunControlPanel(p,a,b) (p)->RunControlPanel(a,b)
12080#define IDirectInputDevice2_Initialize(p,a,b,c) (p)->Initialize(a,b,c)
12081#define IDirectInputDevice2_CreateEffect(p,a,b,c,d) (p)->CreateEffect(a,b,c,d)
12082#define IDirectInputDevice2_EnumEffects(p,a,b,c) (p)->EnumEffects(a,b,c)
12083#define IDirectInputDevice2_GetEffectInfo(p,a,b) (p)->GetEffectInfo(a,b)
12084#define IDirectInputDevice2_GetForceFeedbackState(p,a) (p)->GetForceFeedbackState(a)
12085#define IDirectInputDevice2_SendForceFeedbackCommand(p,a) (p)->SendForceFeedbackCommand(a)
12086#define IDirectInputDevice2_EnumCreatedEffectObjects(p,a,b,c) (p)->EnumCreatedEffectObjects(a,b,c)
12087#define IDirectInputDevice2_Escape(p,a) (p)->Escape(a)
12088#define IDirectInputDevice2_Poll(p) (p)->Poll()
12089#define IDirectInputDevice2_SendDeviceData(p,a,b,c,d) (p)->SendDeviceData(a,b,c,d)
12090#endif
12091
12092#endif
12093
12094#endif
12095
12096#if(DIRECTINPUT_VERSION >= 0x0700)
12097#define DIFEF_DEFAULT               0x00000000
12098#define DIFEF_INCLUDENONSTANDARD    0x00000001
12099#define DIFEF_MODIFYIFNEEDED            0x00000010
12100
12101#ifndef DIJ_RINGZERO
12102
12103#undef INTERFACE
12104#define INTERFACE IDirectInputDevice7W
12105
12106DECLARE_INTERFACE_(IDirectInputDevice7W, IDirectInputDevice2W)
12107{
12108
12109    STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
12110    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
12111    STDMETHOD_(ULONG,Release)(THIS) PURE;
12112
12113    STDMETHOD(GetCapabilities)(THIS_ LPDIDEVCAPS) PURE;
12114    STDMETHOD(EnumObjects)(THIS_ LPDIENUMDEVICEOBJECTSCALLBACKW,LPVOID,DWORD) PURE;
12115    STDMETHOD(GetProperty)(THIS_ REFGUID,LPDIPROPHEADER) PURE;
12116    STDMETHOD(SetProperty)(THIS_ REFGUID,LPCDIPROPHEADER) PURE;
12117    STDMETHOD(Acquire)(THIS) PURE;
12118    STDMETHOD(Unacquire)(THIS) PURE;
12119    STDMETHOD(GetDeviceState)(THIS_ DWORD,LPVOID) PURE;
12120    STDMETHOD(GetDeviceData)(THIS_ DWORD,LPDIDEVICEOBJECTDATA,LPDWORD,DWORD) PURE;
12121    STDMETHOD(SetDataFormat)(THIS_ LPCDIDATAFORMAT) PURE;
12122    STDMETHOD(SetEventNotification)(THIS_ HANDLE) PURE;
12123    STDMETHOD(SetCooperativeLevel)(THIS_ HWND,DWORD) PURE;
12124    STDMETHOD(GetObjectInfo)(THIS_ LPDIDEVICEOBJECTINSTANCEW,DWORD,DWORD) PURE;
12125    STDMETHOD(GetDeviceInfo)(THIS_ LPDIDEVICEINSTANCEW) PURE;
12126    STDMETHOD(RunControlPanel)(THIS_ HWND,DWORD) PURE;
12127    STDMETHOD(Initialize)(THIS_ HINSTANCE,DWORD,REFGUID) PURE;
12128    STDMETHOD(CreateEffect)(THIS_ REFGUID,LPCDIEFFECT,LPDIRECTINPUTEFFECT *,LPUNKNOWN) PURE;
12129    STDMETHOD(EnumEffects)(THIS_ LPDIENUMEFFECTSCALLBACKW,LPVOID,DWORD) PURE;
12130    STDMETHOD(GetEffectInfo)(THIS_ LPDIEFFECTINFOW,REFGUID) PURE;
12131    STDMETHOD(GetForceFeedbackState)(THIS_ LPDWORD) PURE;
12132    STDMETHOD(SendForceFeedbackCommand)(THIS_ DWORD) PURE;
12133    STDMETHOD(EnumCreatedEffectObjects)(THIS_ LPDIENUMCREATEDEFFECTOBJECTSCALLBACK,LPVOID,DWORD) PURE;
12134    STDMETHOD(Escape)(THIS_ LPDIEFFESCAPE) PURE;
12135    STDMETHOD(Poll)(THIS) PURE;
12136    STDMETHOD(SendDeviceData)(THIS_ DWORD,LPCDIDEVICEOBJECTDATA,LPDWORD,DWORD) PURE;
12137
12138    STDMETHOD(EnumEffectsInFile)(THIS_ LPCWSTR,LPDIENUMEFFECTSINFILECALLBACK,LPVOID,DWORD) PURE;
12139    STDMETHOD(WriteEffectToFile)(THIS_ LPCWSTR,DWORD,LPDIFILEEFFECT,DWORD) PURE;
12140};
12141
12142typedef struct IDirectInputDevice7W *LPDIRECTINPUTDEVICE7W;
12143
12144#undef INTERFACE
12145#define INTERFACE IDirectInputDevice7A
12146
12147DECLARE_INTERFACE_(IDirectInputDevice7A, IDirectInputDevice2A)
12148{
12149
12150    STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
12151    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
12152    STDMETHOD_(ULONG,Release)(THIS) PURE;
12153
12154    STDMETHOD(GetCapabilities)(THIS_ LPDIDEVCAPS) PURE;
12155    STDMETHOD(EnumObjects)(THIS_ LPDIENUMDEVICEOBJECTSCALLBACKA,LPVOID,DWORD) PURE;
12156    STDMETHOD(GetProperty)(THIS_ REFGUID,LPDIPROPHEADER) PURE;
12157    STDMETHOD(SetProperty)(THIS_ REFGUID,LPCDIPROPHEADER) PURE;
12158    STDMETHOD(Acquire)(THIS) PURE;
12159    STDMETHOD(Unacquire)(THIS) PURE;
12160    STDMETHOD(GetDeviceState)(THIS_ DWORD,LPVOID) PURE;
12161    STDMETHOD(GetDeviceData)(THIS_ DWORD,LPDIDEVICEOBJECTDATA,LPDWORD,DWORD) PURE;
12162    STDMETHOD(SetDataFormat)(THIS_ LPCDIDATAFORMAT) PURE;
12163    STDMETHOD(SetEventNotification)(THIS_ HANDLE) PURE;
12164    STDMETHOD(SetCooperativeLevel)(THIS_ HWND,DWORD) PURE;
12165    STDMETHOD(GetObjectInfo)(THIS_ LPDIDEVICEOBJECTINSTANCEA,DWORD,DWORD) PURE;
12166    STDMETHOD(GetDeviceInfo)(THIS_ LPDIDEVICEINSTANCEA) PURE;
12167    STDMETHOD(RunControlPanel)(THIS_ HWND,DWORD) PURE;
12168    STDMETHOD(Initialize)(THIS_ HINSTANCE,DWORD,REFGUID) PURE;
12169    STDMETHOD(CreateEffect)(THIS_ REFGUID,LPCDIEFFECT,LPDIRECTINPUTEFFECT *,LPUNKNOWN) PURE;
12170    STDMETHOD(EnumEffects)(THIS_ LPDIENUMEFFECTSCALLBACKA,LPVOID,DWORD) PURE;
12171    STDMETHOD(GetEffectInfo)(THIS_ LPDIEFFECTINFOA,REFGUID) PURE;
12172    STDMETHOD(GetForceFeedbackState)(THIS_ LPDWORD) PURE;
12173    STDMETHOD(SendForceFeedbackCommand)(THIS_ DWORD) PURE;
12174    STDMETHOD(EnumCreatedEffectObjects)(THIS_ LPDIENUMCREATEDEFFECTOBJECTSCALLBACK,LPVOID,DWORD) PURE;
12175    STDMETHOD(Escape)(THIS_ LPDIEFFESCAPE) PURE;
12176    STDMETHOD(Poll)(THIS) PURE;
12177    STDMETHOD(SendDeviceData)(THIS_ DWORD,LPCDIDEVICEOBJECTDATA,LPDWORD,DWORD) PURE;
12178
12179    STDMETHOD(EnumEffectsInFile)(THIS_ LPCSTR,LPDIENUMEFFECTSINFILECALLBACK,LPVOID,DWORD) PURE;
12180    STDMETHOD(WriteEffectToFile)(THIS_ LPCSTR,DWORD,LPDIFILEEFFECT,DWORD) PURE;
12181};
12182
12183typedef struct IDirectInputDevice7A *LPDIRECTINPUTDEVICE7A;
12184
12185#ifdef UNICODE
12186#define IID_IDirectInputDevice7 IID_IDirectInputDevice7W
12187#define IDirectInputDevice7 IDirectInputDevice7W
12188#define IDirectInputDevice7Vtbl IDirectInputDevice7WVtbl
12189#else
12190#define IID_IDirectInputDevice7 IID_IDirectInputDevice7A
12191#define IDirectInputDevice7 IDirectInputDevice7A
12192#define IDirectInputDevice7Vtbl IDirectInputDevice7AVtbl
12193#endif
12194typedef struct IDirectInputDevice7 *LPDIRECTINPUTDEVICE7;
12195
12196#if !defined(__cplusplus) || defined(CINTERFACE)
12197#define IDirectInputDevice7_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
12198#define IDirectInputDevice7_AddRef(p) (p)->lpVtbl->AddRef(p)
12199#define IDirectInputDevice7_Release(p) (p)->lpVtbl->Release(p)
12200#define IDirectInputDevice7_GetCapabilities(p,a) (p)->lpVtbl->GetCapabilities(p,a)
12201#define IDirectInputDevice7_EnumObjects(p,a,b,c) (p)->lpVtbl->EnumObjects(p,a,b,c)
12202#define IDirectInputDevice7_GetProperty(p,a,b) (p)->lpVtbl->GetProperty(p,a,b)
12203#define IDirectInputDevice7_SetProperty(p,a,b) (p)->lpVtbl->SetProperty(p,a,b)
12204#define IDirectInputDevice7_Acquire(p) (p)->lpVtbl->Acquire(p)
12205#define IDirectInputDevice7_Unacquire(p) (p)->lpVtbl->Unacquire(p)
12206#define IDirectInputDevice7_GetDeviceState(p,a,b) (p)->lpVtbl->GetDeviceState(p,a,b)
12207#define IDirectInputDevice7_GetDeviceData(p,a,b,c,d) (p)->lpVtbl->GetDeviceData(p,a,b,c,d)
12208#define IDirectInputDevice7_SetDataFormat(p,a) (p)->lpVtbl->SetDataFormat(p,a)
12209#define IDirectInputDevice7_SetEventNotification(p,a) (p)->lpVtbl->SetEventNotification(p,a)
12210#define IDirectInputDevice7_SetCooperativeLevel(p,a,b) (p)->lpVtbl->SetCooperativeLevel(p,a,b)
12211#define IDirectInputDevice7_GetObjectInfo(p,a,b,c) (p)->lpVtbl->GetObjectInfo(p,a,b,c)
12212#define IDirectInputDevice7_GetDeviceInfo(p,a) (p)->lpVtbl->GetDeviceInfo(p,a)
12213#define IDirectInputDevice7_RunControlPanel(p,a,b) (p)->lpVtbl->RunControlPanel(p,a,b)
12214#define IDirectInputDevice7_Initialize(p,a,b,c) (p)->lpVtbl->Initialize(p,a,b,c)
12215#define IDirectInputDevice7_CreateEffect(p,a,b,c,d) (p)->lpVtbl->CreateEffect(p,a,b,c,d)
12216#define IDirectInputDevice7_EnumEffects(p,a,b,c) (p)->lpVtbl->EnumEffects(p,a,b,c)
12217#define IDirectInputDevice7_GetEffectInfo(p,a,b) (p)->lpVtbl->GetEffectInfo(p,a,b)
12218#define IDirectInputDevice7_GetForceFeedbackState(p,a) (p)->lpVtbl->GetForceFeedbackState(p,a)
12219#define IDirectInputDevice7_SendForceFeedbackCommand(p,a) (p)->lpVtbl->SendForceFeedbackCommand(p,a)
12220#define IDirectInputDevice7_EnumCreatedEffectObjects(p,a,b,c) (p)->lpVtbl->EnumCreatedEffectObjects(p,a,b,c)
12221#define IDirectInputDevice7_Escape(p,a) (p)->lpVtbl->Escape(p,a)
12222#define IDirectInputDevice7_Poll(p) (p)->lpVtbl->Poll(p)
12223#define IDirectInputDevice7_SendDeviceData(p,a,b,c,d) (p)->lpVtbl->SendDeviceData(p,a,b,c,d)
12224#define IDirectInputDevice7_EnumEffectsInFile(p,a,b,c,d) (p)->lpVtbl->EnumEffectsInFile(p,a,b,c,d)
12225#define IDirectInputDevice7_WriteEffectToFile(p,a,b,c,d) (p)->lpVtbl->WriteEffectToFile(p,a,b,c,d)
12226#else
12227#define IDirectInputDevice7_QueryInterface(p,a,b) (p)->QueryInterface(a,b)
12228#define IDirectInputDevice7_AddRef(p) (p)->AddRef()
12229#define IDirectInputDevice7_Release(p) (p)->Release()
12230#define IDirectInputDevice7_GetCapabilities(p,a) (p)->GetCapabilities(a)
12231#define IDirectInputDevice7_EnumObjects(p,a,b,c) (p)->EnumObjects(a,b,c)
12232#define IDirectInputDevice7_GetProperty(p,a,b) (p)->GetProperty(a,b)
12233#define IDirectInputDevice7_SetProperty(p,a,b) (p)->SetProperty(a,b)
12234#define IDirectInputDevice7_Acquire(p) (p)->Acquire()
12235#define IDirectInputDevice7_Unacquire(p) (p)->Unacquire()
12236#define IDirectInputDevice7_GetDeviceState(p,a,b) (p)->GetDeviceState(a,b)
12237#define IDirectInputDevice7_GetDeviceData(p,a,b,c,d) (p)->GetDeviceData(a,b,c,d)
12238#define IDirectInputDevice7_SetDataFormat(p,a) (p)->SetDataFormat(a)
12239#define IDirectInputDevice7_SetEventNotification(p,a) (p)->SetEventNotification(a)
12240#define IDirectInputDevice7_SetCooperativeLevel(p,a,b) (p)->SetCooperativeLevel(a,b)
12241#define IDirectInputDevice7_GetObjectInfo(p,a,b,c) (p)->GetObjectInfo(a,b,c)
12242#define IDirectInputDevice7_GetDeviceInfo(p,a) (p)->GetDeviceInfo(a)
12243#define IDirectInputDevice7_RunControlPanel(p,a,b) (p)->RunControlPanel(a,b)
12244#define IDirectInputDevice7_Initialize(p,a,b,c) (p)->Initialize(a,b,c)
12245#define IDirectInputDevice7_CreateEffect(p,a,b,c,d) (p)->CreateEffect(a,b,c,d)
12246#define IDirectInputDevice7_EnumEffects(p,a,b,c) (p)->EnumEffects(a,b,c)
12247#define IDirectInputDevice7_GetEffectInfo(p,a,b) (p)->GetEffectInfo(a,b)
12248#define IDirectInputDevice7_GetForceFeedbackState(p,a) (p)->GetForceFeedbackState(a)
12249#define IDirectInputDevice7_SendForceFeedbackCommand(p,a) (p)->SendForceFeedbackCommand(a)
12250#define IDirectInputDevice7_EnumCreatedEffectObjects(p,a,b,c) (p)->EnumCreatedEffectObjects(a,b,c)
12251#define IDirectInputDevice7_Escape(p,a) (p)->Escape(a)
12252#define IDirectInputDevice7_Poll(p) (p)->Poll()
12253#define IDirectInputDevice7_SendDeviceData(p,a,b,c,d) (p)->SendDeviceData(a,b,c,d)
12254#define IDirectInputDevice7_EnumEffectsInFile(p,a,b,c,d) (p)->EnumEffectsInFile(a,b,c,d)
12255#define IDirectInputDevice7_WriteEffectToFile(p,a,b,c,d) (p)->WriteEffectToFile(a,b,c,d)
12256#endif
12257
12258#endif
12259
12260#endif
12261
12262#if(DIRECTINPUT_VERSION >= 0x0800)
12263
12264#ifndef DIJ_RINGZERO
12265
12266#undef INTERFACE
12267#define INTERFACE IDirectInputDevice8W
12268
12269DECLARE_INTERFACE_(IDirectInputDevice8W, IUnknown)
12270{
12271
12272    STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
12273    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
12274    STDMETHOD_(ULONG,Release)(THIS) PURE;
12275
12276    STDMETHOD(GetCapabilities)(THIS_ LPDIDEVCAPS) PURE;
12277    STDMETHOD(EnumObjects)(THIS_ LPDIENUMDEVICEOBJECTSCALLBACKW,LPVOID,DWORD) PURE;
12278    STDMETHOD(GetProperty)(THIS_ REFGUID,LPDIPROPHEADER) PURE;
12279    STDMETHOD(SetProperty)(THIS_ REFGUID,LPCDIPROPHEADER) PURE;
12280    STDMETHOD(Acquire)(THIS) PURE;
12281    STDMETHOD(Unacquire)(THIS) PURE;
12282    STDMETHOD(GetDeviceState)(THIS_ DWORD,LPVOID) PURE;
12283    STDMETHOD(GetDeviceData)(THIS_ DWORD,LPDIDEVICEOBJECTDATA,LPDWORD,DWORD) PURE;
12284    STDMETHOD(SetDataFormat)(THIS_ LPCDIDATAFORMAT) PURE;
12285    STDMETHOD(SetEventNotification)(THIS_ HANDLE) PURE;
12286    STDMETHOD(SetCooperativeLevel)(THIS_ HWND,DWORD) PURE;
12287    STDMETHOD(GetObjectInfo)(THIS_ LPDIDEVICEOBJECTINSTANCEW,DWORD,DWORD) PURE;
12288    STDMETHOD(GetDeviceInfo)(THIS_ LPDIDEVICEINSTANCEW) PURE;
12289    STDMETHOD(RunControlPanel)(THIS_ HWND,DWORD) PURE;
12290    STDMETHOD(Initialize)(THIS_ HINSTANCE,DWORD,REFGUID) PURE;
12291    STDMETHOD(CreateEffect)(THIS_ REFGUID,LPCDIEFFECT,LPDIRECTINPUTEFFECT *,LPUNKNOWN) PURE;
12292    STDMETHOD(EnumEffects)(THIS_ LPDIENUMEFFECTSCALLBACKW,LPVOID,DWORD) PURE;
12293    STDMETHOD(GetEffectInfo)(THIS_ LPDIEFFECTINFOW,REFGUID) PURE;
12294    STDMETHOD(GetForceFeedbackState)(THIS_ LPDWORD) PURE;
12295    STDMETHOD(SendForceFeedbackCommand)(THIS_ DWORD) PURE;
12296    STDMETHOD(EnumCreatedEffectObjects)(THIS_ LPDIENUMCREATEDEFFECTOBJECTSCALLBACK,LPVOID,DWORD) PURE;
12297    STDMETHOD(Escape)(THIS_ LPDIEFFESCAPE) PURE;
12298    STDMETHOD(Poll)(THIS) PURE;
12299    STDMETHOD(SendDeviceData)(THIS_ DWORD,LPCDIDEVICEOBJECTDATA,LPDWORD,DWORD) PURE;
12300    STDMETHOD(EnumEffectsInFile)(THIS_ LPCWSTR,LPDIENUMEFFECTSINFILECALLBACK,LPVOID,DWORD) PURE;
12301    STDMETHOD(WriteEffectToFile)(THIS_ LPCWSTR,DWORD,LPDIFILEEFFECT,DWORD) PURE;
12302    STDMETHOD(BuildActionMap)(THIS_ LPDIACTIONFORMATW,LPCWSTR,DWORD) PURE;
12303    STDMETHOD(SetActionMap)(THIS_ LPDIACTIONFORMATW,LPCWSTR,DWORD) PURE;
12304    STDMETHOD(GetImageInfo)(THIS_ LPDIDEVICEIMAGEINFOHEADERW) PURE;
12305};
12306
12307typedef struct IDirectInputDevice8W *LPDIRECTINPUTDEVICE8W;
12308
12309#undef INTERFACE
12310#define INTERFACE IDirectInputDevice8A
12311
12312DECLARE_INTERFACE_(IDirectInputDevice8A, IUnknown)
12313{
12314
12315    STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
12316    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
12317    STDMETHOD_(ULONG,Release)(THIS) PURE;
12318
12319    STDMETHOD(GetCapabilities)(THIS_ LPDIDEVCAPS) PURE;
12320    STDMETHOD(EnumObjects)(THIS_ LPDIENUMDEVICEOBJECTSCALLBACKA,LPVOID,DWORD) PURE;
12321    STDMETHOD(GetProperty)(THIS_ REFGUID,LPDIPROPHEADER) PURE;
12322    STDMETHOD(SetProperty)(THIS_ REFGUID,LPCDIPROPHEADER) PURE;
12323    STDMETHOD(Acquire)(THIS) PURE;
12324    STDMETHOD(Unacquire)(THIS) PURE;
12325    STDMETHOD(GetDeviceState)(THIS_ DWORD,LPVOID) PURE;
12326    STDMETHOD(GetDeviceData)(THIS_ DWORD,LPDIDEVICEOBJECTDATA,LPDWORD,DWORD) PURE;
12327    STDMETHOD(SetDataFormat)(THIS_ LPCDIDATAFORMAT) PURE;
12328    STDMETHOD(SetEventNotification)(THIS_ HANDLE) PURE;
12329    STDMETHOD(SetCooperativeLevel)(THIS_ HWND,DWORD) PURE;
12330    STDMETHOD(GetObjectInfo)(THIS_ LPDIDEVICEOBJECTINSTANCEA,DWORD,DWORD) PURE;
12331    STDMETHOD(GetDeviceInfo)(THIS_ LPDIDEVICEINSTANCEA) PURE;
12332    STDMETHOD(RunControlPanel)(THIS_ HWND,DWORD) PURE;
12333    STDMETHOD(Initialize)(THIS_ HINSTANCE,DWORD,REFGUID) PURE;
12334    STDMETHOD(CreateEffect)(THIS_ REFGUID,LPCDIEFFECT,LPDIRECTINPUTEFFECT *,LPUNKNOWN) PURE;
12335    STDMETHOD(EnumEffects)(THIS_ LPDIENUMEFFECTSCALLBACKA,LPVOID,DWORD) PURE;
12336    STDMETHOD(GetEffectInfo)(THIS_ LPDIEFFECTINFOA,REFGUID) PURE;
12337    STDMETHOD(GetForceFeedbackState)(THIS_ LPDWORD) PURE;
12338    STDMETHOD(SendForceFeedbackCommand)(THIS_ DWORD) PURE;
12339    STDMETHOD(EnumCreatedEffectObjects)(THIS_ LPDIENUMCREATEDEFFECTOBJECTSCALLBACK,LPVOID,DWORD) PURE;
12340    STDMETHOD(Escape)(THIS_ LPDIEFFESCAPE) PURE;
12341    STDMETHOD(Poll)(THIS) PURE;
12342    STDMETHOD(SendDeviceData)(THIS_ DWORD,LPCDIDEVICEOBJECTDATA,LPDWORD,DWORD) PURE;
12343    STDMETHOD(EnumEffectsInFile)(THIS_ LPCSTR,LPDIENUMEFFECTSINFILECALLBACK,LPVOID,DWORD) PURE;
12344    STDMETHOD(WriteEffectToFile)(THIS_ LPCSTR,DWORD,LPDIFILEEFFECT,DWORD) PURE;
12345    STDMETHOD(BuildActionMap)(THIS_ LPDIACTIONFORMATA,LPCSTR,DWORD) PURE;
12346    STDMETHOD(SetActionMap)(THIS_ LPDIACTIONFORMATA,LPCSTR,DWORD) PURE;
12347    STDMETHOD(GetImageInfo)(THIS_ LPDIDEVICEIMAGEINFOHEADERA) PURE;
12348};
12349
12350typedef struct IDirectInputDevice8A *LPDIRECTINPUTDEVICE8A;
12351
12352#ifdef UNICODE
12353#define IID_IDirectInputDevice8 IID_IDirectInputDevice8W
12354#define IDirectInputDevice8 IDirectInputDevice8W
12355#define IDirectInputDevice8Vtbl IDirectInputDevice8WVtbl
12356#else
12357#define IID_IDirectInputDevice8 IID_IDirectInputDevice8A
12358#define IDirectInputDevice8 IDirectInputDevice8A
12359#define IDirectInputDevice8Vtbl IDirectInputDevice8AVtbl
12360#endif
12361typedef struct IDirectInputDevice8 *LPDIRECTINPUTDEVICE8;
12362
12363#if !defined(__cplusplus) || defined(CINTERFACE)
12364#define IDirectInputDevice8_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
12365#define IDirectInputDevice8_AddRef(p) (p)->lpVtbl->AddRef(p)
12366#define IDirectInputDevice8_Release(p) (p)->lpVtbl->Release(p)
12367#define IDirectInputDevice8_GetCapabilities(p,a) (p)->lpVtbl->GetCapabilities(p,a)
12368#define IDirectInputDevice8_EnumObjects(p,a,b,c) (p)->lpVtbl->EnumObjects(p,a,b,c)
12369#define IDirectInputDevice8_GetProperty(p,a,b) (p)->lpVtbl->GetProperty(p,a,b)
12370#define IDirectInputDevice8_SetProperty(p,a,b) (p)->lpVtbl->SetProperty(p,a,b)
12371#define IDirectInputDevice8_Acquire(p) (p)->lpVtbl->Acquire(p)
12372#define IDirectInputDevice8_Unacquire(p) (p)->lpVtbl->Unacquire(p)
12373#define IDirectInputDevice8_GetDeviceState(p,a,b) (p)->lpVtbl->GetDeviceState(p,a,b)
12374#define IDirectInputDevice8_GetDeviceData(p,a,b,c,d) (p)->lpVtbl->GetDeviceData(p,a,b,c,d)
12375#define IDirectInputDevice8_SetDataFormat(p,a) (p)->lpVtbl->SetDataFormat(p,a)
12376#define IDirectInputDevice8_SetEventNotification(p,a) (p)->lpVtbl->SetEventNotification(p,a)
12377#define IDirectInputDevice8_SetCooperativeLevel(p,a,b) (p)->lpVtbl->SetCooperativeLevel(p,a,b)
12378#define IDirectInputDevice8_GetObjectInfo(p,a,b,c) (p)->lpVtbl->GetObjectInfo(p,a,b,c)
12379#define IDirectInputDevice8_GetDeviceInfo(p,a) (p)->lpVtbl->GetDeviceInfo(p,a)
12380#define IDirectInputDevice8_RunControlPanel(p,a,b) (p)->lpVtbl->RunControlPanel(p,a,b)
12381#define IDirectInputDevice8_Initialize(p,a,b,c) (p)->lpVtbl->Initialize(p,a,b,c)
12382#define IDirectInputDevice8_CreateEffect(p,a,b,c,d) (p)->lpVtbl->CreateEffect(p,a,b,c,d)
12383#define IDirectInputDevice8_EnumEffects(p,a,b,c) (p)->lpVtbl->EnumEffects(p,a,b,c)
12384#define IDirectInputDevice8_GetEffectInfo(p,a,b) (p)->lpVtbl->GetEffectInfo(p,a,b)
12385#define IDirectInputDevice8_GetForceFeedbackState(p,a) (p)->lpVtbl->GetForceFeedbackState(p,a)
12386#define IDirectInputDevice8_SendForceFeedbackCommand(p,a) (p)->lpVtbl->SendForceFeedbackCommand(p,a)
12387#define IDirectInputDevice8_EnumCreatedEffectObjects(p,a,b,c) (p)->lpVtbl->EnumCreatedEffectObjects(p,a,b,c)
12388#define IDirectInputDevice8_Escape(p,a) (p)->lpVtbl->Escape(p,a)
12389#define IDirectInputDevice8_Poll(p) (p)->lpVtbl->Poll(p)
12390#define IDirectInputDevice8_SendDeviceData(p,a,b,c,d) (p)->lpVtbl->SendDeviceData(p,a,b,c,d)
12391#define IDirectInputDevice8_EnumEffectsInFile(p,a,b,c,d) (p)->lpVtbl->EnumEffectsInFile(p,a,b,c,d)
12392#define IDirectInputDevice8_WriteEffectToFile(p,a,b,c,d) (p)->lpVtbl->WriteEffectToFile(p,a,b,c,d)
12393#define IDirectInputDevice8_BuildActionMap(p,a,b,c) (p)->lpVtbl->BuildActionMap(p,a,b,c)
12394#define IDirectInputDevice8_SetActionMap(p,a,b,c) (p)->lpVtbl->SetActionMap(p,a,b,c)
12395#define IDirectInputDevice8_GetImageInfo(p,a) (p)->lpVtbl->GetImageInfo(p,a)
12396#else
12397#define IDirectInputDevice8_QueryInterface(p,a,b) (p)->QueryInterface(a,b)
12398#define IDirectInputDevice8_AddRef(p) (p)->AddRef()
12399#define IDirectInputDevice8_Release(p) (p)->Release()
12400#define IDirectInputDevice8_GetCapabilities(p,a) (p)->GetCapabilities(a)
12401#define IDirectInputDevice8_EnumObjects(p,a,b,c) (p)->EnumObjects(a,b,c)
12402#define IDirectInputDevice8_GetProperty(p,a,b) (p)->GetProperty(a,b)
12403#define IDirectInputDevice8_SetProperty(p,a,b) (p)->SetProperty(a,b)
12404#define IDirectInputDevice8_Acquire(p) (p)->Acquire()
12405#define IDirectInputDevice8_Unacquire(p) (p)->Unacquire()
12406#define IDirectInputDevice8_GetDeviceState(p,a,b) (p)->GetDeviceState(a,b)
12407#define IDirectInputDevice8_GetDeviceData(p,a,b,c,d) (p)->GetDeviceData(a,b,c,d)
12408#define IDirectInputDevice8_SetDataFormat(p,a) (p)->SetDataFormat(a)
12409#define IDirectInputDevice8_SetEventNotification(p,a) (p)->SetEventNotification(a)
12410#define IDirectInputDevice8_SetCooperativeLevel(p,a,b) (p)->SetCooperativeLevel(a,b)
12411#define IDirectInputDevice8_GetObjectInfo(p,a,b,c) (p)->GetObjectInfo(a,b,c)
12412#define IDirectInputDevice8_GetDeviceInfo(p,a) (p)->GetDeviceInfo(a)
12413#define IDirectInputDevice8_RunControlPanel(p,a,b) (p)->RunControlPanel(a,b)
12414#define IDirectInputDevice8_Initialize(p,a,b,c) (p)->Initialize(a,b,c)
12415#define IDirectInputDevice8_CreateEffect(p,a,b,c,d) (p)->CreateEffect(a,b,c,d)
12416#define IDirectInputDevice8_EnumEffects(p,a,b,c) (p)->EnumEffects(a,b,c)
12417#define IDirectInputDevice8_GetEffectInfo(p,a,b) (p)->GetEffectInfo(a,b)
12418#define IDirectInputDevice8_GetForceFeedbackState(p,a) (p)->GetForceFeedbackState(a)
12419#define IDirectInputDevice8_SendForceFeedbackCommand(p,a) (p)->SendForceFeedbackCommand(a)
12420#define IDirectInputDevice8_EnumCreatedEffectObjects(p,a,b,c) (p)->EnumCreatedEffectObjects(a,b,c)
12421#define IDirectInputDevice8_Escape(p,a) (p)->Escape(a)
12422#define IDirectInputDevice8_Poll(p) (p)->Poll()
12423#define IDirectInputDevice8_SendDeviceData(p,a,b,c,d) (p)->SendDeviceData(a,b,c,d)
12424#define IDirectInputDevice8_EnumEffectsInFile(p,a,b,c,d) (p)->EnumEffectsInFile(a,b,c,d)
12425#define IDirectInputDevice8_WriteEffectToFile(p,a,b,c,d) (p)->WriteEffectToFile(a,b,c,d)
12426#define IDirectInputDevice8_BuildActionMap(p,a,b,c) (p)->BuildActionMap(a,b,c)
12427#define IDirectInputDevice8_SetActionMap(p,a,b,c) (p)->SetActionMap(a,b,c)
12428#define IDirectInputDevice8_GetImageInfo(p,a) (p)->GetImageInfo(a)
12429#endif
12430
12431#endif
12432
12433#endif
12434
12435#ifndef DIJ_RINGZERO
12436
12437typedef struct _DIMOUSESTATE {
12438    LONG    lX;
12439    LONG    lY;
12440    LONG    lZ;
12441    BYTE    rgbButtons[4];
12442} DIMOUSESTATE, *LPDIMOUSESTATE;
12443
12444#if DIRECTINPUT_VERSION >= 0x0700
12445typedef struct _DIMOUSESTATE2 {
12446    LONG    lX;
12447    LONG    lY;
12448    LONG    lZ;
12449    BYTE    rgbButtons[8];
12450} DIMOUSESTATE2, *LPDIMOUSESTATE2;
12451#endif
12452
12453#define DIMOFS_X        FIELD_OFFSET(DIMOUSESTATE, lX)
12454#define DIMOFS_Y        FIELD_OFFSET(DIMOUSESTATE, lY)
12455#define DIMOFS_Z        FIELD_OFFSET(DIMOUSESTATE, lZ)
12456#define DIMOFS_BUTTON0 (FIELD_OFFSET(DIMOUSESTATE, rgbButtons) + 0)
12457#define DIMOFS_BUTTON1 (FIELD_OFFSET(DIMOUSESTATE, rgbButtons) + 1)
12458#define DIMOFS_BUTTON2 (FIELD_OFFSET(DIMOUSESTATE, rgbButtons) + 2)
12459#define DIMOFS_BUTTON3 (FIELD_OFFSET(DIMOUSESTATE, rgbButtons) + 3)
12460#if (DIRECTINPUT_VERSION >= 0x0700)
12461#define DIMOFS_BUTTON4 (FIELD_OFFSET(DIMOUSESTATE2, rgbButtons) + 4)
12462#define DIMOFS_BUTTON5 (FIELD_OFFSET(DIMOUSESTATE2, rgbButtons) + 5)
12463#define DIMOFS_BUTTON6 (FIELD_OFFSET(DIMOUSESTATE2, rgbButtons) + 6)
12464#define DIMOFS_BUTTON7 (FIELD_OFFSET(DIMOUSESTATE2, rgbButtons) + 7)
12465#endif
12466#endif
12467
12468#ifndef DIJ_RINGZERO
12469
12470#define DIK_ESCAPE          0x01
12471#define DIK_1               0x02
12472#define DIK_2               0x03
12473#define DIK_3               0x04
12474#define DIK_4               0x05
12475#define DIK_5               0x06
12476#define DIK_6               0x07
12477#define DIK_7               0x08
12478#define DIK_8               0x09
12479#define DIK_9               0x0A
12480#define DIK_0               0x0B
12481#define DIK_MINUS           0x0C
12482#define DIK_EQUALS          0x0D
12483#define DIK_BACK            0x0E
12484#define DIK_TAB             0x0F
12485#define DIK_Q               0x10
12486#define DIK_W               0x11
12487#define DIK_E               0x12
12488#define DIK_R               0x13
12489#define DIK_T               0x14
12490#define DIK_Y               0x15
12491#define DIK_U               0x16
12492#define DIK_I               0x17
12493#define DIK_O               0x18
12494#define DIK_P               0x19
12495#define DIK_LBRACKET        0x1A
12496#define DIK_RBRACKET        0x1B
12497#define DIK_RETURN          0x1C
12498#define DIK_LCONTROL        0x1D
12499#define DIK_A               0x1E
12500#define DIK_S               0x1F
12501#define DIK_D               0x20
12502#define DIK_F               0x21
12503#define DIK_G               0x22
12504#define DIK_H               0x23
12505#define DIK_J               0x24
12506#define DIK_K               0x25
12507#define DIK_L               0x26
12508#define DIK_SEMICOLON       0x27
12509#define DIK_APOSTROPHE      0x28
12510#define DIK_GRAVE           0x29
12511#define DIK_LSHIFT          0x2A
12512#define DIK_BACKSLASH       0x2B
12513#define DIK_Z               0x2C
12514#define DIK_X               0x2D
12515#define DIK_C               0x2E
12516#define DIK_V               0x2F
12517#define DIK_B               0x30
12518#define DIK_N               0x31
12519#define DIK_M               0x32
12520#define DIK_COMMA           0x33
12521#define DIK_PERIOD          0x34
12522#define DIK_SLASH           0x35
12523#define DIK_RSHIFT          0x36
12524#define DIK_MULTIPLY        0x37
12525#define DIK_LMENU           0x38
12526#define DIK_SPACE           0x39
12527#define DIK_CAPITAL         0x3A
12528#define DIK_F1              0x3B
12529#define DIK_F2              0x3C
12530#define DIK_F3              0x3D
12531#define DIK_F4              0x3E
12532#define DIK_F5              0x3F
12533#define DIK_F6              0x40
12534#define DIK_F7              0x41
12535#define DIK_F8              0x42
12536#define DIK_F9              0x43
12537#define DIK_F10             0x44
12538#define DIK_NUMLOCK         0x45
12539#define DIK_SCROLL          0x46
12540#define DIK_NUMPAD7         0x47
12541#define DIK_NUMPAD8         0x48
12542#define DIK_NUMPAD9         0x49
12543#define DIK_SUBTRACT        0x4A
12544#define DIK_NUMPAD4         0x4B
12545#define DIK_NUMPAD5         0x4C
12546#define DIK_NUMPAD6         0x4D
12547#define DIK_ADD             0x4E
12548#define DIK_NUMPAD1         0x4F
12549#define DIK_NUMPAD2         0x50
12550#define DIK_NUMPAD3         0x51
12551#define DIK_NUMPAD0         0x52
12552#define DIK_DECIMAL         0x53
12553#define DIK_OEM_102         0x56
12554#define DIK_F11             0x57
12555#define DIK_F12             0x58
12556#define DIK_F13             0x64
12557#define DIK_F14             0x65
12558#define DIK_F15             0x66
12559#define DIK_KANA            0x70
12560#define DIK_ABNT_C1         0x73
12561#define DIK_CONVERT         0x79
12562#define DIK_NOCONVERT       0x7B
12563#define DIK_YEN             0x7D
12564#define DIK_ABNT_C2         0x7E
12565#define DIK_NUMPADEQUALS    0x8D
12566#define DIK_PREVTRACK       0x90
12567#define DIK_AT              0x91
12568#define DIK_COLON           0x92
12569#define DIK_UNDERLINE       0x93
12570#define DIK_KANJI           0x94
12571#define DIK_STOP            0x95
12572#define DIK_AX              0x96
12573#define DIK_UNLABELED       0x97
12574#define DIK_NEXTTRACK       0x99
12575#define DIK_NUMPADENTER     0x9C
12576#define DIK_RCONTROL        0x9D
12577#define DIK_MUTE            0xA0
12578#define DIK_CALCULATOR      0xA1
12579#define DIK_PLAYPAUSE       0xA2
12580#define DIK_MEDIASTOP       0xA4
12581#define DIK_VOLUMEDOWN      0xAE
12582#define DIK_VOLUMEUP        0xB0
12583#define DIK_WEBHOME         0xB2
12584#define DIK_NUMPADCOMMA     0xB3
12585#define DIK_DIVIDE          0xB5
12586#define DIK_SYSRQ           0xB7
12587#define DIK_RMENU           0xB8
12588#define DIK_PAUSE           0xC5
12589#define DIK_HOME            0xC7
12590#define DIK_UP              0xC8
12591#define DIK_PRIOR           0xC9
12592#define DIK_LEFT            0xCB
12593#define DIK_RIGHT           0xCD
12594#define DIK_END             0xCF
12595#define DIK_DOWN            0xD0
12596#define DIK_NEXT            0xD1
12597#define DIK_INSERT          0xD2
12598#define DIK_DELETE          0xD3
12599#define DIK_LWIN            0xDB
12600#define DIK_RWIN            0xDC
12601#define DIK_APPS            0xDD
12602#define DIK_POWER           0xDE
12603#define DIK_SLEEP           0xDF
12604#define DIK_WAKE            0xE3
12605#define DIK_WEBSEARCH       0xE5
12606#define DIK_WEBFAVORITES    0xE6
12607#define DIK_WEBREFRESH      0xE7
12608#define DIK_WEBSTOP         0xE8
12609#define DIK_WEBFORWARD      0xE9
12610#define DIK_WEBBACK         0xEA
12611#define DIK_MYCOMPUTER      0xEB
12612#define DIK_MAIL            0xEC
12613#define DIK_MEDIASELECT     0xED
12614
12615#define DIK_BACKSPACE       DIK_BACK
12616#define DIK_NUMPADSTAR      DIK_MULTIPLY
12617#define DIK_LALT            DIK_LMENU
12618#define DIK_CAPSLOCK        DIK_CAPITAL
12619#define DIK_NUMPADMINUS     DIK_SUBTRACT
12620#define DIK_NUMPADPLUS      DIK_ADD
12621#define DIK_NUMPADPERIOD    DIK_DECIMAL
12622#define DIK_NUMPADSLASH     DIK_DIVIDE
12623#define DIK_RALT            DIK_RMENU
12624#define DIK_UPARROW         DIK_UP
12625#define DIK_PGUP            DIK_PRIOR
12626#define DIK_LEFTARROW       DIK_LEFT
12627#define DIK_RIGHTARROW      DIK_RIGHT
12628#define DIK_DOWNARROW       DIK_DOWN
12629#define DIK_PGDN            DIK_NEXT
12630
12631#define DIK_CIRCUMFLEX      DIK_PREVTRACK
12632
12633#endif
12634
12635#ifndef DIJ_RINGZERO
12636
12637typedef struct DIJOYSTATE {
12638    LONG    lX;
12639    LONG    lY;
12640    LONG    lZ;
12641    LONG    lRx;
12642    LONG    lRy;
12643    LONG    lRz;
12644    LONG    rglSlider[2];
12645    DWORD   rgdwPOV[4];
12646    BYTE    rgbButtons[32];
12647} DIJOYSTATE, *LPDIJOYSTATE;
12648
12649typedef struct DIJOYSTATE2 {
12650    LONG    lX;
12651    LONG    lY;
12652    LONG    lZ;
12653    LONG    lRx;
12654    LONG    lRy;
12655    LONG    lRz;
12656    LONG    rglSlider[2];
12657    DWORD   rgdwPOV[4];
12658    BYTE    rgbButtons[128];
12659    LONG    lVX;
12660    LONG    lVY;
12661    LONG    lVZ;
12662    LONG    lVRx;
12663    LONG    lVRy;
12664    LONG    lVRz;
12665    LONG    rglVSlider[2];
12666    LONG    lAX;
12667    LONG    lAY;
12668    LONG    lAZ;
12669    LONG    lARx;
12670    LONG    lARy;
12671    LONG    lARz;
12672    LONG    rglASlider[2];
12673    LONG    lFX;
12674    LONG    lFY;
12675    LONG    lFZ;
12676    LONG    lFRx;
12677    LONG    lFRy;
12678    LONG    lFRz;
12679    LONG    rglFSlider[2];
12680} DIJOYSTATE2, *LPDIJOYSTATE2;
12681
12682#define DIJOFS_X            FIELD_OFFSET(DIJOYSTATE, lX)
12683#define DIJOFS_Y            FIELD_OFFSET(DIJOYSTATE, lY)
12684#define DIJOFS_Z            FIELD_OFFSET(DIJOYSTATE, lZ)
12685#define DIJOFS_RX           FIELD_OFFSET(DIJOYSTATE, lRx)
12686#define DIJOFS_RY           FIELD_OFFSET(DIJOYSTATE, lRy)
12687#define DIJOFS_RZ           FIELD_OFFSET(DIJOYSTATE, lRz)
12688#define DIJOFS_SLIDER(n)   (FIELD_OFFSET(DIJOYSTATE, rglSlider) + \
12689                                                        (n) * sizeof(LONG))
12690#define DIJOFS_POV(n)      (FIELD_OFFSET(DIJOYSTATE, rgdwPOV) + \
12691                                                        (n) * sizeof(DWORD))
12692#define DIJOFS_BUTTON(n)   (FIELD_OFFSET(DIJOYSTATE, rgbButtons) + (n))
12693#define DIJOFS_BUTTON0      DIJOFS_BUTTON(0)
12694#define DIJOFS_BUTTON1      DIJOFS_BUTTON(1)
12695#define DIJOFS_BUTTON2      DIJOFS_BUTTON(2)
12696#define DIJOFS_BUTTON3      DIJOFS_BUTTON(3)
12697#define DIJOFS_BUTTON4      DIJOFS_BUTTON(4)
12698#define DIJOFS_BUTTON5      DIJOFS_BUTTON(5)
12699#define DIJOFS_BUTTON6      DIJOFS_BUTTON(6)
12700#define DIJOFS_BUTTON7      DIJOFS_BUTTON(7)
12701#define DIJOFS_BUTTON8      DIJOFS_BUTTON(8)
12702#define DIJOFS_BUTTON9      DIJOFS_BUTTON(9)
12703#define DIJOFS_BUTTON10     DIJOFS_BUTTON(10)
12704#define DIJOFS_BUTTON11     DIJOFS_BUTTON(11)
12705#define DIJOFS_BUTTON12     DIJOFS_BUTTON(12)
12706#define DIJOFS_BUTTON13     DIJOFS_BUTTON(13)
12707#define DIJOFS_BUTTON14     DIJOFS_BUTTON(14)
12708#define DIJOFS_BUTTON15     DIJOFS_BUTTON(15)
12709#define DIJOFS_BUTTON16     DIJOFS_BUTTON(16)
12710#define DIJOFS_BUTTON17     DIJOFS_BUTTON(17)
12711#define DIJOFS_BUTTON18     DIJOFS_BUTTON(18)
12712#define DIJOFS_BUTTON19     DIJOFS_BUTTON(19)
12713#define DIJOFS_BUTTON20     DIJOFS_BUTTON(20)
12714#define DIJOFS_BUTTON21     DIJOFS_BUTTON(21)
12715#define DIJOFS_BUTTON22     DIJOFS_BUTTON(22)
12716#define DIJOFS_BUTTON23     DIJOFS_BUTTON(23)
12717#define DIJOFS_BUTTON24     DIJOFS_BUTTON(24)
12718#define DIJOFS_BUTTON25     DIJOFS_BUTTON(25)
12719#define DIJOFS_BUTTON26     DIJOFS_BUTTON(26)
12720#define DIJOFS_BUTTON27     DIJOFS_BUTTON(27)
12721#define DIJOFS_BUTTON28     DIJOFS_BUTTON(28)
12722#define DIJOFS_BUTTON29     DIJOFS_BUTTON(29)
12723#define DIJOFS_BUTTON30     DIJOFS_BUTTON(30)
12724#define DIJOFS_BUTTON31     DIJOFS_BUTTON(31)
12725
12726#endif
12727
12728#ifndef DIJ_RINGZERO
12729
12730#define DIENUM_STOP             0
12731#define DIENUM_CONTINUE         1
12732
12733typedef BOOL (FAR PASCAL * LPDIENUMDEVICESCALLBACKA)(LPCDIDEVICEINSTANCEA, LPVOID);
12734typedef BOOL (FAR PASCAL * LPDIENUMDEVICESCALLBACKW)(LPCDIDEVICEINSTANCEW, LPVOID);
12735#ifdef UNICODE
12736#define LPDIENUMDEVICESCALLBACK  LPDIENUMDEVICESCALLBACKW
12737#else
12738#define LPDIENUMDEVICESCALLBACK  LPDIENUMDEVICESCALLBACKA
12739#endif
12740typedef BOOL (FAR PASCAL * LPDICONFIGUREDEVICESCALLBACK)(IUnknown FAR *, LPVOID);
12741
12742#define DIEDFL_ALLDEVICES       0x00000000
12743#define DIEDFL_ATTACHEDONLY     0x00000001
12744#if(DIRECTINPUT_VERSION >= 0x0500)
12745#define DIEDFL_FORCEFEEDBACK    0x00000100
12746#endif
12747#if(DIRECTINPUT_VERSION >= 0x050a)
12748#define DIEDFL_INCLUDEALIASES   0x00010000
12749#define DIEDFL_INCLUDEPHANTOMS  0x00020000
12750#endif
12751#if(DIRECTINPUT_VERSION >= 0x0800)
12752#define DIEDFL_INCLUDEHIDDEN    0x00040000
12753#endif
12754
12755#if(DIRECTINPUT_VERSION >= 0x0800)
12756typedef BOOL (FAR PASCAL * LPDIENUMDEVICESBYSEMANTICSCBA)(LPCDIDEVICEINSTANCEA, LPDIRECTINPUTDEVICE8A, DWORD, DWORD, LPVOID);
12757typedef BOOL (FAR PASCAL * LPDIENUMDEVICESBYSEMANTICSCBW)(LPCDIDEVICEINSTANCEW, LPDIRECTINPUTDEVICE8W, DWORD, DWORD, LPVOID);
12758#ifdef UNICODE
12759#define LPDIENUMDEVICESBYSEMANTICSCB  LPDIENUMDEVICESBYSEMANTICSCBW
12760#else
12761#define LPDIENUMDEVICESBYSEMANTICSCB  LPDIENUMDEVICESBYSEMANTICSCBA
12762#endif
12763#endif
12764
12765#if(DIRECTINPUT_VERSION >= 0x0800)
12766#define DIEDBS_MAPPEDPRI1         0x00000001
12767#define DIEDBS_MAPPEDPRI2         0x00000002
12768#define DIEDBS_RECENTDEVICE       0x00000010
12769#define DIEDBS_NEWDEVICE          0x00000020
12770#endif
12771
12772#if(DIRECTINPUT_VERSION >= 0x0800)
12773#define DIEDBSFL_ATTACHEDONLY       0x00000000
12774#define DIEDBSFL_THISUSER           0x00000010
12775#define DIEDBSFL_FORCEFEEDBACK      DIEDFL_FORCEFEEDBACK
12776#define DIEDBSFL_AVAILABLEDEVICES   0x00001000
12777#define DIEDBSFL_MULTIMICEKEYBOARDS 0x00002000
12778#define DIEDBSFL_NONGAMINGDEVICES   0x00004000
12779#define DIEDBSFL_VALID              0x00007110
12780#endif
12781
12782#undef INTERFACE
12783#define INTERFACE IDirectInputW
12784
12785DECLARE_INTERFACE_(IDirectInputW, IUnknown)
12786{
12787
12788    STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
12789    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
12790    STDMETHOD_(ULONG,Release)(THIS) PURE;
12791
12792    STDMETHOD(CreateDevice)(THIS_ REFGUID,LPDIRECTINPUTDEVICEW *,LPUNKNOWN) PURE;
12793    STDMETHOD(EnumDevices)(THIS_ DWORD,LPDIENUMDEVICESCALLBACKW,LPVOID,DWORD) PURE;
12794    STDMETHOD(GetDeviceStatus)(THIS_ REFGUID) PURE;
12795    STDMETHOD(RunControlPanel)(THIS_ HWND,DWORD) PURE;
12796    STDMETHOD(Initialize)(THIS_ HINSTANCE,DWORD) PURE;
12797};
12798
12799typedef struct IDirectInputW *LPDIRECTINPUTW;
12800
12801#undef INTERFACE
12802#define INTERFACE IDirectInputA
12803
12804DECLARE_INTERFACE_(IDirectInputA, IUnknown)
12805{
12806
12807    STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
12808    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
12809    STDMETHOD_(ULONG,Release)(THIS) PURE;
12810
12811    STDMETHOD(CreateDevice)(THIS_ REFGUID,LPDIRECTINPUTDEVICEA *,LPUNKNOWN) PURE;
12812    STDMETHOD(EnumDevices)(THIS_ DWORD,LPDIENUMDEVICESCALLBACKA,LPVOID,DWORD) PURE;
12813    STDMETHOD(GetDeviceStatus)(THIS_ REFGUID) PURE;
12814    STDMETHOD(RunControlPanel)(THIS_ HWND,DWORD) PURE;
12815    STDMETHOD(Initialize)(THIS_ HINSTANCE,DWORD) PURE;
12816};
12817
12818typedef struct IDirectInputA *LPDIRECTINPUTA;
12819
12820#ifdef UNICODE
12821#define IID_IDirectInput IID_IDirectInputW
12822#define IDirectInput IDirectInputW
12823#define IDirectInputVtbl IDirectInputWVtbl
12824#else
12825#define IID_IDirectInput IID_IDirectInputA
12826#define IDirectInput IDirectInputA
12827#define IDirectInputVtbl IDirectInputAVtbl
12828#endif
12829typedef struct IDirectInput *LPDIRECTINPUT;
12830
12831#if !defined(__cplusplus) || defined(CINTERFACE)
12832#define IDirectInput_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
12833#define IDirectInput_AddRef(p) (p)->lpVtbl->AddRef(p)
12834#define IDirectInput_Release(p) (p)->lpVtbl->Release(p)
12835#define IDirectInput_CreateDevice(p,a,b,c) (p)->lpVtbl->CreateDevice(p,a,b,c)
12836#define IDirectInput_EnumDevices(p,a,b,c,d) (p)->lpVtbl->EnumDevices(p,a,b,c,d)
12837#define IDirectInput_GetDeviceStatus(p,a) (p)->lpVtbl->GetDeviceStatus(p,a)
12838#define IDirectInput_RunControlPanel(p,a,b) (p)->lpVtbl->RunControlPanel(p,a,b)
12839#define IDirectInput_Initialize(p,a,b) (p)->lpVtbl->Initialize(p,a,b)
12840#else
12841#define IDirectInput_QueryInterface(p,a,b) (p)->QueryInterface(a,b)
12842#define IDirectInput_AddRef(p) (p)->AddRef()
12843#define IDirectInput_Release(p) (p)->Release()
12844#define IDirectInput_CreateDevice(p,a,b,c) (p)->CreateDevice(a,b,c)
12845#define IDirectInput_EnumDevices(p,a,b,c,d) (p)->EnumDevices(a,b,c,d)
12846#define IDirectInput_GetDeviceStatus(p,a) (p)->GetDeviceStatus(a)
12847#define IDirectInput_RunControlPanel(p,a,b) (p)->RunControlPanel(a,b)
12848#define IDirectInput_Initialize(p,a,b) (p)->Initialize(a,b)
12849#endif
12850
12851#undef INTERFACE
12852#define INTERFACE IDirectInput2W
12853
12854DECLARE_INTERFACE_(IDirectInput2W, IDirectInputW)
12855{
12856
12857    STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
12858    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
12859    STDMETHOD_(ULONG,Release)(THIS) PURE;
12860
12861    STDMETHOD(CreateDevice)(THIS_ REFGUID,LPDIRECTINPUTDEVICEW *,LPUNKNOWN) PURE;
12862    STDMETHOD(EnumDevices)(THIS_ DWORD,LPDIENUMDEVICESCALLBACKW,LPVOID,DWORD) PURE;
12863    STDMETHOD(GetDeviceStatus)(THIS_ REFGUID) PURE;
12864    STDMETHOD(RunControlPanel)(THIS_ HWND,DWORD) PURE;
12865    STDMETHOD(Initialize)(THIS_ HINSTANCE,DWORD) PURE;
12866
12867    STDMETHOD(FindDevice)(THIS_ REFGUID,LPCWSTR,LPGUID) PURE;
12868};
12869
12870typedef struct IDirectInput2W *LPDIRECTINPUT2W;
12871
12872#undef INTERFACE
12873#define INTERFACE IDirectInput2A
12874
12875DECLARE_INTERFACE_(IDirectInput2A, IDirectInputA)
12876{
12877
12878    STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
12879    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
12880    STDMETHOD_(ULONG,Release)(THIS) PURE;
12881
12882    STDMETHOD(CreateDevice)(THIS_ REFGUID,LPDIRECTINPUTDEVICEA *,LPUNKNOWN) PURE;
12883    STDMETHOD(EnumDevices)(THIS_ DWORD,LPDIENUMDEVICESCALLBACKA,LPVOID,DWORD) PURE;
12884    STDMETHOD(GetDeviceStatus)(THIS_ REFGUID) PURE;
12885    STDMETHOD(RunControlPanel)(THIS_ HWND,DWORD) PURE;
12886    STDMETHOD(Initialize)(THIS_ HINSTANCE,DWORD) PURE;
12887
12888    STDMETHOD(FindDevice)(THIS_ REFGUID,LPCSTR,LPGUID) PURE;
12889};
12890
12891typedef struct IDirectInput2A *LPDIRECTINPUT2A;
12892
12893#ifdef UNICODE
12894#define IID_IDirectInput2 IID_IDirectInput2W
12895#define IDirectInput2 IDirectInput2W
12896#define IDirectInput2Vtbl IDirectInput2WVtbl
12897#else
12898#define IID_IDirectInput2 IID_IDirectInput2A
12899#define IDirectInput2 IDirectInput2A
12900#define IDirectInput2Vtbl IDirectInput2AVtbl
12901#endif
12902typedef struct IDirectInput2 *LPDIRECTINPUT2;
12903
12904#if !defined(__cplusplus) || defined(CINTERFACE)
12905#define IDirectInput2_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
12906#define IDirectInput2_AddRef(p) (p)->lpVtbl->AddRef(p)
12907#define IDirectInput2_Release(p) (p)->lpVtbl->Release(p)
12908#define IDirectInput2_CreateDevice(p,a,b,c) (p)->lpVtbl->CreateDevice(p,a,b,c)
12909#define IDirectInput2_EnumDevices(p,a,b,c,d) (p)->lpVtbl->EnumDevices(p,a,b,c,d)
12910#define IDirectInput2_GetDeviceStatus(p,a) (p)->lpVtbl->GetDeviceStatus(p,a)
12911#define IDirectInput2_RunControlPanel(p,a,b) (p)->lpVtbl->RunControlPanel(p,a,b)
12912#define IDirectInput2_Initialize(p,a,b) (p)->lpVtbl->Initialize(p,a,b)
12913#define IDirectInput2_FindDevice(p,a,b,c) (p)->lpVtbl->FindDevice(p,a,b,c)
12914#else
12915#define IDirectInput2_QueryInterface(p,a,b) (p)->QueryInterface(a,b)
12916#define IDirectInput2_AddRef(p) (p)->AddRef()
12917#define IDirectInput2_Release(p) (p)->Release()
12918#define IDirectInput2_CreateDevice(p,a,b,c) (p)->CreateDevice(a,b,c)
12919#define IDirectInput2_EnumDevices(p,a,b,c,d) (p)->EnumDevices(a,b,c,d)
12920#define IDirectInput2_GetDeviceStatus(p,a) (p)->GetDeviceStatus(a)
12921#define IDirectInput2_RunControlPanel(p,a,b) (p)->RunControlPanel(a,b)
12922#define IDirectInput2_Initialize(p,a,b) (p)->Initialize(a,b)
12923#define IDirectInput2_FindDevice(p,a,b,c) (p)->FindDevice(a,b,c)
12924#endif
12925
12926#undef INTERFACE
12927#define INTERFACE IDirectInput7W
12928
12929DECLARE_INTERFACE_(IDirectInput7W, IDirectInput2W)
12930{
12931
12932    STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
12933    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
12934    STDMETHOD_(ULONG,Release)(THIS) PURE;
12935
12936    STDMETHOD(CreateDevice)(THIS_ REFGUID,LPDIRECTINPUTDEVICEW *,LPUNKNOWN) PURE;
12937    STDMETHOD(EnumDevices)(THIS_ DWORD,LPDIENUMDEVICESCALLBACKW,LPVOID,DWORD) PURE;
12938    STDMETHOD(GetDeviceStatus)(THIS_ REFGUID) PURE;
12939    STDMETHOD(RunControlPanel)(THIS_ HWND,DWORD) PURE;
12940    STDMETHOD(Initialize)(THIS_ HINSTANCE,DWORD) PURE;
12941    STDMETHOD(FindDevice)(THIS_ REFGUID,LPCWSTR,LPGUID) PURE;
12942
12943    STDMETHOD(CreateDeviceEx)(THIS_ REFGUID,REFIID,LPVOID *,LPUNKNOWN) PURE;
12944};
12945
12946typedef struct IDirectInput7W *LPDIRECTINPUT7W;
12947
12948#undef INTERFACE
12949#define INTERFACE IDirectInput7A
12950
12951DECLARE_INTERFACE_(IDirectInput7A, IDirectInput2A)
12952{
12953
12954    STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
12955    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
12956    STDMETHOD_(ULONG,Release)(THIS) PURE;
12957
12958    STDMETHOD(CreateDevice)(THIS_ REFGUID,LPDIRECTINPUTDEVICEA *,LPUNKNOWN) PURE;
12959    STDMETHOD(EnumDevices)(THIS_ DWORD,LPDIENUMDEVICESCALLBACKA,LPVOID,DWORD) PURE;
12960    STDMETHOD(GetDeviceStatus)(THIS_ REFGUID) PURE;
12961    STDMETHOD(RunControlPanel)(THIS_ HWND,DWORD) PURE;
12962    STDMETHOD(Initialize)(THIS_ HINSTANCE,DWORD) PURE;
12963    STDMETHOD(FindDevice)(THIS_ REFGUID,LPCSTR,LPGUID) PURE;
12964
12965    STDMETHOD(CreateDeviceEx)(THIS_ REFGUID,REFIID,LPVOID *,LPUNKNOWN) PURE;
12966};
12967
12968typedef struct IDirectInput7A *LPDIRECTINPUT7A;
12969
12970#ifdef UNICODE
12971#define IID_IDirectInput7 IID_IDirectInput7W
12972#define IDirectInput7 IDirectInput7W
12973#define IDirectInput7Vtbl IDirectInput7WVtbl
12974#else
12975#define IID_IDirectInput7 IID_IDirectInput7A
12976#define IDirectInput7 IDirectInput7A
12977#define IDirectInput7Vtbl IDirectInput7AVtbl
12978#endif
12979typedef struct IDirectInput7 *LPDIRECTINPUT7;
12980
12981#if !defined(__cplusplus) || defined(CINTERFACE)
12982#define IDirectInput7_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
12983#define IDirectInput7_AddRef(p) (p)->lpVtbl->AddRef(p)
12984#define IDirectInput7_Release(p) (p)->lpVtbl->Release(p)
12985#define IDirectInput7_CreateDevice(p,a,b,c) (p)->lpVtbl->CreateDevice(p,a,b,c)
12986#define IDirectInput7_EnumDevices(p,a,b,c,d) (p)->lpVtbl->EnumDevices(p,a,b,c,d)
12987#define IDirectInput7_GetDeviceStatus(p,a) (p)->lpVtbl->GetDeviceStatus(p,a)
12988#define IDirectInput7_RunControlPanel(p,a,b) (p)->lpVtbl->RunControlPanel(p,a,b)
12989#define IDirectInput7_Initialize(p,a,b) (p)->lpVtbl->Initialize(p,a,b)
12990#define IDirectInput7_FindDevice(p,a,b,c) (p)->lpVtbl->FindDevice(p,a,b,c)
12991#define IDirectInput7_CreateDeviceEx(p,a,b,c,d) (p)->lpVtbl->CreateDeviceEx(p,a,b,c,d)
12992#else
12993#define IDirectInput7_QueryInterface(p,a,b) (p)->QueryInterface(a,b)
12994#define IDirectInput7_AddRef(p) (p)->AddRef()
12995#define IDirectInput7_Release(p) (p)->Release()
12996#define IDirectInput7_CreateDevice(p,a,b,c) (p)->CreateDevice(a,b,c)
12997#define IDirectInput7_EnumDevices(p,a,b,c,d) (p)->EnumDevices(a,b,c,d)
12998#define IDirectInput7_GetDeviceStatus(p,a) (p)->GetDeviceStatus(a)
12999#define IDirectInput7_RunControlPanel(p,a,b) (p)->RunControlPanel(a,b)
13000#define IDirectInput7_Initialize(p,a,b) (p)->Initialize(a,b)
13001#define IDirectInput7_FindDevice(p,a,b,c) (p)->FindDevice(a,b,c)
13002#define IDirectInput7_CreateDeviceEx(p,a,b,c,d) (p)->CreateDeviceEx(a,b,c,d)
13003#endif
13004
13005#if(DIRECTINPUT_VERSION >= 0x0800)
13006#undef INTERFACE
13007#define INTERFACE IDirectInput8W
13008
13009DECLARE_INTERFACE_(IDirectInput8W, IUnknown)
13010{
13011
13012    STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
13013    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
13014    STDMETHOD_(ULONG,Release)(THIS) PURE;
13015
13016    STDMETHOD(CreateDevice)(THIS_ REFGUID,LPDIRECTINPUTDEVICE8W *,LPUNKNOWN) PURE;
13017    STDMETHOD(EnumDevices)(THIS_ DWORD,LPDIENUMDEVICESCALLBACKW,LPVOID,DWORD) PURE;
13018    STDMETHOD(GetDeviceStatus)(THIS_ REFGUID) PURE;
13019    STDMETHOD(RunControlPanel)(THIS_ HWND,DWORD) PURE;
13020    STDMETHOD(Initialize)(THIS_ HINSTANCE,DWORD) PURE;
13021    STDMETHOD(FindDevice)(THIS_ REFGUID,LPCWSTR,LPGUID) PURE;
13022    STDMETHOD(EnumDevicesBySemantics)(THIS_ LPCWSTR,LPDIACTIONFORMATW,LPDIENUMDEVICESBYSEMANTICSCBW,LPVOID,DWORD) PURE;
13023    STDMETHOD(ConfigureDevices)(THIS_ LPDICONFIGUREDEVICESCALLBACK,LPDICONFIGUREDEVICESPARAMSW,DWORD,LPVOID) PURE;
13024};
13025
13026typedef struct IDirectInput8W *LPDIRECTINPUT8W;
13027
13028#undef INTERFACE
13029#define INTERFACE IDirectInput8A
13030
13031DECLARE_INTERFACE_(IDirectInput8A, IUnknown)
13032{
13033
13034    STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
13035    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
13036    STDMETHOD_(ULONG,Release)(THIS) PURE;
13037
13038    STDMETHOD(CreateDevice)(THIS_ REFGUID,LPDIRECTINPUTDEVICE8A *,LPUNKNOWN) PURE;
13039    STDMETHOD(EnumDevices)(THIS_ DWORD,LPDIENUMDEVICESCALLBACKA,LPVOID,DWORD) PURE;
13040    STDMETHOD(GetDeviceStatus)(THIS_ REFGUID) PURE;
13041    STDMETHOD(RunControlPanel)(THIS_ HWND,DWORD) PURE;
13042    STDMETHOD(Initialize)(THIS_ HINSTANCE,DWORD) PURE;
13043    STDMETHOD(FindDevice)(THIS_ REFGUID,LPCSTR,LPGUID) PURE;
13044    STDMETHOD(EnumDevicesBySemantics)(THIS_ LPCSTR,LPDIACTIONFORMATA,LPDIENUMDEVICESBYSEMANTICSCBA,LPVOID,DWORD) PURE;
13045    STDMETHOD(ConfigureDevices)(THIS_ LPDICONFIGUREDEVICESCALLBACK,LPDICONFIGUREDEVICESPARAMSA,DWORD,LPVOID) PURE;
13046};
13047
13048typedef struct IDirectInput8A *LPDIRECTINPUT8A;
13049
13050#ifdef UNICODE
13051#define IID_IDirectInput8 IID_IDirectInput8W
13052#define IDirectInput8 IDirectInput8W
13053#define IDirectInput8Vtbl IDirectInput8WVtbl
13054#else
13055#define IID_IDirectInput8 IID_IDirectInput8A
13056#define IDirectInput8 IDirectInput8A
13057#define IDirectInput8Vtbl IDirectInput8AVtbl
13058#endif
13059typedef struct IDirectInput8 *LPDIRECTINPUT8;
13060
13061#if !defined(__cplusplus) || defined(CINTERFACE)
13062#define IDirectInput8_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
13063#define IDirectInput8_AddRef(p) (p)->lpVtbl->AddRef(p)
13064#define IDirectInput8_Release(p) (p)->lpVtbl->Release(p)
13065#define IDirectInput8_CreateDevice(p,a,b,c) (p)->lpVtbl->CreateDevice(p,a,b,c)
13066#define IDirectInput8_EnumDevices(p,a,b,c,d) (p)->lpVtbl->EnumDevices(p,a,b,c,d)
13067#define IDirectInput8_GetDeviceStatus(p,a) (p)->lpVtbl->GetDeviceStatus(p,a)
13068#define IDirectInput8_RunControlPanel(p,a,b) (p)->lpVtbl->RunControlPanel(p,a,b)
13069#define IDirectInput8_Initialize(p,a,b) (p)->lpVtbl->Initialize(p,a,b)
13070#define IDirectInput8_FindDevice(p,a,b,c) (p)->lpVtbl->FindDevice(p,a,b,c)
13071#define IDirectInput8_EnumDevicesBySemantics(p,a,b,c,d,e) (p)->lpVtbl->EnumDevicesBySemantics(p,a,b,c,d,e)
13072#define IDirectInput8_ConfigureDevices(p,a,b,c,d) (p)->lpVtbl->ConfigureDevices(p,a,b,c,d)
13073#else
13074#define IDirectInput8_QueryInterface(p,a,b) (p)->QueryInterface(a,b)
13075#define IDirectInput8_AddRef(p) (p)->AddRef()
13076#define IDirectInput8_Release(p) (p)->Release()
13077#define IDirectInput8_CreateDevice(p,a,b,c) (p)->CreateDevice(a,b,c)
13078#define IDirectInput8_EnumDevices(p,a,b,c,d) (p)->EnumDevices(a,b,c,d)
13079#define IDirectInput8_GetDeviceStatus(p,a) (p)->GetDeviceStatus(a)
13080#define IDirectInput8_RunControlPanel(p,a,b) (p)->RunControlPanel(a,b)
13081#define IDirectInput8_Initialize(p,a,b) (p)->Initialize(a,b)
13082#define IDirectInput8_FindDevice(p,a,b,c) (p)->FindDevice(a,b,c)
13083#define IDirectInput8_EnumDevicesBySemantics(p,a,b,c,d,e) (p)->EnumDevicesBySemantics(a,b,c,d,e)
13084#define IDirectInput8_ConfigureDevices(p,a,b,c,d) (p)->ConfigureDevices(a,b,c,d)
13085#endif
13086#endif
13087
13088#if DIRECTINPUT_VERSION > 0x0700
13089
13090extern HRESULT WINAPI DirectInput8Create(HINSTANCE hinst, DWORD dwVersion, REFIID riidltf, LPVOID *ppvOut, LPUNKNOWN punkOuter);
13091
13092#else
13093extern HRESULT WINAPI DirectInputCreateA(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUTA *ppDI, LPUNKNOWN punkOuter);
13094extern HRESULT WINAPI DirectInputCreateW(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUTW *ppDI, LPUNKNOWN punkOuter);
13095#ifdef UNICODE
13096#define DirectInputCreate  DirectInputCreateW
13097#else
13098#define DirectInputCreate  DirectInputCreateA
13099#endif
13100
13101extern HRESULT WINAPI DirectInputCreateEx(HINSTANCE hinst, DWORD dwVersion, REFIID riidltf, LPVOID *ppvOut, LPUNKNOWN punkOuter);
13102
13103#endif
13104
13105#endif
13106
13107#define DI_OK                           S_OK
13108
13109#define DI_NOTATTACHED                  S_FALSE
13110
13111#define DI_BUFFEROVERFLOW               S_FALSE
13112
13113#define DI_PROPNOEFFECT                 S_FALSE
13114
13115#define DI_NOEFFECT                     S_FALSE
13116
13117#define DI_POLLEDDEVICE                 ((HRESULT)0x00000002L)
13118
13119#define DI_DOWNLOADSKIPPED              ((HRESULT)0x00000003L)
13120
13121#define DI_EFFECTRESTARTED              ((HRESULT)0x00000004L)
13122
13123#define DI_TRUNCATED                    ((HRESULT)0x00000008L)
13124
13125#define DI_SETTINGSNOTSAVED				((HRESULT)0x0000000BL)
13126
13127#define DI_TRUNCATEDANDRESTARTED        ((HRESULT)0x0000000CL)
13128
13129#define DI_WRITEPROTECT                 ((HRESULT)0x00000013L)
13130
13131#define DIERR_OLDDIRECTINPUTVERSION     \
13132    MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_OLD_WIN_VERSION)
13133
13134#define DIERR_BETADIRECTINPUTVERSION    \
13135    MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_RMODE_APP)
13136
13137#define DIERR_BADDRIVERVER              \
13138    MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_BAD_DRIVER_LEVEL)
13139
13140#define DIERR_DEVICENOTREG              REGDB_E_CLASSNOTREG
13141
13142#define DIERR_NOTFOUND                  \
13143    MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_FILE_NOT_FOUND)
13144
13145#define DIERR_OBJECTNOTFOUND            \
13146    MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_FILE_NOT_FOUND)
13147
13148#define DIERR_INVALIDPARAM              E_INVALIDARG
13149
13150#define DIERR_NOINTERFACE               E_NOINTERFACE
13151
13152#define DIERR_GENERIC                   E_FAIL
13153
13154#define DIERR_OUTOFMEMORY               E_OUTOFMEMORY
13155
13156#define DIERR_UNSUPPORTED               E_NOTIMPL
13157
13158#define DIERR_NOTINITIALIZED            \
13159    MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_NOT_READY)
13160
13161#define DIERR_ALREADYINITIALIZED        \
13162    MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_ALREADY_INITIALIZED)
13163
13164#define DIERR_NOAGGREGATION             CLASS_E_NOAGGREGATION
13165
13166#define DIERR_OTHERAPPHASPRIO           E_ACCESSDENIED
13167
13168#define DIERR_INPUTLOST                 \
13169    MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_READ_FAULT)
13170
13171#define DIERR_ACQUIRED                  \
13172    MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_BUSY)
13173
13174#define DIERR_NOTACQUIRED               \
13175    MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_INVALID_ACCESS)
13176
13177#define DIERR_READONLY                  E_ACCESSDENIED
13178
13179#define DIERR_HANDLEEXISTS              E_ACCESSDENIED
13180
13181#ifndef E_PENDING
13182#define E_PENDING                       0x8000000AL
13183#endif
13184
13185#define DIERR_INSUFFICIENTPRIVS         0x80040200L
13186
13187#define DIERR_DEVICEFULL                0x80040201L
13188
13189#define DIERR_MOREDATA                  0x80040202L
13190
13191#define DIERR_NOTDOWNLOADED             0x80040203L
13192
13193#define DIERR_HASEFFECTS                0x80040204L
13194
13195#define DIERR_NOTEXCLUSIVEACQUIRED      0x80040205L
13196
13197#define DIERR_INCOMPLETEEFFECT          0x80040206L
13198
13199#define DIERR_NOTBUFFERED               0x80040207L
13200
13201#define DIERR_EFFECTPLAYING             0x80040208L
13202
13203#define DIERR_UNPLUGGED                 0x80040209L
13204
13205#define DIERR_REPORTFULL                0x8004020AL
13206
13207#define DIERR_MAPFILEFAIL               0x8004020BL
13208
13209#define DIKEYBOARD_ESCAPE                       0x81000401
13210#define DIKEYBOARD_1                            0x81000402
13211#define DIKEYBOARD_2                            0x81000403
13212#define DIKEYBOARD_3                            0x81000404
13213#define DIKEYBOARD_4                            0x81000405
13214#define DIKEYBOARD_5                            0x81000406
13215#define DIKEYBOARD_6                            0x81000407
13216#define DIKEYBOARD_7                            0x81000408
13217#define DIKEYBOARD_8                            0x81000409
13218#define DIKEYBOARD_9                            0x8100040A
13219#define DIKEYBOARD_0                            0x8100040B
13220#define DIKEYBOARD_MINUS                        0x8100040C
13221#define DIKEYBOARD_EQUALS                       0x8100040D
13222#define DIKEYBOARD_BACK                         0x8100040E
13223#define DIKEYBOARD_TAB                          0x8100040F
13224#define DIKEYBOARD_Q                            0x81000410
13225#define DIKEYBOARD_W                            0x81000411
13226#define DIKEYBOARD_E                            0x81000412
13227#define DIKEYBOARD_R                            0x81000413
13228#define DIKEYBOARD_T                            0x81000414
13229#define DIKEYBOARD_Y                            0x81000415
13230#define DIKEYBOARD_U                            0x81000416
13231#define DIKEYBOARD_I                            0x81000417
13232#define DIKEYBOARD_O                            0x81000418
13233#define DIKEYBOARD_P                            0x81000419
13234#define DIKEYBOARD_LBRACKET                     0x8100041A
13235#define DIKEYBOARD_RBRACKET                     0x8100041B
13236#define DIKEYBOARD_RETURN                       0x8100041C
13237#define DIKEYBOARD_LCONTROL                     0x8100041D
13238#define DIKEYBOARD_A                            0x8100041E
13239#define DIKEYBOARD_S                            0x8100041F
13240#define DIKEYBOARD_D                            0x81000420
13241#define DIKEYBOARD_F                            0x81000421
13242#define DIKEYBOARD_G                            0x81000422
13243#define DIKEYBOARD_H                            0x81000423
13244#define DIKEYBOARD_J                            0x81000424
13245#define DIKEYBOARD_K                            0x81000425
13246#define DIKEYBOARD_L                            0x81000426
13247#define DIKEYBOARD_SEMICOLON                    0x81000427
13248#define DIKEYBOARD_APOSTROPHE                   0x81000428
13249#define DIKEYBOARD_GRAVE                        0x81000429
13250#define DIKEYBOARD_LSHIFT                       0x8100042A
13251#define DIKEYBOARD_BACKSLASH                    0x8100042B
13252#define DIKEYBOARD_Z                            0x8100042C
13253#define DIKEYBOARD_X                            0x8100042D
13254#define DIKEYBOARD_C                            0x8100042E
13255#define DIKEYBOARD_V                            0x8100042F
13256#define DIKEYBOARD_B                            0x81000430
13257#define DIKEYBOARD_N                            0x81000431
13258#define DIKEYBOARD_M                            0x81000432
13259#define DIKEYBOARD_COMMA                        0x81000433
13260#define DIKEYBOARD_PERIOD                       0x81000434
13261#define DIKEYBOARD_SLASH                        0x81000435
13262#define DIKEYBOARD_RSHIFT                       0x81000436
13263#define DIKEYBOARD_MULTIPLY                     0x81000437
13264#define DIKEYBOARD_LMENU                        0x81000438
13265#define DIKEYBOARD_SPACE                        0x81000439
13266#define DIKEYBOARD_CAPITAL                      0x8100043A
13267#define DIKEYBOARD_F1                           0x8100043B
13268#define DIKEYBOARD_F2                           0x8100043C
13269#define DIKEYBOARD_F3                           0x8100043D
13270#define DIKEYBOARD_F4                           0x8100043E
13271#define DIKEYBOARD_F5                           0x8100043F
13272#define DIKEYBOARD_F6                           0x81000440
13273#define DIKEYBOARD_F7                           0x81000441
13274#define DIKEYBOARD_F8                           0x81000442
13275#define DIKEYBOARD_F9                           0x81000443
13276#define DIKEYBOARD_F10                          0x81000444
13277#define DIKEYBOARD_NUMLOCK                      0x81000445
13278#define DIKEYBOARD_SCROLL                       0x81000446
13279#define DIKEYBOARD_NUMPAD7                      0x81000447
13280#define DIKEYBOARD_NUMPAD8                      0x81000448
13281#define DIKEYBOARD_NUMPAD9                      0x81000449
13282#define DIKEYBOARD_SUBTRACT                     0x8100044A
13283#define DIKEYBOARD_NUMPAD4                      0x8100044B
13284#define DIKEYBOARD_NUMPAD5                      0x8100044C
13285#define DIKEYBOARD_NUMPAD6                      0x8100044D
13286#define DIKEYBOARD_ADD                          0x8100044E
13287#define DIKEYBOARD_NUMPAD1                      0x8100044F
13288#define DIKEYBOARD_NUMPAD2                      0x81000450
13289#define DIKEYBOARD_NUMPAD3                      0x81000451
13290#define DIKEYBOARD_NUMPAD0                      0x81000452
13291#define DIKEYBOARD_DECIMAL                      0x81000453
13292#define DIKEYBOARD_OEM_102                      0x81000456
13293#define DIKEYBOARD_F11                          0x81000457
13294#define DIKEYBOARD_F12                          0x81000458
13295#define DIKEYBOARD_F13                          0x81000464
13296#define DIKEYBOARD_F14                          0x81000465
13297#define DIKEYBOARD_F15                          0x81000466
13298#define DIKEYBOARD_KANA                         0x81000470
13299#define DIKEYBOARD_ABNT_C1                      0x81000473
13300#define DIKEYBOARD_CONVERT                      0x81000479
13301#define DIKEYBOARD_NOCONVERT                    0x8100047B
13302#define DIKEYBOARD_YEN                          0x8100047D
13303#define DIKEYBOARD_ABNT_C2                      0x8100047E
13304#define DIKEYBOARD_NUMPADEQUALS                 0x8100048D
13305#define DIKEYBOARD_PREVTRACK                    0x81000490
13306#define DIKEYBOARD_AT                           0x81000491
13307#define DIKEYBOARD_COLON                        0x81000492
13308#define DIKEYBOARD_UNDERLINE                    0x81000493
13309#define DIKEYBOARD_KANJI                        0x81000494
13310#define DIKEYBOARD_STOP                         0x81000495
13311#define DIKEYBOARD_AX                           0x81000496
13312#define DIKEYBOARD_UNLABELED                    0x81000497
13313#define DIKEYBOARD_NEXTTRACK                    0x81000499
13314#define DIKEYBOARD_NUMPADENTER                  0x8100049C
13315#define DIKEYBOARD_RCONTROL                     0x8100049D
13316#define DIKEYBOARD_MUTE                         0x810004A0
13317#define DIKEYBOARD_CALCULATOR                   0x810004A1
13318#define DIKEYBOARD_PLAYPAUSE                    0x810004A2
13319#define DIKEYBOARD_MEDIASTOP                    0x810004A4
13320#define DIKEYBOARD_VOLUMEDOWN                   0x810004AE
13321#define DIKEYBOARD_VOLUMEUP                     0x810004B0
13322#define DIKEYBOARD_WEBHOME                      0x810004B2
13323#define DIKEYBOARD_NUMPADCOMMA                  0x810004B3
13324#define DIKEYBOARD_DIVIDE                       0x810004B5
13325#define DIKEYBOARD_SYSRQ                        0x810004B7
13326#define DIKEYBOARD_RMENU                        0x810004B8
13327#define DIKEYBOARD_PAUSE                        0x810004C5
13328#define DIKEYBOARD_HOME                         0x810004C7
13329#define DIKEYBOARD_UP                           0x810004C8
13330#define DIKEYBOARD_PRIOR                        0x810004C9
13331#define DIKEYBOARD_LEFT                         0x810004CB
13332#define DIKEYBOARD_RIGHT                        0x810004CD
13333#define DIKEYBOARD_END                          0x810004CF
13334#define DIKEYBOARD_DOWN                         0x810004D0
13335#define DIKEYBOARD_NEXT                         0x810004D1
13336#define DIKEYBOARD_INSERT                       0x810004D2
13337#define DIKEYBOARD_DELETE                       0x810004D3
13338#define DIKEYBOARD_LWIN                         0x810004DB
13339#define DIKEYBOARD_RWIN                         0x810004DC
13340#define DIKEYBOARD_APPS                         0x810004DD
13341#define DIKEYBOARD_POWER                        0x810004DE
13342#define DIKEYBOARD_SLEEP                        0x810004DF
13343#define DIKEYBOARD_WAKE                         0x810004E3
13344#define DIKEYBOARD_WEBSEARCH                    0x810004E5
13345#define DIKEYBOARD_WEBFAVORITES                 0x810004E6
13346#define DIKEYBOARD_WEBREFRESH                   0x810004E7
13347#define DIKEYBOARD_WEBSTOP                      0x810004E8
13348#define DIKEYBOARD_WEBFORWARD                   0x810004E9
13349#define DIKEYBOARD_WEBBACK                      0x810004EA
13350#define DIKEYBOARD_MYCOMPUTER                   0x810004EB
13351#define DIKEYBOARD_MAIL                         0x810004EC
13352#define DIKEYBOARD_MEDIASELECT                  0x810004ED
13353
13354#define DIMOUSE_XAXISAB                         (0x82000200 |DIMOFS_X )
13355#define DIMOUSE_YAXISAB                         (0x82000200 |DIMOFS_Y )
13356#define DIMOUSE_XAXIS                           (0x82000300 |DIMOFS_X )
13357#define DIMOUSE_YAXIS                           (0x82000300 |DIMOFS_Y )
13358#define DIMOUSE_WHEEL                           (0x82000300 |DIMOFS_Z )
13359#define DIMOUSE_BUTTON0                         (0x82000400 |DIMOFS_BUTTON0)
13360#define DIMOUSE_BUTTON1                         (0x82000400 |DIMOFS_BUTTON1)
13361#define DIMOUSE_BUTTON2                         (0x82000400 |DIMOFS_BUTTON2)
13362#define DIMOUSE_BUTTON3                         (0x82000400 |DIMOFS_BUTTON3)
13363#define DIMOUSE_BUTTON4                         (0x82000400 |DIMOFS_BUTTON4)
13364#define DIMOUSE_BUTTON5                         (0x82000400 |DIMOFS_BUTTON5)
13365#define DIMOUSE_BUTTON6                         (0x82000400 |DIMOFS_BUTTON6)
13366#define DIMOUSE_BUTTON7                         (0x82000400 |DIMOFS_BUTTON7)
13367
13368#define DIVOICE_CHANNEL1                        0x83000401
13369#define DIVOICE_CHANNEL2                        0x83000402
13370#define DIVOICE_CHANNEL3                        0x83000403
13371#define DIVOICE_CHANNEL4                        0x83000404
13372#define DIVOICE_CHANNEL5                        0x83000405
13373#define DIVOICE_CHANNEL6                        0x83000406
13374#define DIVOICE_CHANNEL7                        0x83000407
13375#define DIVOICE_CHANNEL8                        0x83000408
13376#define DIVOICE_TEAM                            0x83000409
13377#define DIVOICE_ALL                             0x8300040A
13378#define DIVOICE_RECORDMUTE                      0x8300040B
13379#define DIVOICE_PLAYBACKMUTE                    0x8300040C
13380#define DIVOICE_TRANSMIT                        0x8300040D
13381
13382#define DIVOICE_VOICECOMMAND                    0x83000410
13383
13384#define DIVIRTUAL_DRIVING_RACE                  0x01000000
13385#define DIAXIS_DRIVINGR_STEER                   0x01008A01
13386#define DIAXIS_DRIVINGR_ACCELERATE              0x01039202
13387#define DIAXIS_DRIVINGR_BRAKE                   0x01041203
13388#define DIBUTTON_DRIVINGR_SHIFTUP               0x01000C01
13389#define DIBUTTON_DRIVINGR_SHIFTDOWN             0x01000C02
13390#define DIBUTTON_DRIVINGR_VIEW                  0x01001C03
13391#define DIBUTTON_DRIVINGR_MENU                  0x010004FD
13392
13393#define DIAXIS_DRIVINGR_ACCEL_AND_BRAKE         0x01014A04
13394#define DIHATSWITCH_DRIVINGR_GLANCE             0x01004601
13395#define DIBUTTON_DRIVINGR_BRAKE                 0x01004C04
13396#define DIBUTTON_DRIVINGR_DASHBOARD             0x01004405
13397#define DIBUTTON_DRIVINGR_AIDS                  0x01004406
13398#define DIBUTTON_DRIVINGR_MAP                   0x01004407
13399#define DIBUTTON_DRIVINGR_BOOST                 0x01004408
13400#define DIBUTTON_DRIVINGR_PIT                   0x01004409
13401#define DIBUTTON_DRIVINGR_ACCELERATE_LINK       0x0103D4E0
13402#define DIBUTTON_DRIVINGR_STEER_LEFT_LINK       0x0100CCE4
13403#define DIBUTTON_DRIVINGR_STEER_RIGHT_LINK      0x0100CCEC
13404#define DIBUTTON_DRIVINGR_GLANCE_LEFT_LINK      0x0107C4E4
13405#define DIBUTTON_DRIVINGR_GLANCE_RIGHT_LINK     0x0107C4EC
13406#define DIBUTTON_DRIVINGR_DEVICE                0x010044FE
13407#define DIBUTTON_DRIVINGR_PAUSE                 0x010044FC
13408
13409#define DIVIRTUAL_DRIVING_COMBAT                0x02000000
13410#define DIAXIS_DRIVINGC_STEER                   0x02008A01
13411#define DIAXIS_DRIVINGC_ACCELERATE              0x02039202
13412#define DIAXIS_DRIVINGC_BRAKE                   0x02041203
13413#define DIBUTTON_DRIVINGC_FIRE                  0x02000C01
13414#define DIBUTTON_DRIVINGC_WEAPONS               0x02000C02
13415#define DIBUTTON_DRIVINGC_TARGET                0x02000C03
13416#define DIBUTTON_DRIVINGC_MENU                  0x020004FD
13417
13418#define DIAXIS_DRIVINGC_ACCEL_AND_BRAKE         0x02014A04
13419#define DIHATSWITCH_DRIVINGC_GLANCE             0x02004601
13420#define DIBUTTON_DRIVINGC_SHIFTUP               0x02004C04
13421#define DIBUTTON_DRIVINGC_SHIFTDOWN             0x02004C05
13422#define DIBUTTON_DRIVINGC_DASHBOARD             0x02004406
13423#define DIBUTTON_DRIVINGC_AIDS                  0x02004407
13424#define DIBUTTON_DRIVINGC_BRAKE                 0x02004C08
13425#define DIBUTTON_DRIVINGC_FIRESECONDARY         0x02004C09
13426#define DIBUTTON_DRIVINGC_ACCELERATE_LINK       0x0203D4E0
13427#define DIBUTTON_DRIVINGC_STEER_LEFT_LINK       0x0200CCE4
13428#define DIBUTTON_DRIVINGC_STEER_RIGHT_LINK      0x0200CCEC
13429#define DIBUTTON_DRIVINGC_GLANCE_LEFT_LINK      0x0207C4E4
13430#define DIBUTTON_DRIVINGC_GLANCE_RIGHT_LINK     0x0207C4EC
13431#define DIBUTTON_DRIVINGC_DEVICE                0x020044FE
13432#define DIBUTTON_DRIVINGC_PAUSE                 0x020044FC
13433
13434#define DIVIRTUAL_DRIVING_TANK                  0x03000000
13435#define DIAXIS_DRIVINGT_STEER                   0x03008A01
13436#define DIAXIS_DRIVINGT_BARREL                  0x03010202
13437#define DIAXIS_DRIVINGT_ACCELERATE              0x03039203
13438#define DIAXIS_DRIVINGT_ROTATE                  0x03020204
13439#define DIBUTTON_DRIVINGT_FIRE                  0x03000C01
13440#define DIBUTTON_DRIVINGT_WEAPONS               0x03000C02
13441#define DIBUTTON_DRIVINGT_TARGET                0x03000C03
13442#define DIBUTTON_DRIVINGT_MENU                  0x030004FD
13443
13444#define DIHATSWITCH_DRIVINGT_GLANCE             0x03004601
13445#define DIAXIS_DRIVINGT_BRAKE                   0x03045205
13446#define DIAXIS_DRIVINGT_ACCEL_AND_BRAKE         0x03014A06
13447#define DIBUTTON_DRIVINGT_VIEW                  0x03005C04
13448#define DIBUTTON_DRIVINGT_DASHBOARD             0x03005C05
13449#define DIBUTTON_DRIVINGT_BRAKE                 0x03004C06
13450#define DIBUTTON_DRIVINGT_FIRESECONDARY         0x03004C07
13451#define DIBUTTON_DRIVINGT_ACCELERATE_LINK       0x0303D4E0
13452#define DIBUTTON_DRIVINGT_STEER_LEFT_LINK       0x0300CCE4
13453#define DIBUTTON_DRIVINGT_STEER_RIGHT_LINK      0x0300CCEC
13454#define DIBUTTON_DRIVINGT_BARREL_UP_LINK        0x030144E0
13455#define DIBUTTON_DRIVINGT_BARREL_DOWN_LINK      0x030144E8
13456#define DIBUTTON_DRIVINGT_ROTATE_LEFT_LINK      0x030244E4
13457#define DIBUTTON_DRIVINGT_ROTATE_RIGHT_LINK     0x030244EC
13458#define DIBUTTON_DRIVINGT_GLANCE_LEFT_LINK      0x0307C4E4
13459#define DIBUTTON_DRIVINGT_GLANCE_RIGHT_LINK     0x0307C4EC
13460#define DIBUTTON_DRIVINGT_DEVICE                0x030044FE
13461#define DIBUTTON_DRIVINGT_PAUSE                 0x030044FC
13462
13463#define DIVIRTUAL_FLYING_CIVILIAN               0x04000000
13464#define DIAXIS_FLYINGC_BANK                     0x04008A01
13465#define DIAXIS_FLYINGC_PITCH                    0x04010A02
13466#define DIAXIS_FLYINGC_THROTTLE                 0x04039203
13467#define DIBUTTON_FLYINGC_VIEW                   0x04002401
13468#define DIBUTTON_FLYINGC_DISPLAY                0x04002402
13469#define DIBUTTON_FLYINGC_GEAR                   0x04002C03
13470#define DIBUTTON_FLYINGC_MENU                   0x040004FD
13471
13472#define DIHATSWITCH_FLYINGC_GLANCE              0x04004601
13473#define DIAXIS_FLYINGC_BRAKE                    0x04046A04
13474#define DIAXIS_FLYINGC_RUDDER                   0x04025205
13475#define DIAXIS_FLYINGC_FLAPS                    0x04055A06
13476#define DIBUTTON_FLYINGC_FLAPSUP                0x04006404
13477#define DIBUTTON_FLYINGC_FLAPSDOWN              0x04006405
13478#define DIBUTTON_FLYINGC_BRAKE_LINK             0x04046CE0
13479#define DIBUTTON_FLYINGC_FASTER_LINK            0x0403D4E0
13480#define DIBUTTON_FLYINGC_SLOWER_LINK            0x0403D4E8
13481#define DIBUTTON_FLYINGC_GLANCE_LEFT_LINK       0x0407C4E4
13482#define DIBUTTON_FLYINGC_GLANCE_RIGHT_LINK      0x0407C4EC
13483#define DIBUTTON_FLYINGC_GLANCE_UP_LINK         0x0407C4E0
13484#define DIBUTTON_FLYINGC_GLANCE_DOWN_LINK       0x0407C4E8
13485#define DIBUTTON_FLYINGC_DEVICE                 0x040044FE
13486#define DIBUTTON_FLYINGC_PAUSE                  0x040044FC
13487
13488#define DIVIRTUAL_FLYING_MILITARY               0x05000000
13489#define DIAXIS_FLYINGM_BANK                     0x05008A01
13490#define DIAXIS_FLYINGM_PITCH                    0x05010A02
13491#define DIAXIS_FLYINGM_THROTTLE                 0x05039203
13492#define DIBUTTON_FLYINGM_FIRE                   0x05000C01
13493#define DIBUTTON_FLYINGM_WEAPONS                0x05000C02
13494#define DIBUTTON_FLYINGM_TARGET                 0x05000C03
13495#define DIBUTTON_FLYINGM_MENU                   0x050004FD
13496
13497#define DIHATSWITCH_FLYINGM_GLANCE              0x05004601
13498#define DIBUTTON_FLYINGM_COUNTER                0x05005C04
13499#define DIAXIS_FLYINGM_RUDDER                   0x05024A04
13500#define DIAXIS_FLYINGM_BRAKE                    0x05046205
13501#define DIBUTTON_FLYINGM_VIEW                   0x05006405
13502#define DIBUTTON_FLYINGM_DISPLAY                0x05006406
13503#define DIAXIS_FLYINGM_FLAPS                    0x05055206
13504#define DIBUTTON_FLYINGM_FLAPSUP                0x05005407
13505#define DIBUTTON_FLYINGM_FLAPSDOWN              0x05005408
13506#define DIBUTTON_FLYINGM_FIRESECONDARY          0x05004C09
13507#define DIBUTTON_FLYINGM_GEAR                   0x0500640A
13508#define DIBUTTON_FLYINGM_BRAKE_LINK             0x050464E0
13509#define DIBUTTON_FLYINGM_FASTER_LINK            0x0503D4E0
13510#define DIBUTTON_FLYINGM_SLOWER_LINK            0x0503D4E8
13511#define DIBUTTON_FLYINGM_GLANCE_LEFT_LINK       0x0507C4E4
13512#define DIBUTTON_FLYINGM_GLANCE_RIGHT_LINK      0x0507C4EC
13513#define DIBUTTON_FLYINGM_GLANCE_UP_LINK         0x0507C4E0
13514#define DIBUTTON_FLYINGM_GLANCE_DOWN_LINK       0x0507C4E8
13515#define DIBUTTON_FLYINGM_DEVICE                 0x050044FE
13516#define DIBUTTON_FLYINGM_PAUSE                  0x050044FC
13517
13518#define DIVIRTUAL_FLYING_HELICOPTER             0x06000000
13519#define DIAXIS_FLYINGH_BANK                     0x06008A01
13520#define DIAXIS_FLYINGH_PITCH                    0x06010A02
13521#define DIAXIS_FLYINGH_COLLECTIVE               0x06018A03
13522#define DIBUTTON_FLYINGH_FIRE                   0x06001401
13523#define DIBUTTON_FLYINGH_WEAPONS                0x06001402
13524#define DIBUTTON_FLYINGH_TARGET                 0x06001403
13525#define DIBUTTON_FLYINGH_MENU                   0x060004FD
13526
13527#define DIHATSWITCH_FLYINGH_GLANCE              0x06004601
13528#define DIAXIS_FLYINGH_TORQUE                   0x06025A04
13529#define DIAXIS_FLYINGH_THROTTLE                 0x0603DA05
13530#define DIBUTTON_FLYINGH_COUNTER                0x06005404
13531#define DIBUTTON_FLYINGH_VIEW                   0x06006405
13532#define DIBUTTON_FLYINGH_GEAR                   0x06006406
13533#define DIBUTTON_FLYINGH_FIRESECONDARY          0x06004C07
13534#define DIBUTTON_FLYINGH_FASTER_LINK            0x0603DCE0
13535#define DIBUTTON_FLYINGH_SLOWER_LINK            0x0603DCE8
13536#define DIBUTTON_FLYINGH_GLANCE_LEFT_LINK       0x0607C4E4
13537#define DIBUTTON_FLYINGH_GLANCE_RIGHT_LINK      0x0607C4EC
13538#define DIBUTTON_FLYINGH_GLANCE_UP_LINK         0x0607C4E0
13539#define DIBUTTON_FLYINGH_GLANCE_DOWN_LINK       0x0607C4E8
13540#define DIBUTTON_FLYINGH_DEVICE                 0x060044FE
13541#define DIBUTTON_FLYINGH_PAUSE                  0x060044FC
13542
13543#define DIVIRTUAL_SPACESIM                      0x07000000
13544#define DIAXIS_SPACESIM_LATERAL                 0x07008201
13545#define DIAXIS_SPACESIM_MOVE                    0x07010202
13546#define DIAXIS_SPACESIM_THROTTLE                0x07038203
13547#define DIBUTTON_SPACESIM_FIRE                  0x07000401
13548#define DIBUTTON_SPACESIM_WEAPONS               0x07000402
13549#define DIBUTTON_SPACESIM_TARGET                0x07000403
13550#define DIBUTTON_SPACESIM_MENU                  0x070004FD
13551
13552#define DIHATSWITCH_SPACESIM_GLANCE             0x07004601
13553#define DIAXIS_SPACESIM_CLIMB                   0x0701C204
13554#define DIAXIS_SPACESIM_ROTATE                  0x07024205
13555#define DIBUTTON_SPACESIM_VIEW                  0x07004404
13556#define DIBUTTON_SPACESIM_DISPLAY               0x07004405
13557#define DIBUTTON_SPACESIM_RAISE                 0x07004406
13558#define DIBUTTON_SPACESIM_LOWER                 0x07004407
13559#define DIBUTTON_SPACESIM_GEAR                  0x07004408
13560#define DIBUTTON_SPACESIM_FIRESECONDARY         0x07004409
13561#define DIBUTTON_SPACESIM_LEFT_LINK             0x0700C4E4
13562#define DIBUTTON_SPACESIM_RIGHT_LINK            0x0700C4EC
13563#define DIBUTTON_SPACESIM_FORWARD_LINK          0x070144E0
13564#define DIBUTTON_SPACESIM_BACKWARD_LINK         0x070144E8
13565#define DIBUTTON_SPACESIM_FASTER_LINK           0x0703C4E0
13566#define DIBUTTON_SPACESIM_SLOWER_LINK           0x0703C4E8
13567#define DIBUTTON_SPACESIM_TURN_LEFT_LINK        0x070244E4
13568#define DIBUTTON_SPACESIM_TURN_RIGHT_LINK       0x070244EC
13569#define DIBUTTON_SPACESIM_GLANCE_LEFT_LINK      0x0707C4E4
13570#define DIBUTTON_SPACESIM_GLANCE_RIGHT_LINK     0x0707C4EC
13571#define DIBUTTON_SPACESIM_GLANCE_UP_LINK        0x0707C4E0
13572#define DIBUTTON_SPACESIM_GLANCE_DOWN_LINK      0x0707C4E8
13573#define DIBUTTON_SPACESIM_DEVICE                0x070044FE
13574#define DIBUTTON_SPACESIM_PAUSE                 0x070044FC
13575
13576#define DIVIRTUAL_FIGHTING_HAND2HAND            0x08000000
13577#define DIAXIS_FIGHTINGH_LATERAL                0x08008201
13578#define DIAXIS_FIGHTINGH_MOVE                   0x08010202
13579#define DIBUTTON_FIGHTINGH_PUNCH                0x08000401
13580#define DIBUTTON_FIGHTINGH_KICK                 0x08000402
13581#define DIBUTTON_FIGHTINGH_BLOCK                0x08000403
13582#define DIBUTTON_FIGHTINGH_CROUCH               0x08000404
13583#define DIBUTTON_FIGHTINGH_JUMP                 0x08000405
13584#define DIBUTTON_FIGHTINGH_SPECIAL1             0x08000406
13585#define DIBUTTON_FIGHTINGH_SPECIAL2             0x08000407
13586#define DIBUTTON_FIGHTINGH_MENU                 0x080004FD
13587
13588#define DIBUTTON_FIGHTINGH_SELECT               0x08004408
13589#define DIHATSWITCH_FIGHTINGH_SLIDE             0x08004601
13590#define DIBUTTON_FIGHTINGH_DISPLAY              0x08004409
13591#define DIAXIS_FIGHTINGH_ROTATE                 0x08024203
13592#define DIBUTTON_FIGHTINGH_DODGE                0x0800440A
13593#define DIBUTTON_FIGHTINGH_LEFT_LINK            0x0800C4E4
13594#define DIBUTTON_FIGHTINGH_RIGHT_LINK           0x0800C4EC
13595#define DIBUTTON_FIGHTINGH_FORWARD_LINK         0x080144E0
13596#define DIBUTTON_FIGHTINGH_BACKWARD_LINK        0x080144E8
13597#define DIBUTTON_FIGHTINGH_DEVICE               0x080044FE
13598#define DIBUTTON_FIGHTINGH_PAUSE                0x080044FC
13599
13600#define DIVIRTUAL_FIGHTING_FPS                  0x09000000
13601#define DIAXIS_FPS_ROTATE                       0x09008201
13602#define DIAXIS_FPS_MOVE                         0x09010202
13603#define DIBUTTON_FPS_FIRE                       0x09000401
13604#define DIBUTTON_FPS_WEAPONS                    0x09000402
13605#define DIBUTTON_FPS_APPLY                      0x09000403
13606#define DIBUTTON_FPS_SELECT                     0x09000404
13607#define DIBUTTON_FPS_CROUCH                     0x09000405
13608#define DIBUTTON_FPS_JUMP                       0x09000406
13609#define DIAXIS_FPS_LOOKUPDOWN                   0x09018203
13610#define DIBUTTON_FPS_STRAFE                     0x09000407
13611#define DIBUTTON_FPS_MENU                       0x090004FD
13612
13613#define DIHATSWITCH_FPS_GLANCE                  0x09004601
13614#define DIBUTTON_FPS_DISPLAY                    0x09004408
13615#define DIAXIS_FPS_SIDESTEP                     0x09024204
13616#define DIBUTTON_FPS_DODGE                      0x09004409
13617#define DIBUTTON_FPS_GLANCEL                    0x0900440A
13618#define DIBUTTON_FPS_GLANCER                    0x0900440B
13619#define DIBUTTON_FPS_FIRESECONDARY              0x0900440C
13620#define DIBUTTON_FPS_ROTATE_LEFT_LINK           0x0900C4E4
13621#define DIBUTTON_FPS_ROTATE_RIGHT_LINK          0x0900C4EC
13622#define DIBUTTON_FPS_FORWARD_LINK               0x090144E0
13623#define DIBUTTON_FPS_BACKWARD_LINK              0x090144E8
13624#define DIBUTTON_FPS_GLANCE_UP_LINK             0x0901C4E0
13625#define DIBUTTON_FPS_GLANCE_DOWN_LINK           0x0901C4E8
13626#define DIBUTTON_FPS_DEVICE                     0x090044FE
13627#define DIBUTTON_FPS_PAUSE                      0x090044FC
13628
13629#define DIVIRTUAL_FIGHTING_THIRDPERSON          0x0A000000
13630#define DIAXIS_TPS_TURN                         0x0A020201
13631#define DIAXIS_TPS_MOVE                         0x0A010202
13632#define DIBUTTON_TPS_RUN                        0x0A000401
13633#define DIBUTTON_TPS_ACTION                     0x0A000402
13634#define DIBUTTON_TPS_SELECT                     0x0A000403
13635#define DIBUTTON_TPS_USE                        0x0A000404
13636#define DIBUTTON_TPS_JUMP                       0x0A000405
13637#define DIBUTTON_TPS_MENU                       0x0A0004FD
13638
13639#define DIHATSWITCH_TPS_GLANCE                  0x0A004601
13640#define DIBUTTON_TPS_VIEW                       0x0A004406
13641#define DIBUTTON_TPS_STEPLEFT                   0x0A004407
13642#define DIBUTTON_TPS_STEPRIGHT                  0x0A004408
13643#define DIAXIS_TPS_STEP                         0x0A00C203
13644#define DIBUTTON_TPS_DODGE                      0x0A004409
13645#define DIBUTTON_TPS_INVENTORY                  0x0A00440A
13646#define DIBUTTON_TPS_TURN_LEFT_LINK             0x0A0244E4
13647#define DIBUTTON_TPS_TURN_RIGHT_LINK            0x0A0244EC
13648#define DIBUTTON_TPS_FORWARD_LINK               0x0A0144E0
13649#define DIBUTTON_TPS_BACKWARD_LINK              0x0A0144E8
13650#define DIBUTTON_TPS_GLANCE_UP_LINK             0x0A07C4E0
13651#define DIBUTTON_TPS_GLANCE_DOWN_LINK           0x0A07C4E8
13652#define DIBUTTON_TPS_GLANCE_LEFT_LINK           0x0A07C4E4
13653#define DIBUTTON_TPS_GLANCE_RIGHT_LINK          0x0A07C4EC
13654#define DIBUTTON_TPS_DEVICE                     0x0A0044FE
13655#define DIBUTTON_TPS_PAUSE                      0x0A0044FC
13656
13657#define DIVIRTUAL_STRATEGY_ROLEPLAYING          0x0B000000
13658#define DIAXIS_STRATEGYR_LATERAL                0x0B008201
13659#define DIAXIS_STRATEGYR_MOVE                   0x0B010202
13660#define DIBUTTON_STRATEGYR_GET                  0x0B000401
13661#define DIBUTTON_STRATEGYR_APPLY                0x0B000402
13662#define DIBUTTON_STRATEGYR_SELECT               0x0B000403
13663#define DIBUTTON_STRATEGYR_ATTACK               0x0B000404
13664#define DIBUTTON_STRATEGYR_CAST                 0x0B000405
13665#define DIBUTTON_STRATEGYR_CROUCH               0x0B000406
13666#define DIBUTTON_STRATEGYR_JUMP                 0x0B000407
13667#define DIBUTTON_STRATEGYR_MENU                 0x0B0004FD
13668
13669#define DIHATSWITCH_STRATEGYR_GLANCE            0x0B004601
13670#define DIBUTTON_STRATEGYR_MAP                  0x0B004408
13671#define DIBUTTON_STRATEGYR_DISPLAY              0x0B004409
13672#define DIAXIS_STRATEGYR_ROTATE                 0x0B024203
13673#define DIBUTTON_STRATEGYR_LEFT_LINK            0x0B00C4E4
13674#define DIBUTTON_STRATEGYR_RIGHT_LINK           0x0B00C4EC
13675#define DIBUTTON_STRATEGYR_FORWARD_LINK         0x0B0144E0
13676#define DIBUTTON_STRATEGYR_BACK_LINK            0x0B0144E8
13677#define DIBUTTON_STRATEGYR_ROTATE_LEFT_LINK     0x0B0244E4
13678#define DIBUTTON_STRATEGYR_ROTATE_RIGHT_LINK    0x0B0244EC
13679#define DIBUTTON_STRATEGYR_DEVICE               0x0B0044FE
13680#define DIBUTTON_STRATEGYR_PAUSE                0x0B0044FC
13681
13682#define DIVIRTUAL_STRATEGY_TURN                 0x0C000000
13683#define DIAXIS_STRATEGYT_LATERAL                0x0C008201
13684#define DIAXIS_STRATEGYT_MOVE                   0x0C010202
13685#define DIBUTTON_STRATEGYT_SELECT               0x0C000401
13686#define DIBUTTON_STRATEGYT_INSTRUCT             0x0C000402
13687#define DIBUTTON_STRATEGYT_APPLY                0x0C000403
13688#define DIBUTTON_STRATEGYT_TEAM                 0x0C000404
13689#define DIBUTTON_STRATEGYT_TURN                 0x0C000405
13690#define DIBUTTON_STRATEGYT_MENU                 0x0C0004FD
13691
13692#define DIBUTTON_STRATEGYT_ZOOM                 0x0C004406
13693#define DIBUTTON_STRATEGYT_MAP                  0x0C004407
13694#define DIBUTTON_STRATEGYT_DISPLAY              0x0C004408
13695#define DIBUTTON_STRATEGYT_LEFT_LINK            0x0C00C4E4
13696#define DIBUTTON_STRATEGYT_RIGHT_LINK           0x0C00C4EC
13697#define DIBUTTON_STRATEGYT_FORWARD_LINK         0x0C0144E0
13698#define DIBUTTON_STRATEGYT_BACK_LINK            0x0C0144E8
13699#define DIBUTTON_STRATEGYT_DEVICE               0x0C0044FE
13700#define DIBUTTON_STRATEGYT_PAUSE                0x0C0044FC
13701
13702#define DIVIRTUAL_SPORTS_HUNTING                0x0D000000
13703#define DIAXIS_HUNTING_LATERAL                  0x0D008201
13704#define DIAXIS_HUNTING_MOVE                     0x0D010202
13705#define DIBUTTON_HUNTING_FIRE                   0x0D000401
13706#define DIBUTTON_HUNTING_AIM                    0x0D000402
13707#define DIBUTTON_HUNTING_WEAPON                 0x0D000403
13708#define DIBUTTON_HUNTING_BINOCULAR              0x0D000404
13709#define DIBUTTON_HUNTING_CALL                   0x0D000405
13710#define DIBUTTON_HUNTING_MAP                    0x0D000406
13711#define DIBUTTON_HUNTING_SPECIAL                0x0D000407
13712#define DIBUTTON_HUNTING_MENU                   0x0D0004FD
13713
13714#define DIHATSWITCH_HUNTING_GLANCE              0x0D004601
13715#define DIBUTTON_HUNTING_DISPLAY                0x0D004408
13716#define DIAXIS_HUNTING_ROTATE                   0x0D024203
13717#define DIBUTTON_HUNTING_CROUCH                 0x0D004409
13718#define DIBUTTON_HUNTING_JUMP                   0x0D00440A
13719#define DIBUTTON_HUNTING_FIRESECONDARY          0x0D00440B
13720#define DIBUTTON_HUNTING_LEFT_LINK              0x0D00C4E4
13721#define DIBUTTON_HUNTING_RIGHT_LINK             0x0D00C4EC
13722#define DIBUTTON_HUNTING_FORWARD_LINK           0x0D0144E0
13723#define DIBUTTON_HUNTING_BACK_LINK              0x0D0144E8
13724#define DIBUTTON_HUNTING_ROTATE_LEFT_LINK       0x0D0244E4
13725#define DIBUTTON_HUNTING_ROTATE_RIGHT_LINK      0x0D0244EC
13726#define DIBUTTON_HUNTING_DEVICE                 0x0D0044FE
13727#define DIBUTTON_HUNTING_PAUSE                  0x0D0044FC
13728
13729#define DIVIRTUAL_SPORTS_FISHING                0x0E000000
13730#define DIAXIS_FISHING_LATERAL                  0x0E008201
13731#define DIAXIS_FISHING_MOVE                     0x0E010202
13732#define DIBUTTON_FISHING_CAST                   0x0E000401
13733#define DIBUTTON_FISHING_TYPE                   0x0E000402
13734#define DIBUTTON_FISHING_BINOCULAR              0x0E000403
13735#define DIBUTTON_FISHING_BAIT                   0x0E000404
13736#define DIBUTTON_FISHING_MAP                    0x0E000405
13737#define DIBUTTON_FISHING_MENU                   0x0E0004FD
13738
13739#define DIHATSWITCH_FISHING_GLANCE              0x0E004601
13740#define DIBUTTON_FISHING_DISPLAY                0x0E004406
13741#define DIAXIS_FISHING_ROTATE                   0x0E024203
13742#define DIBUTTON_FISHING_CROUCH                 0x0E004407
13743#define DIBUTTON_FISHING_JUMP                   0x0E004408
13744#define DIBUTTON_FISHING_LEFT_LINK              0x0E00C4E4
13745#define DIBUTTON_FISHING_RIGHT_LINK             0x0E00C4EC
13746#define DIBUTTON_FISHING_FORWARD_LINK           0x0E0144E0
13747#define DIBUTTON_FISHING_BACK_LINK              0x0E0144E8
13748#define DIBUTTON_FISHING_ROTATE_LEFT_LINK       0x0E0244E4
13749#define DIBUTTON_FISHING_ROTATE_RIGHT_LINK      0x0E0244EC
13750#define DIBUTTON_FISHING_DEVICE                 0x0E0044FE
13751#define DIBUTTON_FISHING_PAUSE                  0x0E0044FC
13752
13753#define DIVIRTUAL_SPORTS_BASEBALL_BAT           0x0F000000
13754#define DIAXIS_BASEBALLB_LATERAL                0x0F008201
13755#define DIAXIS_BASEBALLB_MOVE                   0x0F010202
13756#define DIBUTTON_BASEBALLB_SELECT               0x0F000401
13757#define DIBUTTON_BASEBALLB_NORMAL               0x0F000402
13758#define DIBUTTON_BASEBALLB_POWER                0x0F000403
13759#define DIBUTTON_BASEBALLB_BUNT                 0x0F000404
13760#define DIBUTTON_BASEBALLB_STEAL                0x0F000405
13761#define DIBUTTON_BASEBALLB_BURST                0x0F000406
13762#define DIBUTTON_BASEBALLB_SLIDE                0x0F000407
13763#define DIBUTTON_BASEBALLB_CONTACT              0x0F000408
13764#define DIBUTTON_BASEBALLB_MENU                 0x0F0004FD
13765
13766#define DIBUTTON_BASEBALLB_NOSTEAL              0x0F004409
13767#define DIBUTTON_BASEBALLB_BOX                  0x0F00440A
13768#define DIBUTTON_BASEBALLB_LEFT_LINK            0x0F00C4E4
13769#define DIBUTTON_BASEBALLB_RIGHT_LINK           0x0F00C4EC
13770#define DIBUTTON_BASEBALLB_FORWARD_LINK         0x0F0144E0
13771#define DIBUTTON_BASEBALLB_BACK_LINK            0x0F0144E8
13772#define DIBUTTON_BASEBALLB_DEVICE               0x0F0044FE
13773#define DIBUTTON_BASEBALLB_PAUSE                0x0F0044FC
13774
13775#define DIVIRTUAL_SPORTS_BASEBALL_PITCH         0x10000000
13776#define DIAXIS_BASEBALLP_LATERAL                0x10008201
13777#define DIAXIS_BASEBALLP_MOVE                   0x10010202
13778#define DIBUTTON_BASEBALLP_SELECT               0x10000401
13779#define DIBUTTON_BASEBALLP_PITCH                0x10000402
13780#define DIBUTTON_BASEBALLP_BASE                 0x10000403
13781#define DIBUTTON_BASEBALLP_THROW                0x10000404
13782#define DIBUTTON_BASEBALLP_FAKE                 0x10000405
13783#define DIBUTTON_BASEBALLP_MENU                 0x100004FD
13784
13785#define DIBUTTON_BASEBALLP_WALK                 0x10004406
13786#define DIBUTTON_BASEBALLP_LOOK                 0x10004407
13787#define DIBUTTON_BASEBALLP_LEFT_LINK            0x1000C4E4
13788#define DIBUTTON_BASEBALLP_RIGHT_LINK           0x1000C4EC
13789#define DIBUTTON_BASEBALLP_FORWARD_LINK         0x100144E0
13790#define DIBUTTON_BASEBALLP_BACK_LINK            0x100144E8
13791#define DIBUTTON_BASEBALLP_DEVICE               0x100044FE
13792#define DIBUTTON_BASEBALLP_PAUSE                0x100044FC
13793
13794#define DIVIRTUAL_SPORTS_BASEBALL_FIELD         0x11000000
13795#define DIAXIS_BASEBALLF_LATERAL                0x11008201
13796#define DIAXIS_BASEBALLF_MOVE                   0x11010202
13797#define DIBUTTON_BASEBALLF_NEAREST              0x11000401
13798#define DIBUTTON_BASEBALLF_THROW1               0x11000402
13799#define DIBUTTON_BASEBALLF_THROW2               0x11000403
13800#define DIBUTTON_BASEBALLF_BURST                0x11000404
13801#define DIBUTTON_BASEBALLF_JUMP                 0x11000405
13802#define DIBUTTON_BASEBALLF_DIVE                 0x11000406
13803#define DIBUTTON_BASEBALLF_MENU                 0x110004FD
13804
13805#define DIBUTTON_BASEBALLF_SHIFTIN              0x11004407
13806#define DIBUTTON_BASEBALLF_SHIFTOUT             0x11004408
13807#define DIBUTTON_BASEBALLF_AIM_LEFT_LINK        0x1100C4E4
13808#define DIBUTTON_BASEBALLF_AIM_RIGHT_LINK       0x1100C4EC
13809#define DIBUTTON_BASEBALLF_FORWARD_LINK         0x110144E0
13810#define DIBUTTON_BASEBALLF_BACK_LINK            0x110144E8
13811#define DIBUTTON_BASEBALLF_DEVICE               0x110044FE
13812#define DIBUTTON_BASEBALLF_PAUSE                0x110044FC
13813
13814#define DIVIRTUAL_SPORTS_BASKETBALL_OFFENSE     0x12000000
13815#define DIAXIS_BBALLO_LATERAL                   0x12008201
13816#define DIAXIS_BBALLO_MOVE                      0x12010202
13817#define DIBUTTON_BBALLO_SHOOT                   0x12000401
13818#define DIBUTTON_BBALLO_DUNK                    0x12000402
13819#define DIBUTTON_BBALLO_PASS                    0x12000403
13820#define DIBUTTON_BBALLO_FAKE                    0x12000404
13821#define DIBUTTON_BBALLO_SPECIAL                 0x12000405
13822#define DIBUTTON_BBALLO_PLAYER                  0x12000406
13823#define DIBUTTON_BBALLO_BURST                   0x12000407
13824#define DIBUTTON_BBALLO_CALL                    0x12000408
13825#define DIBUTTON_BBALLO_MENU                    0x120004FD
13826
13827#define DIHATSWITCH_BBALLO_GLANCE               0x12004601
13828#define DIBUTTON_BBALLO_SCREEN                  0x12004409
13829#define DIBUTTON_BBALLO_PLAY                    0x1200440A
13830#define DIBUTTON_BBALLO_JAB                     0x1200440B
13831#define DIBUTTON_BBALLO_POST                    0x1200440C
13832#define DIBUTTON_BBALLO_TIMEOUT                 0x1200440D
13833#define DIBUTTON_BBALLO_SUBSTITUTE              0x1200440E
13834#define DIBUTTON_BBALLO_LEFT_LINK               0x1200C4E4
13835#define DIBUTTON_BBALLO_RIGHT_LINK              0x1200C4EC
13836#define DIBUTTON_BBALLO_FORWARD_LINK            0x120144E0
13837#define DIBUTTON_BBALLO_BACK_LINK               0x120144E8
13838#define DIBUTTON_BBALLO_DEVICE                  0x120044FE
13839#define DIBUTTON_BBALLO_PAUSE                   0x120044FC
13840
13841#define DIVIRTUAL_SPORTS_BASKETBALL_DEFENSE     0x13000000
13842#define DIAXIS_BBALLD_LATERAL                   0x13008201
13843#define DIAXIS_BBALLD_MOVE                      0x13010202
13844#define DIBUTTON_BBALLD_JUMP                    0x13000401
13845#define DIBUTTON_BBALLD_STEAL                   0x13000402
13846#define DIBUTTON_BBALLD_FAKE                    0x13000403
13847#define DIBUTTON_BBALLD_SPECIAL                 0x13000404
13848#define DIBUTTON_BBALLD_PLAYER                  0x13000405
13849#define DIBUTTON_BBALLD_BURST                   0x13000406
13850#define DIBUTTON_BBALLD_PLAY                    0x13000407
13851#define DIBUTTON_BBALLD_MENU                    0x130004FD
13852
13853#define DIHATSWITCH_BBALLD_GLANCE               0x13004601
13854#define DIBUTTON_BBALLD_TIMEOUT                 0x13004408
13855#define DIBUTTON_BBALLD_SUBSTITUTE              0x13004409
13856#define DIBUTTON_BBALLD_LEFT_LINK               0x1300C4E4
13857#define DIBUTTON_BBALLD_RIGHT_LINK              0x1300C4EC
13858#define DIBUTTON_BBALLD_FORWARD_LINK            0x130144E0
13859#define DIBUTTON_BBALLD_BACK_LINK               0x130144E8
13860#define DIBUTTON_BBALLD_DEVICE                  0x130044FE
13861#define DIBUTTON_BBALLD_PAUSE                   0x130044FC
13862
13863#define DIVIRTUAL_SPORTS_FOOTBALL_FIELD         0x14000000
13864#define DIBUTTON_FOOTBALLP_PLAY                 0x14000401
13865#define DIBUTTON_FOOTBALLP_SELECT               0x14000402
13866#define DIBUTTON_FOOTBALLP_HELP                 0x14000403
13867#define DIBUTTON_FOOTBALLP_MENU                 0x140004FD
13868
13869#define DIBUTTON_FOOTBALLP_DEVICE               0x140044FE
13870#define DIBUTTON_FOOTBALLP_PAUSE                0x140044FC
13871
13872#define DIVIRTUAL_SPORTS_FOOTBALL_QBCK          0x15000000
13873#define DIAXIS_FOOTBALLQ_LATERAL                0x15008201
13874#define DIAXIS_FOOTBALLQ_MOVE                   0x15010202
13875#define DIBUTTON_FOOTBALLQ_SELECT               0x15000401
13876#define DIBUTTON_FOOTBALLQ_SNAP                 0x15000402
13877#define DIBUTTON_FOOTBALLQ_JUMP                 0x15000403
13878#define DIBUTTON_FOOTBALLQ_SLIDE                0x15000404
13879#define DIBUTTON_FOOTBALLQ_PASS                 0x15000405
13880#define DIBUTTON_FOOTBALLQ_FAKE                 0x15000406
13881#define DIBUTTON_FOOTBALLQ_MENU                 0x150004FD
13882
13883#define DIBUTTON_FOOTBALLQ_FAKESNAP             0x15004407
13884#define DIBUTTON_FOOTBALLQ_MOTION               0x15004408
13885#define DIBUTTON_FOOTBALLQ_AUDIBLE              0x15004409
13886#define DIBUTTON_FOOTBALLQ_LEFT_LINK            0x1500C4E4
13887#define DIBUTTON_FOOTBALLQ_RIGHT_LINK           0x1500C4EC
13888#define DIBUTTON_FOOTBALLQ_FORWARD_LINK         0x150144E0
13889#define DIBUTTON_FOOTBALLQ_BACK_LINK            0x150144E8
13890#define DIBUTTON_FOOTBALLQ_DEVICE               0x150044FE
13891#define DIBUTTON_FOOTBALLQ_PAUSE                0x150044FC
13892
13893#define DIVIRTUAL_SPORTS_FOOTBALL_OFFENSE       0x16000000
13894#define DIAXIS_FOOTBALLO_LATERAL                0x16008201
13895#define DIAXIS_FOOTBALLO_MOVE                   0x16010202
13896#define DIBUTTON_FOOTBALLO_JUMP                 0x16000401
13897#define DIBUTTON_FOOTBALLO_LEFTARM              0x16000402
13898#define DIBUTTON_FOOTBALLO_RIGHTARM             0x16000403
13899#define DIBUTTON_FOOTBALLO_THROW                0x16000404
13900#define DIBUTTON_FOOTBALLO_SPIN                 0x16000405
13901#define DIBUTTON_FOOTBALLO_MENU                 0x160004FD
13902
13903#define DIBUTTON_FOOTBALLO_JUKE                 0x16004406
13904#define DIBUTTON_FOOTBALLO_SHOULDER             0x16004407
13905#define DIBUTTON_FOOTBALLO_TURBO                0x16004408
13906#define DIBUTTON_FOOTBALLO_DIVE                 0x16004409
13907#define DIBUTTON_FOOTBALLO_ZOOM                 0x1600440A
13908#define DIBUTTON_FOOTBALLO_SUBSTITUTE           0x1600440B
13909#define DIBUTTON_FOOTBALLO_LEFT_LINK            0x1600C4E4
13910#define DIBUTTON_FOOTBALLO_RIGHT_LINK           0x1600C4EC
13911#define DIBUTTON_FOOTBALLO_FORWARD_LINK         0x160144E0
13912#define DIBUTTON_FOOTBALLO_BACK_LINK            0x160144E8
13913#define DIBUTTON_FOOTBALLO_DEVICE               0x160044FE
13914#define DIBUTTON_FOOTBALLO_PAUSE                0x160044FC
13915
13916#define DIVIRTUAL_SPORTS_FOOTBALL_DEFENSE       0x17000000
13917#define DIAXIS_FOOTBALLD_LATERAL                0x17008201
13918#define DIAXIS_FOOTBALLD_MOVE                   0x17010202
13919#define DIBUTTON_FOOTBALLD_PLAY                 0x17000401
13920#define DIBUTTON_FOOTBALLD_SELECT               0x17000402
13921#define DIBUTTON_FOOTBALLD_JUMP                 0x17000403
13922#define DIBUTTON_FOOTBALLD_TACKLE               0x17000404
13923#define DIBUTTON_FOOTBALLD_FAKE                 0x17000405
13924#define DIBUTTON_FOOTBALLD_SUPERTACKLE          0x17000406
13925#define DIBUTTON_FOOTBALLD_MENU                 0x170004FD
13926
13927#define DIBUTTON_FOOTBALLD_SPIN                 0x17004407
13928#define DIBUTTON_FOOTBALLD_SWIM                 0x17004408
13929#define DIBUTTON_FOOTBALLD_BULLRUSH             0x17004409
13930#define DIBUTTON_FOOTBALLD_RIP                  0x1700440A
13931#define DIBUTTON_FOOTBALLD_AUDIBLE              0x1700440B
13932#define DIBUTTON_FOOTBALLD_ZOOM                 0x1700440C
13933#define DIBUTTON_FOOTBALLD_SUBSTITUTE           0x1700440D
13934#define DIBUTTON_FOOTBALLD_LEFT_LINK            0x1700C4E4
13935#define DIBUTTON_FOOTBALLD_RIGHT_LINK           0x1700C4EC
13936#define DIBUTTON_FOOTBALLD_FORWARD_LINK         0x170144E0
13937#define DIBUTTON_FOOTBALLD_BACK_LINK            0x170144E8
13938#define DIBUTTON_FOOTBALLD_DEVICE               0x170044FE
13939#define DIBUTTON_FOOTBALLD_PAUSE                0x170044FC
13940
13941#define DIVIRTUAL_SPORTS_GOLF                   0x18000000
13942#define DIAXIS_GOLF_LATERAL                     0x18008201
13943#define DIAXIS_GOLF_MOVE                        0x18010202
13944#define DIBUTTON_GOLF_SWING                     0x18000401
13945#define DIBUTTON_GOLF_SELECT                    0x18000402
13946#define DIBUTTON_GOLF_UP                        0x18000403
13947#define DIBUTTON_GOLF_DOWN                      0x18000404
13948#define DIBUTTON_GOLF_TERRAIN                   0x18000405
13949#define DIBUTTON_GOLF_FLYBY                     0x18000406
13950#define DIBUTTON_GOLF_MENU                      0x180004FD
13951
13952#define DIHATSWITCH_GOLF_SCROLL                 0x18004601
13953#define DIBUTTON_GOLF_ZOOM                      0x18004407
13954#define DIBUTTON_GOLF_TIMEOUT                   0x18004408
13955#define DIBUTTON_GOLF_SUBSTITUTE                0x18004409
13956#define DIBUTTON_GOLF_LEFT_LINK                 0x1800C4E4
13957#define DIBUTTON_GOLF_RIGHT_LINK                0x1800C4EC
13958#define DIBUTTON_GOLF_FORWARD_LINK              0x180144E0
13959#define DIBUTTON_GOLF_BACK_LINK                 0x180144E8
13960#define DIBUTTON_GOLF_DEVICE                    0x180044FE
13961#define DIBUTTON_GOLF_PAUSE                     0x180044FC
13962
13963#define DIVIRTUAL_SPORTS_HOCKEY_OFFENSE         0x19000000
13964#define DIAXIS_HOCKEYO_LATERAL                  0x19008201
13965#define DIAXIS_HOCKEYO_MOVE                     0x19010202
13966#define DIBUTTON_HOCKEYO_SHOOT                  0x19000401
13967#define DIBUTTON_HOCKEYO_PASS                   0x19000402
13968#define DIBUTTON_HOCKEYO_BURST                  0x19000403
13969#define DIBUTTON_HOCKEYO_SPECIAL                0x19000404
13970#define DIBUTTON_HOCKEYO_FAKE                   0x19000405
13971#define DIBUTTON_HOCKEYO_MENU                   0x190004FD
13972
13973#define DIHATSWITCH_HOCKEYO_SCROLL              0x19004601
13974#define DIBUTTON_HOCKEYO_ZOOM                   0x19004406
13975#define DIBUTTON_HOCKEYO_STRATEGY               0x19004407
13976#define DIBUTTON_HOCKEYO_TIMEOUT                0x19004408
13977#define DIBUTTON_HOCKEYO_SUBSTITUTE             0x19004409
13978#define DIBUTTON_HOCKEYO_LEFT_LINK              0x1900C4E4
13979#define DIBUTTON_HOCKEYO_RIGHT_LINK             0x1900C4EC
13980#define DIBUTTON_HOCKEYO_FORWARD_LINK           0x190144E0
13981#define DIBUTTON_HOCKEYO_BACK_LINK              0x190144E8
13982#define DIBUTTON_HOCKEYO_DEVICE                 0x190044FE
13983#define DIBUTTON_HOCKEYO_PAUSE                  0x190044FC
13984
13985#define DIVIRTUAL_SPORTS_HOCKEY_DEFENSE         0x1A000000
13986#define DIAXIS_HOCKEYD_LATERAL                  0x1A008201
13987#define DIAXIS_HOCKEYD_MOVE                     0x1A010202
13988#define DIBUTTON_HOCKEYD_PLAYER                 0x1A000401
13989#define DIBUTTON_HOCKEYD_STEAL                  0x1A000402
13990#define DIBUTTON_HOCKEYD_BURST                  0x1A000403
13991#define DIBUTTON_HOCKEYD_BLOCK                  0x1A000404
13992#define DIBUTTON_HOCKEYD_FAKE                   0x1A000405
13993#define DIBUTTON_HOCKEYD_MENU                   0x1A0004FD
13994
13995#define DIHATSWITCH_HOCKEYD_SCROLL              0x1A004601
13996#define DIBUTTON_HOCKEYD_ZOOM                   0x1A004406
13997#define DIBUTTON_HOCKEYD_STRATEGY               0x1A004407
13998#define DIBUTTON_HOCKEYD_TIMEOUT                0x1A004408
13999#define DIBUTTON_HOCKEYD_SUBSTITUTE             0x1A004409
14000#define DIBUTTON_HOCKEYD_LEFT_LINK              0x1A00C4E4
14001#define DIBUTTON_HOCKEYD_RIGHT_LINK             0x1A00C4EC
14002#define DIBUTTON_HOCKEYD_FORWARD_LINK           0x1A0144E0
14003#define DIBUTTON_HOCKEYD_BACK_LINK              0x1A0144E8
14004#define DIBUTTON_HOCKEYD_DEVICE                 0x1A0044FE
14005#define DIBUTTON_HOCKEYD_PAUSE                  0x1A0044FC
14006
14007#define DIVIRTUAL_SPORTS_HOCKEY_GOALIE          0x1B000000
14008#define DIAXIS_HOCKEYG_LATERAL                  0x1B008201
14009#define DIAXIS_HOCKEYG_MOVE                     0x1B010202
14010#define DIBUTTON_HOCKEYG_PASS                   0x1B000401
14011#define DIBUTTON_HOCKEYG_POKE                   0x1B000402
14012#define DIBUTTON_HOCKEYG_STEAL                  0x1B000403
14013#define DIBUTTON_HOCKEYG_BLOCK                  0x1B000404
14014#define DIBUTTON_HOCKEYG_MENU                   0x1B0004FD
14015
14016#define DIHATSWITCH_HOCKEYG_SCROLL              0x1B004601
14017#define DIBUTTON_HOCKEYG_ZOOM                   0x1B004405
14018#define DIBUTTON_HOCKEYG_STRATEGY               0x1B004406
14019#define DIBUTTON_HOCKEYG_TIMEOUT                0x1B004407
14020#define DIBUTTON_HOCKEYG_SUBSTITUTE             0x1B004408
14021#define DIBUTTON_HOCKEYG_LEFT_LINK              0x1B00C4E4
14022#define DIBUTTON_HOCKEYG_RIGHT_LINK             0x1B00C4EC
14023#define DIBUTTON_HOCKEYG_FORWARD_LINK           0x1B0144E0
14024#define DIBUTTON_HOCKEYG_BACK_LINK              0x1B0144E8
14025#define DIBUTTON_HOCKEYG_DEVICE                 0x1B0044FE
14026#define DIBUTTON_HOCKEYG_PAUSE                  0x1B0044FC
14027
14028#define DIVIRTUAL_SPORTS_BIKING_MOUNTAIN        0x1C000000
14029#define DIAXIS_BIKINGM_TURN                     0x1C008201
14030#define DIAXIS_BIKINGM_PEDAL                    0x1C010202
14031#define DIBUTTON_BIKINGM_JUMP                   0x1C000401
14032#define DIBUTTON_BIKINGM_CAMERA                 0x1C000402
14033#define DIBUTTON_BIKINGM_SPECIAL1               0x1C000403
14034#define DIBUTTON_BIKINGM_SELECT                 0x1C000404
14035#define DIBUTTON_BIKINGM_SPECIAL2               0x1C000405
14036#define DIBUTTON_BIKINGM_MENU                   0x1C0004FD
14037
14038#define DIHATSWITCH_BIKINGM_SCROLL              0x1C004601
14039#define DIBUTTON_BIKINGM_ZOOM                   0x1C004406
14040#define DIAXIS_BIKINGM_BRAKE                    0x1C044203
14041#define DIBUTTON_BIKINGM_LEFT_LINK              0x1C00C4E4
14042#define DIBUTTON_BIKINGM_RIGHT_LINK             0x1C00C4EC
14043#define DIBUTTON_BIKINGM_FASTER_LINK            0x1C0144E0
14044#define DIBUTTON_BIKINGM_SLOWER_LINK            0x1C0144E8
14045#define DIBUTTON_BIKINGM_BRAKE_BUTTON_LINK      0x1C0444E8
14046#define DIBUTTON_BIKINGM_DEVICE                 0x1C0044FE
14047#define DIBUTTON_BIKINGM_PAUSE                  0x1C0044FC
14048
14049#define DIVIRTUAL_SPORTS_SKIING                 0x1D000000
14050#define DIAXIS_SKIING_TURN                      0x1D008201
14051#define DIAXIS_SKIING_SPEED                     0x1D010202
14052#define DIBUTTON_SKIING_JUMP                    0x1D000401
14053#define DIBUTTON_SKIING_CROUCH                  0x1D000402
14054#define DIBUTTON_SKIING_CAMERA                  0x1D000403
14055#define DIBUTTON_SKIING_SPECIAL1                0x1D000404
14056#define DIBUTTON_SKIING_SELECT                  0x1D000405
14057#define DIBUTTON_SKIING_SPECIAL2                0x1D000406
14058#define DIBUTTON_SKIING_MENU                    0x1D0004FD
14059
14060#define DIHATSWITCH_SKIING_GLANCE               0x1D004601
14061#define DIBUTTON_SKIING_ZOOM                    0x1D004407
14062#define DIBUTTON_SKIING_LEFT_LINK               0x1D00C4E4
14063#define DIBUTTON_SKIING_RIGHT_LINK              0x1D00C4EC
14064#define DIBUTTON_SKIING_FASTER_LINK             0x1D0144E0
14065#define DIBUTTON_SKIING_SLOWER_LINK             0x1D0144E8
14066#define DIBUTTON_SKIING_DEVICE                  0x1D0044FE
14067#define DIBUTTON_SKIING_PAUSE                   0x1D0044FC
14068
14069#define DIVIRTUAL_SPORTS_SOCCER_OFFENSE         0x1E000000
14070#define DIAXIS_SOCCERO_LATERAL                  0x1E008201
14071#define DIAXIS_SOCCERO_MOVE                     0x1E010202
14072#define DIAXIS_SOCCERO_BEND                     0x1E018203
14073#define DIBUTTON_SOCCERO_SHOOT                  0x1E000401
14074#define DIBUTTON_SOCCERO_PASS                   0x1E000402
14075#define DIBUTTON_SOCCERO_FAKE                   0x1E000403
14076#define DIBUTTON_SOCCERO_PLAYER                 0x1E000404
14077#define DIBUTTON_SOCCERO_SPECIAL1               0x1E000405
14078#define DIBUTTON_SOCCERO_SELECT                 0x1E000406
14079#define DIBUTTON_SOCCERO_MENU                   0x1E0004FD
14080
14081#define DIHATSWITCH_SOCCERO_GLANCE              0x1E004601
14082#define DIBUTTON_SOCCERO_SUBSTITUTE             0x1E004407
14083#define DIBUTTON_SOCCERO_SHOOTLOW               0x1E004408
14084#define DIBUTTON_SOCCERO_SHOOTHIGH              0x1E004409
14085#define DIBUTTON_SOCCERO_PASSTHRU               0x1E00440A
14086#define DIBUTTON_SOCCERO_SPRINT                 0x1E00440B
14087#define DIBUTTON_SOCCERO_CONTROL                0x1E00440C
14088#define DIBUTTON_SOCCERO_HEAD                   0x1E00440D
14089#define DIBUTTON_SOCCERO_LEFT_LINK              0x1E00C4E4
14090#define DIBUTTON_SOCCERO_RIGHT_LINK             0x1E00C4EC
14091#define DIBUTTON_SOCCERO_FORWARD_LINK           0x1E0144E0
14092#define DIBUTTON_SOCCERO_BACK_LINK              0x1E0144E8
14093#define DIBUTTON_SOCCERO_DEVICE                 0x1E0044FE
14094#define DIBUTTON_SOCCERO_PAUSE                  0x1E0044FC
14095
14096#define DIVIRTUAL_SPORTS_SOCCER_DEFENSE         0x1F000000
14097#define DIAXIS_SOCCERD_LATERAL                  0x1F008201
14098#define DIAXIS_SOCCERD_MOVE                     0x1F010202
14099#define DIBUTTON_SOCCERD_BLOCK                  0x1F000401
14100#define DIBUTTON_SOCCERD_STEAL                  0x1F000402
14101#define DIBUTTON_SOCCERD_FAKE                   0x1F000403
14102#define DIBUTTON_SOCCERD_PLAYER                 0x1F000404
14103#define DIBUTTON_SOCCERD_SPECIAL                0x1F000405
14104#define DIBUTTON_SOCCERD_SELECT                 0x1F000406
14105#define DIBUTTON_SOCCERD_SLIDE                  0x1F000407
14106#define DIBUTTON_SOCCERD_MENU                   0x1F0004FD
14107
14108#define DIHATSWITCH_SOCCERD_GLANCE              0x1F004601
14109#define DIBUTTON_SOCCERD_FOUL                   0x1F004408
14110#define DIBUTTON_SOCCERD_HEAD                   0x1F004409
14111#define DIBUTTON_SOCCERD_CLEAR                  0x1F00440A
14112#define DIBUTTON_SOCCERD_GOALIECHARGE           0x1F00440B
14113#define DIBUTTON_SOCCERD_SUBSTITUTE             0x1F00440C
14114#define DIBUTTON_SOCCERD_LEFT_LINK              0x1F00C4E4
14115#define DIBUTTON_SOCCERD_RIGHT_LINK             0x1F00C4EC
14116#define DIBUTTON_SOCCERD_FORWARD_LINK           0x1F0144E0
14117#define DIBUTTON_SOCCERD_BACK_LINK              0x1F0144E8
14118#define DIBUTTON_SOCCERD_DEVICE                 0x1F0044FE
14119#define DIBUTTON_SOCCERD_PAUSE                  0x1F0044FC
14120
14121#define DIVIRTUAL_SPORTS_RACQUET                0x20000000
14122#define DIAXIS_RACQUET_LATERAL                  0x20008201
14123#define DIAXIS_RACQUET_MOVE                     0x20010202
14124#define DIBUTTON_RACQUET_SWING                  0x20000401
14125#define DIBUTTON_RACQUET_BACKSWING              0x20000402
14126#define DIBUTTON_RACQUET_SMASH                  0x20000403
14127#define DIBUTTON_RACQUET_SPECIAL                0x20000404
14128#define DIBUTTON_RACQUET_SELECT                 0x20000405
14129#define DIBUTTON_RACQUET_MENU                   0x200004FD
14130
14131#define DIHATSWITCH_RACQUET_GLANCE              0x20004601
14132#define DIBUTTON_RACQUET_TIMEOUT                0x20004406
14133#define DIBUTTON_RACQUET_SUBSTITUTE             0x20004407
14134#define DIBUTTON_RACQUET_LEFT_LINK              0x2000C4E4
14135#define DIBUTTON_RACQUET_RIGHT_LINK             0x2000C4EC
14136#define DIBUTTON_RACQUET_FORWARD_LINK           0x200144E0
14137#define DIBUTTON_RACQUET_BACK_LINK              0x200144E8
14138#define DIBUTTON_RACQUET_DEVICE                 0x200044FE
14139#define DIBUTTON_RACQUET_PAUSE                  0x200044FC
14140
14141#define DIVIRTUAL_ARCADE_SIDE2SIDE              0x21000000
14142#define DIAXIS_ARCADES_LATERAL                  0x21008201
14143#define DIAXIS_ARCADES_MOVE                     0x21010202
14144#define DIBUTTON_ARCADES_THROW                  0x21000401
14145#define DIBUTTON_ARCADES_CARRY                  0x21000402
14146#define DIBUTTON_ARCADES_ATTACK                 0x21000403
14147#define DIBUTTON_ARCADES_SPECIAL                0x21000404
14148#define DIBUTTON_ARCADES_SELECT                 0x21000405
14149#define DIBUTTON_ARCADES_MENU                   0x210004FD
14150
14151#define DIHATSWITCH_ARCADES_VIEW                0x21004601
14152#define DIBUTTON_ARCADES_LEFT_LINK              0x2100C4E4
14153#define DIBUTTON_ARCADES_RIGHT_LINK             0x2100C4EC
14154#define DIBUTTON_ARCADES_FORWARD_LINK           0x210144E0
14155#define DIBUTTON_ARCADES_BACK_LINK              0x210144E8
14156#define DIBUTTON_ARCADES_VIEW_UP_LINK           0x2107C4E0
14157#define DIBUTTON_ARCADES_VIEW_DOWN_LINK         0x2107C4E8
14158#define DIBUTTON_ARCADES_VIEW_LEFT_LINK         0x2107C4E4
14159#define DIBUTTON_ARCADES_VIEW_RIGHT_LINK        0x2107C4EC
14160#define DIBUTTON_ARCADES_DEVICE                 0x210044FE
14161#define DIBUTTON_ARCADES_PAUSE                  0x210044FC
14162
14163#define DIVIRTUAL_ARCADE_PLATFORM               0x22000000
14164#define DIAXIS_ARCADEP_LATERAL                  0x22008201
14165#define DIAXIS_ARCADEP_MOVE                     0x22010202
14166#define DIBUTTON_ARCADEP_JUMP                   0x22000401
14167#define DIBUTTON_ARCADEP_FIRE                   0x22000402
14168#define DIBUTTON_ARCADEP_CROUCH                 0x22000403
14169#define DIBUTTON_ARCADEP_SPECIAL                0x22000404
14170#define DIBUTTON_ARCADEP_SELECT                 0x22000405
14171#define DIBUTTON_ARCADEP_MENU                   0x220004FD
14172
14173#define DIHATSWITCH_ARCADEP_VIEW                0x22004601
14174#define DIBUTTON_ARCADEP_FIRESECONDARY          0x22004406
14175#define DIBUTTON_ARCADEP_LEFT_LINK              0x2200C4E4
14176#define DIBUTTON_ARCADEP_RIGHT_LINK             0x2200C4EC
14177#define DIBUTTON_ARCADEP_FORWARD_LINK           0x220144E0
14178#define DIBUTTON_ARCADEP_BACK_LINK              0x220144E8
14179#define DIBUTTON_ARCADEP_VIEW_UP_LINK           0x2207C4E0
14180#define DIBUTTON_ARCADEP_VIEW_DOWN_LINK         0x2207C4E8
14181#define DIBUTTON_ARCADEP_VIEW_LEFT_LINK         0x2207C4E4
14182#define DIBUTTON_ARCADEP_VIEW_RIGHT_LINK        0x2207C4EC
14183#define DIBUTTON_ARCADEP_DEVICE                 0x220044FE
14184#define DIBUTTON_ARCADEP_PAUSE                  0x220044FC
14185
14186#define DIVIRTUAL_CAD_2DCONTROL                 0x23000000
14187#define DIAXIS_2DCONTROL_LATERAL                0x23008201
14188#define DIAXIS_2DCONTROL_MOVE                   0x23010202
14189#define DIAXIS_2DCONTROL_INOUT                  0x23018203
14190#define DIBUTTON_2DCONTROL_SELECT               0x23000401
14191#define DIBUTTON_2DCONTROL_SPECIAL1             0x23000402
14192#define DIBUTTON_2DCONTROL_SPECIAL              0x23000403
14193#define DIBUTTON_2DCONTROL_SPECIAL2             0x23000404
14194#define DIBUTTON_2DCONTROL_MENU                 0x230004FD
14195
14196#define DIHATSWITCH_2DCONTROL_HATSWITCH         0x23004601
14197#define DIAXIS_2DCONTROL_ROTATEZ                0x23024204
14198#define DIBUTTON_2DCONTROL_DISPLAY              0x23004405
14199#define DIBUTTON_2DCONTROL_DEVICE               0x230044FE
14200#define DIBUTTON_2DCONTROL_PAUSE                0x230044FC
14201
14202#define DIVIRTUAL_CAD_3DCONTROL                 0x24000000
14203#define DIAXIS_3DCONTROL_LATERAL                0x24008201
14204#define DIAXIS_3DCONTROL_MOVE                   0x24010202
14205#define DIAXIS_3DCONTROL_INOUT                  0x24018203
14206#define DIBUTTON_3DCONTROL_SELECT               0x24000401
14207#define DIBUTTON_3DCONTROL_SPECIAL1             0x24000402
14208#define DIBUTTON_3DCONTROL_SPECIAL              0x24000403
14209#define DIBUTTON_3DCONTROL_SPECIAL2             0x24000404
14210#define DIBUTTON_3DCONTROL_MENU                 0x240004FD
14211
14212#define DIHATSWITCH_3DCONTROL_HATSWITCH         0x24004601
14213#define DIAXIS_3DCONTROL_ROTATEX                0x24034204
14214#define DIAXIS_3DCONTROL_ROTATEY                0x2402C205
14215#define DIAXIS_3DCONTROL_ROTATEZ                0x24024206
14216#define DIBUTTON_3DCONTROL_DISPLAY              0x24004405
14217#define DIBUTTON_3DCONTROL_DEVICE               0x240044FE
14218#define DIBUTTON_3DCONTROL_PAUSE                0x240044FC
14219
14220#define DIVIRTUAL_CAD_FLYBY                     0x25000000
14221#define DIAXIS_CADF_LATERAL                     0x25008201
14222#define DIAXIS_CADF_MOVE                        0x25010202
14223#define DIAXIS_CADF_INOUT                       0x25018203
14224#define DIBUTTON_CADF_SELECT                    0x25000401
14225#define DIBUTTON_CADF_SPECIAL1                  0x25000402
14226#define DIBUTTON_CADF_SPECIAL                   0x25000403
14227#define DIBUTTON_CADF_SPECIAL2                  0x25000404
14228#define DIBUTTON_CADF_MENU                      0x250004FD
14229
14230#define DIHATSWITCH_CADF_HATSWITCH              0x25004601
14231#define DIAXIS_CADF_ROTATEX                     0x25034204
14232#define DIAXIS_CADF_ROTATEY                     0x2502C205
14233#define DIAXIS_CADF_ROTATEZ                     0x25024206
14234#define DIBUTTON_CADF_DISPLAY                   0x25004405
14235#define DIBUTTON_CADF_DEVICE                    0x250044FE
14236#define DIBUTTON_CADF_PAUSE                     0x250044FC
14237
14238#define DIVIRTUAL_CAD_MODEL                     0x26000000
14239#define DIAXIS_CADM_LATERAL                     0x26008201
14240#define DIAXIS_CADM_MOVE                        0x26010202
14241#define DIAXIS_CADM_INOUT                       0x26018203
14242#define DIBUTTON_CADM_SELECT                    0x26000401
14243#define DIBUTTON_CADM_SPECIAL1                  0x26000402
14244#define DIBUTTON_CADM_SPECIAL                   0x26000403
14245#define DIBUTTON_CADM_SPECIAL2                  0x26000404
14246#define DIBUTTON_CADM_MENU                      0x260004FD
14247
14248#define DIHATSWITCH_CADM_HATSWITCH              0x26004601
14249#define DIAXIS_CADM_ROTATEX                     0x26034204
14250#define DIAXIS_CADM_ROTATEY                     0x2602C205
14251#define DIAXIS_CADM_ROTATEZ                     0x26024206
14252#define DIBUTTON_CADM_DISPLAY                   0x26004405
14253#define DIBUTTON_CADM_DEVICE                    0x260044FE
14254#define DIBUTTON_CADM_PAUSE                     0x260044FC
14255
14256#define DIVIRTUAL_REMOTE_CONTROL                0x27000000
14257#define DIAXIS_REMOTE_SLIDER                    0x27050201
14258#define DIBUTTON_REMOTE_MUTE                    0x27000401
14259#define DIBUTTON_REMOTE_SELECT                  0x27000402
14260#define DIBUTTON_REMOTE_PLAY                    0x27002403
14261#define DIBUTTON_REMOTE_CUE                     0x27002404
14262#define DIBUTTON_REMOTE_REVIEW                  0x27002405
14263#define DIBUTTON_REMOTE_CHANGE                  0x27002406
14264#define DIBUTTON_REMOTE_RECORD                  0x27002407
14265#define DIBUTTON_REMOTE_MENU                    0x270004FD
14266
14267#define DIAXIS_REMOTE_SLIDER2                   0x27054202
14268#define DIBUTTON_REMOTE_TV                      0x27005C08
14269#define DIBUTTON_REMOTE_CABLE                   0x27005C09
14270#define DIBUTTON_REMOTE_CD                      0x27005C0A
14271#define DIBUTTON_REMOTE_VCR                     0x27005C0B
14272#define DIBUTTON_REMOTE_TUNER                   0x27005C0C
14273#define DIBUTTON_REMOTE_DVD                     0x27005C0D
14274#define DIBUTTON_REMOTE_ADJUST                  0x27005C0E
14275#define DIBUTTON_REMOTE_DIGIT0                  0x2700540F
14276#define DIBUTTON_REMOTE_DIGIT1                  0x27005410
14277#define DIBUTTON_REMOTE_DIGIT2                  0x27005411
14278#define DIBUTTON_REMOTE_DIGIT3                  0x27005412
14279#define DIBUTTON_REMOTE_DIGIT4                  0x27005413
14280#define DIBUTTON_REMOTE_DIGIT5                  0x27005414
14281#define DIBUTTON_REMOTE_DIGIT6                  0x27005415
14282#define DIBUTTON_REMOTE_DIGIT7                  0x27005416
14283#define DIBUTTON_REMOTE_DIGIT8                  0x27005417
14284#define DIBUTTON_REMOTE_DIGIT9                  0x27005418
14285#define DIBUTTON_REMOTE_DEVICE                  0x270044FE
14286#define DIBUTTON_REMOTE_PAUSE                   0x270044FC
14287
14288#define DIVIRTUAL_BROWSER_CONTROL               0x28000000
14289#define DIAXIS_BROWSER_LATERAL                  0x28008201
14290#define DIAXIS_BROWSER_MOVE                     0x28010202
14291#define DIBUTTON_BROWSER_SELECT                 0x28000401
14292#define DIAXIS_BROWSER_VIEW                     0x28018203
14293#define DIBUTTON_BROWSER_REFRESH                0x28000402
14294#define DIBUTTON_BROWSER_MENU                   0x280004FD
14295
14296#define DIBUTTON_BROWSER_SEARCH                 0x28004403
14297#define DIBUTTON_BROWSER_STOP                   0x28004404
14298#define DIBUTTON_BROWSER_HOME                   0x28004405
14299#define DIBUTTON_BROWSER_FAVORITES              0x28004406
14300#define DIBUTTON_BROWSER_NEXT                   0x28004407
14301#define DIBUTTON_BROWSER_PREVIOUS               0x28004408
14302#define DIBUTTON_BROWSER_HISTORY                0x28004409
14303#define DIBUTTON_BROWSER_PRINT                  0x2800440A
14304#define DIBUTTON_BROWSER_DEVICE                 0x280044FE
14305#define DIBUTTON_BROWSER_PAUSE                  0x280044FC
14306
14307#define DIVIRTUAL_DRIVING_MECHA                 0x29000000
14308#define DIAXIS_MECHA_STEER                      0x29008201
14309#define DIAXIS_MECHA_TORSO                      0x29010202
14310#define DIAXIS_MECHA_ROTATE                     0x29020203
14311#define DIAXIS_MECHA_THROTTLE                   0x29038204
14312#define DIBUTTON_MECHA_FIRE                     0x29000401
14313#define DIBUTTON_MECHA_WEAPONS                  0x29000402
14314#define DIBUTTON_MECHA_TARGET                   0x29000403
14315#define DIBUTTON_MECHA_REVERSE                  0x29000404
14316#define DIBUTTON_MECHA_ZOOM                     0x29000405
14317#define DIBUTTON_MECHA_JUMP                     0x29000406
14318#define DIBUTTON_MECHA_MENU                     0x290004FD
14319
14320#define DIBUTTON_MECHA_CENTER                   0x29004407
14321#define DIHATSWITCH_MECHA_GLANCE                0x29004601
14322#define DIBUTTON_MECHA_VIEW                     0x29004408
14323#define DIBUTTON_MECHA_FIRESECONDARY            0x29004409
14324#define DIBUTTON_MECHA_LEFT_LINK                0x2900C4E4
14325#define DIBUTTON_MECHA_RIGHT_LINK               0x2900C4EC
14326#define DIBUTTON_MECHA_FORWARD_LINK             0x290144E0
14327#define DIBUTTON_MECHA_BACK_LINK                0x290144E8
14328#define DIBUTTON_MECHA_ROTATE_LEFT_LINK         0x290244E4
14329#define DIBUTTON_MECHA_ROTATE_RIGHT_LINK        0x290244EC
14330#define DIBUTTON_MECHA_FASTER_LINK              0x2903C4E0
14331#define DIBUTTON_MECHA_SLOWER_LINK              0x2903C4E8
14332#define DIBUTTON_MECHA_DEVICE                   0x290044FE
14333#define DIBUTTON_MECHA_PAUSE                    0x290044FC
14334
14335#define DIAXIS_ANY_X_1                          0xFF00C201
14336#define DIAXIS_ANY_X_2                          0xFF00C202
14337#define DIAXIS_ANY_Y_1                          0xFF014201
14338#define DIAXIS_ANY_Y_2                          0xFF014202
14339#define DIAXIS_ANY_Z_1                          0xFF01C201
14340#define DIAXIS_ANY_Z_2                          0xFF01C202
14341#define DIAXIS_ANY_R_1                          0xFF024201
14342#define DIAXIS_ANY_R_2                          0xFF024202
14343#define DIAXIS_ANY_U_1                          0xFF02C201
14344#define DIAXIS_ANY_U_2                          0xFF02C202
14345#define DIAXIS_ANY_V_1                          0xFF034201
14346#define DIAXIS_ANY_V_2                          0xFF034202
14347#define DIAXIS_ANY_A_1                          0xFF03C201
14348#define DIAXIS_ANY_A_2                          0xFF03C202
14349#define DIAXIS_ANY_B_1                          0xFF044201
14350#define DIAXIS_ANY_B_2                          0xFF044202
14351#define DIAXIS_ANY_C_1                          0xFF04C201
14352#define DIAXIS_ANY_C_2                          0xFF04C202
14353#define DIAXIS_ANY_S_1                          0xFF054201
14354#define DIAXIS_ANY_S_2                          0xFF054202
14355
14356#define DIAXIS_ANY_1                            0xFF004201
14357#define DIAXIS_ANY_2                            0xFF004202
14358#define DIAXIS_ANY_3                            0xFF004203
14359#define DIAXIS_ANY_4                            0xFF004204
14360
14361#define DIPOV_ANY_1                             0xFF004601
14362#define DIPOV_ANY_2                             0xFF004602
14363#define DIPOV_ANY_3                             0xFF004603
14364#define DIPOV_ANY_4                             0xFF004604
14365
14366#define DIBUTTON_ANY(instance)                  ( 0xFF004400 | instance )
14367
14368#ifdef __cplusplus
14369};
14370#endif
14371
14372#endif
14373
14374#ifdef _INC_MMSYSTEM
14375#ifndef MMNOJOY
14376
14377#ifndef __VJOYDX_INCLUDED__
14378#define __VJOYDX_INCLUDED__
14379
14380#ifdef __cplusplus
14381extern "C" {
14382#endif
14383
14384#define JOY_PASSDRIVERDATA          0x10000000l
14385
14386WINMMAPI MMRESULT WINAPI joyConfigChanged( DWORD dwFlags );
14387
14388#define JOY_HWS_ISHEADTRACKER       0x02000000l
14389
14390#define JOY_HWS_ISGAMEPORTDRIVER    0x04000000l
14391
14392#define JOY_HWS_ISANALOGPORTDRIVER  0x08000000l
14393
14394#define JOY_HWS_AUTOLOAD            0x10000000l
14395
14396#define JOY_HWS_NODEVNODE           0x20000000l
14397
14398#define JOY_HWS_ISGAMEPORTBUS       0x80000000l
14399#define JOY_HWS_GAMEPORTBUSBUSY     0x00000001l
14400
14401#define JOY_US_VOLATILE             0x00000008L
14402
14403#ifdef __cplusplus
14404};
14405#endif
14406
14407#endif
14408
14409#endif
14410#endif
14411
14412#ifndef DIJ_RINGZERO
14413
14414#ifdef _INC_MMDDK
14415#ifndef MMNOJOYDEV
14416
14417#ifndef __VJOYDXD_INCLUDED__
14418#define __VJOYDXD_INCLUDED__
14419
14420#define JOY_OEMPOLL_PASSDRIVERDATA  7
14421
14422#endif
14423
14424#endif
14425#endif
14426
14427#endif
14428
14429#endif
14430
14431#undef _THIS
14432#define _THIS   SDL_AudioDevice *this
14433
14434#undef SDLAUDIOHIDDEN
14435#define SDLAUDIOHIDDEN ((struct SDL_PrivateAudioDataDSOUND*)this->hidden)
14436struct SDL_PrivateAudioDataDSOUND
14437{
14438    LPDIRECTSOUND sound;
14439    LPDIRECTSOUNDBUFFER mixbuf;
14440    int num_buffers;
14441    int mixlen;
14442    DWORD lastchunk;
14443    Uint8 *locked_buf;
14444};
14445
14446#endif
14447
14448#ifndef WAVE_FORMAT_IEEE_FLOAT
14449#define WAVE_FORMAT_IEEE_FLOAT 0x0003
14450#endif
14451
14452static void* DSoundDLL = NULL;
14453typedef HRESULT(WINAPI*fnDirectSoundCreate8)(LPGUID,LPDIRECTSOUND*,LPUNKNOWN);
14454typedef HRESULT(WINAPI*fnDirectSoundEnumerateW)(LPDSENUMCALLBACKW, LPVOID);
14455typedef HRESULT(WINAPI*fnDirectSoundCaptureEnumerateW)(LPDSENUMCALLBACKW,LPVOID);
14456static fnDirectSoundCreate8 pDirectSoundCreate8 = NULL;
14457static fnDirectSoundEnumerateW pDirectSoundEnumerateW = NULL;
14458static fnDirectSoundCaptureEnumerateW pDirectSoundCaptureEnumerateW = NULL;
14459
14460static void
14461DSOUND_Unload(void)
14462{
14463    pDirectSoundCreate8 = NULL;
14464    pDirectSoundEnumerateW = NULL;
14465    pDirectSoundCaptureEnumerateW = NULL;
14466
14467    if (DSoundDLL != NULL) {
14468        SDL_UnloadObject(DSoundDLL);
14469        DSoundDLL = NULL;
14470    }
14471}
14472
14473static int
14474DSOUND_Load(void)
14475{
14476    int loaded = 0;
14477
14478    DSOUND_Unload();
14479
14480    DSoundDLL = SDL_LoadObject("DSOUND.DLL");
14481    if (DSoundDLL == NULL) {
14482        SDL_SetError("DirectSound: failed to load DSOUND.DLL");
14483    } else {
14484
14485        #define DSOUNDLOAD(f) { \
14486            p##f = (fn##f) SDL_LoadFunction(DSoundDLL, #f); \
14487            if (!p##f) loaded = 0; \
14488        }
14489        loaded = 1;
14490        DSOUNDLOAD(DirectSoundCreate8);
14491        DSOUNDLOAD(DirectSoundEnumerateW);
14492        DSOUNDLOAD(DirectSoundCaptureEnumerateW);
14493        #undef DSOUNDLOAD
14494
14495        if (!loaded) {
14496            SDL_SetError("DirectSound: System doesn't appear to have DX8.");
14497        }
14498    }
14499
14500    if (!loaded) {
14501        DSOUND_Unload();
14502    }
14503
14504    return loaded;
14505}
14506
14507static int
14508SetDSerror(const char *function, int code)
14509{
14510    static const char *error;
14511    static char errbuf[1024];
14512
14513    errbuf[0] = 0;
14514    switch (code) {
14515    case E_NOINTERFACE:
14516        error = "Unsupported interface -- Is DirectX 8.0 or later installed?";
14517        break;
14518    case DSERR_ALLOCATED:
14519        error = "Audio device in use";
14520        break;
14521    case DSERR_BADFORMAT:
14522        error = "Unsupported audio format";
14523        break;
14524    case DSERR_BUFFERLOST:
14525        error = "Mixing buffer was lost";
14526        break;
14527    case DSERR_CONTROLUNAVAIL:
14528        error = "Control requested is not available";
14529        break;
14530    case DSERR_INVALIDCALL:
14531        error = "Invalid call for the current state";
14532        break;
14533    case DSERR_INVALIDPARAM:
14534        error = "Invalid parameter";
14535        break;
14536    case DSERR_NODRIVER:
14537        error = "No audio device found";
14538        break;
14539    case DSERR_OUTOFMEMORY:
14540        error = "Out of memory";
14541        break;
14542    case DSERR_PRIOLEVELNEEDED:
14543        error = "Caller doesn't have priority";
14544        break;
14545    case DSERR_UNSUPPORTED:
14546        error = "Function not supported";
14547        break;
14548    default:
14549        SDL_snprintf(errbuf, SDL_arraysize(errbuf),
14550                     "%s: Unknown DirectSound error: 0x%x", function, code);
14551        break;
14552    }
14553    if (!errbuf[0]) {
14554        SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function,
14555                     error);
14556    }
14557    return SDL_SetError("%s", errbuf);
14558}
14559
14560static BOOL CALLBACK
14561FindAllDevs(LPGUID guid, LPCWSTR desc, LPCWSTR module, LPVOID data)
14562{
14563    SDL_AddAudioDevice addfn = (SDL_AddAudioDevice) data;
14564    if (guid != NULL) {
14565        char *str = WIN_StringToUTF8(desc);
14566        if (str != NULL) {
14567            addfn(str);
14568            SDL_free(str);
14569        }
14570    }
14571    return TRUE;
14572}
14573
14574static void
14575DSOUND_DetectDevices(int iscapture, SDL_AddAudioDevice addfn)
14576{
14577    if (iscapture) {
14578        pDirectSoundCaptureEnumerateW(FindAllDevs, addfn);
14579    } else {
14580        pDirectSoundEnumerateW(FindAllDevs, addfn);
14581    }
14582}
14583
14584static void
14585DSOUND_WaitDevice(_THIS)
14586{
14587    DWORD status = 0;
14588    DWORD cursor = 0;
14589    DWORD junk = 0;
14590    HRESULT result = DS_OK;
14591
14592    result = IDirectSoundBuffer_GetCurrentPosition(SDLAUDIOHIDDEN->mixbuf,
14593                                                   &junk, &cursor);
14594    if (result != DS_OK) {
14595        if (result == DSERR_BUFFERLOST) {
14596            IDirectSoundBuffer_Restore(SDLAUDIOHIDDEN->mixbuf);
14597        }
14598#ifdef DEBUG_SOUND
14599        SetDSerror("DirectSound GetCurrentPosition", result);
14600#endif
14601        return;
14602    }
14603
14604    while ((cursor / SDLAUDIOHIDDEN->mixlen) == SDLAUDIOHIDDEN->lastchunk) {
14605
14606        SDL_Delay(1);
14607
14608        IDirectSoundBuffer_GetStatus(SDLAUDIOHIDDEN->mixbuf, &status);
14609        if ((status & DSBSTATUS_BUFFERLOST)) {
14610            IDirectSoundBuffer_Restore(SDLAUDIOHIDDEN->mixbuf);
14611            IDirectSoundBuffer_GetStatus(SDLAUDIOHIDDEN->mixbuf, &status);
14612            if ((status & DSBSTATUS_BUFFERLOST)) {
14613                break;
14614            }
14615        }
14616        if (!(status & DSBSTATUS_PLAYING)) {
14617            result = IDirectSoundBuffer_Play(SDLAUDIOHIDDEN->mixbuf, 0, 0,
14618                                             DSBPLAY_LOOPING);
14619            if (result == DS_OK) {
14620                continue;
14621            }
14622#ifdef DEBUG_SOUND
14623            SetDSerror("DirectSound Play", result);
14624#endif
14625            return;
14626        }
14627
14628        result = IDirectSoundBuffer_GetCurrentPosition(SDLAUDIOHIDDEN->mixbuf,
14629                                                       &junk, &cursor);
14630        if (result != DS_OK) {
14631            SetDSerror("DirectSound GetCurrentPosition", result);
14632            return;
14633        }
14634    }
14635}
14636
14637static void
14638DSOUND_PlayDevice(_THIS)
14639{
14640
14641    if (SDLAUDIOHIDDEN->locked_buf) {
14642        IDirectSoundBuffer_Unlock(SDLAUDIOHIDDEN->mixbuf,
14643                                  SDLAUDIOHIDDEN->locked_buf,
14644                                  SDLAUDIOHIDDEN->mixlen, NULL, 0);
14645    }
14646
14647}
14648
14649static Uint8 *
14650DSOUND_GetDeviceBuf(_THIS)
14651{
14652    DWORD cursor = 0;
14653    DWORD junk = 0;
14654    HRESULT result = DS_OK;
14655    DWORD rawlen = 0;
14656
14657    SDLAUDIOHIDDEN->locked_buf = NULL;
14658    result = IDirectSoundBuffer_GetCurrentPosition(SDLAUDIOHIDDEN->mixbuf,
14659                                                   &junk, &cursor);
14660    if (result == DSERR_BUFFERLOST) {
14661        IDirectSoundBuffer_Restore(SDLAUDIOHIDDEN->mixbuf);
14662        result = IDirectSoundBuffer_GetCurrentPosition(SDLAUDIOHIDDEN->mixbuf,
14663                                                       &junk, &cursor);
14664    }
14665    if (result != DS_OK) {
14666        SetDSerror("DirectSound GetCurrentPosition", result);
14667        return (NULL);
14668    }
14669    cursor /= SDLAUDIOHIDDEN->mixlen;
14670#ifdef DEBUG_SOUND
14671
14672    {
14673        DWORD spot = cursor;
14674        if (spot < SDLAUDIOHIDDEN->lastchunk) {
14675            spot += SDLAUDIOHIDDEN->num_buffers;
14676        }
14677        if (spot > SDLAUDIOHIDDEN->lastchunk + 1) {
14678            fprintf(stderr, "Audio dropout, missed %d fragments\n",
14679                    (spot - (SDLAUDIOHIDDEN->lastchunk + 1)));
14680        }
14681    }
14682#endif
14683    SDLAUDIOHIDDEN->lastchunk = cursor;
14684    cursor = (cursor + 1) % SDLAUDIOHIDDEN->num_buffers;
14685    cursor *= SDLAUDIOHIDDEN->mixlen;
14686
14687    result = IDirectSoundBuffer_Lock(SDLAUDIOHIDDEN->mixbuf, cursor,
14688                                     SDLAUDIOHIDDEN->mixlen,
14689                                     (LPVOID *) & SDLAUDIOHIDDEN->locked_buf,
14690                                     &rawlen, NULL, &junk, 0);
14691    if (result == DSERR_BUFFERLOST) {
14692        IDirectSoundBuffer_Restore(SDLAUDIOHIDDEN->mixbuf);
14693        result = IDirectSoundBuffer_Lock(SDLAUDIOHIDDEN->mixbuf, cursor,
14694                                         SDLAUDIOHIDDEN->mixlen,
14695                                         (LPVOID *) & 
14696                                         SDLAUDIOHIDDEN->locked_buf, &rawlen, NULL,
14697                                         &junk, 0);
14698    }
14699    if (result != DS_OK) {
14700        SetDSerror("DirectSound Lock", result);
14701        return (NULL);
14702    }
14703    return (SDLAUDIOHIDDEN->locked_buf);
14704}
14705
14706static void
14707DSOUND_WaitDone(_THIS)
14708{
14709    Uint8 *stream = DSOUND_GetDeviceBuf(this);
14710
14711    if (stream != NULL) {
14712        SDL_memset(stream, this->spec.silence, SDLAUDIOHIDDEN->mixlen);
14713        DSOUND_PlayDevice(this);
14714    }
14715    DSOUND_WaitDevice(this);
14716
14717    IDirectSoundBuffer_Stop(SDLAUDIOHIDDEN->mixbuf);
14718}
14719
14720static void
14721DSOUND_CloseDevice(_THIS)
14722{
14723    if (SDLAUDIOHIDDEN != NULL) {
14724        if (SDLAUDIOHIDDEN->sound != NULL) {
14725            if (SDLAUDIOHIDDEN->mixbuf != NULL) {
14726
14727                IDirectSoundBuffer_Release(SDLAUDIOHIDDEN->mixbuf);
14728                SDLAUDIOHIDDEN->mixbuf = NULL;
14729            }
14730            IDirectSound_Release(SDLAUDIOHIDDEN->sound);
14731            SDLAUDIOHIDDEN->sound = NULL;
14732        }
14733
14734        SDL_free(SDLAUDIOHIDDEN);
14735        this->hidden = NULL;
14736    }
14737}
14738
14739static int
14740CreateSecondary(_THIS, HWND focus)
14741{
14742    LPDIRECTSOUND sndObj = SDLAUDIOHIDDEN->sound;
14743    LPDIRECTSOUNDBUFFER *sndbuf = &SDLAUDIOHIDDEN->mixbuf;
14744    Uint32 chunksize = this->spec.size;
14745    const int numchunks = 8;
14746    HRESULT result = DS_OK;
14747    DSBUFFERDESC format;
14748    LPVOID pvAudioPtr1, pvAudioPtr2;
14749    DWORD dwAudioBytes1, dwAudioBytes2;
14750    WAVEFORMATEX wfmt;
14751
14752    SDL_zero(wfmt);
14753
14754    if (SDL_AUDIO_ISFLOAT(this->spec.format)) {
14755        wfmt.wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
14756    } else {
14757        wfmt.wFormatTag = WAVE_FORMAT_PCM;
14758    }
14759
14760    wfmt.wBitsPerSample = SDL_AUDIO_BITSIZE(this->spec.format);
14761    wfmt.nChannels = this->spec.channels;
14762    wfmt.nSamplesPerSec = this->spec.freq;
14763    wfmt.nBlockAlign = wfmt.nChannels * (wfmt.wBitsPerSample / 8);
14764    wfmt.nAvgBytesPerSec = wfmt.nSamplesPerSec * wfmt.nBlockAlign;
14765
14766    SDL_CalculateAudioSpec(&this->spec);
14767
14768    if (focus) {
14769        result = IDirectSound_SetCooperativeLevel(sndObj,
14770                                                  focus, DSSCL_PRIORITY);
14771    } else {
14772        result = IDirectSound_SetCooperativeLevel(sndObj,
14773                                                  GetDesktopWindow(),
14774                                                  DSSCL_NORMAL);
14775    }
14776    if (result != DS_OK) {
14777        return SetDSerror("DirectSound SetCooperativeLevel", result);
14778    }
14779
14780    SDL_zero(format);
14781    format.dwSize = sizeof(format);
14782    format.dwFlags = DSBCAPS_GETCURRENTPOSITION2;
14783    if (!focus) {
14784        format.dwFlags |= DSBCAPS_GLOBALFOCUS;
14785    } else {
14786        format.dwFlags |= DSBCAPS_STICKYFOCUS;
14787    }
14788    format.dwBufferBytes = numchunks * chunksize;
14789    if ((format.dwBufferBytes < DSBSIZE_MIN) ||
14790        (format.dwBufferBytes > DSBSIZE_MAX)) {
14791        return SDL_SetError("Sound buffer size must be between %d and %d",
14792                            DSBSIZE_MIN / numchunks, DSBSIZE_MAX / numchunks);
14793    }
14794    format.dwReserved = 0;
14795    format.lpwfxFormat = &wfmt;
14796    result = IDirectSound_CreateSoundBuffer(sndObj, &format, sndbuf, NULL);
14797    if (result != DS_OK) {
14798        return SetDSerror("DirectSound CreateSoundBuffer", result);
14799    }
14800    IDirectSoundBuffer_SetFormat(*sndbuf, &wfmt);
14801
14802    result = IDirectSoundBuffer_Lock(*sndbuf, 0, format.dwBufferBytes,
14803                                     (LPVOID *) & pvAudioPtr1, &dwAudioBytes1,
14804                                     (LPVOID *) & pvAudioPtr2, &dwAudioBytes2,
14805                                     DSBLOCK_ENTIREBUFFER);
14806    if (result == DS_OK) {
14807        SDL_memset(pvAudioPtr1, this->spec.silence, dwAudioBytes1);
14808        IDirectSoundBuffer_Unlock(*sndbuf,
14809                                  (LPVOID) pvAudioPtr1, dwAudioBytes1,
14810                                  (LPVOID) pvAudioPtr2, dwAudioBytes2);
14811    }
14812
14813    return (numchunks);
14814}
14815
14816typedef struct FindDevGUIDData
14817{
14818    const char *devname;
14819    GUID guid;
14820    int found;
14821} FindDevGUIDData;
14822
14823static BOOL CALLBACK
14824FindDevGUID(LPGUID guid, LPCWSTR desc, LPCWSTR module, LPVOID _data)
14825{
14826    if (guid != NULL) {
14827        FindDevGUIDData *data = (FindDevGUIDData *) _data;
14828        char *str = WIN_StringToUTF8(desc);
14829        const int match = (SDL_strcmp(str, data->devname) == 0);
14830        SDL_free(str);
14831        if (match) {
14832            data->found = 1;
14833            SDL_memcpy(&data->guid, guid, sizeof (data->guid));
14834            return FALSE;
14835        }
14836    }
14837    return TRUE;
14838}
14839
14840static int
14841DSOUND_OpenDevice(_THIS, const char *devname, int iscapture)
14842{
14843    HRESULT result;
14844    SDL_bool valid_format = SDL_FALSE;
14845    SDL_bool tried_format = SDL_FALSE;
14846    SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
14847    FindDevGUIDData devguid;
14848    LPGUID guid = NULL;
14849
14850    if (devname != NULL) {
14851        devguid.found = 0;
14852        devguid.devname = devname;
14853        if (iscapture)
14854            pDirectSoundCaptureEnumerateW(FindDevGUID, &devguid);
14855        else
14856            pDirectSoundEnumerateW(FindDevGUID, &devguid);
14857
14858        if (!devguid.found) {
14859            return SDL_SetError("DirectSound: Requested device not found");
14860        }
14861        guid = &devguid.guid;
14862    }
14863
14864    this->hidden = (struct SDL_PrivateAudioData *)
14865        SDL_malloc((sizeof *SDLAUDIOHIDDEN));
14866    if (SDLAUDIOHIDDEN == NULL) {
14867        return SDL_OutOfMemory();
14868    }
14869    SDL_memset(SDLAUDIOHIDDEN, 0, (sizeof *SDLAUDIOHIDDEN));
14870
14871    result = pDirectSoundCreate8(guid, &SDLAUDIOHIDDEN->sound, NULL);
14872    if (result != DS_OK) {
14873        DSOUND_CloseDevice(this);
14874        return SetDSerror("DirectSoundCreate", result);
14875    }
14876
14877    while ((!valid_format) && (test_format)) {
14878        switch (test_format) {
14879        case AUDIO_U8:
14880        case AUDIO_S16:
14881        case AUDIO_S32:
14882        case AUDIO_F32:
14883            tried_format = SDL_TRUE;
14884            this->spec.format = test_format;
14885            SDLAUDIOHIDDEN->num_buffers = CreateSecondary(this, NULL);
14886            if (SDLAUDIOHIDDEN->num_buffers > 0) {
14887                valid_format = SDL_TRUE;
14888            }
14889            break;
14890        }
14891        test_format = SDL_NextAudioFormat();
14892    }
14893
14894    if (!valid_format) {
14895        DSOUND_CloseDevice(this);
14896        if (tried_format) {
14897            return -1;
14898        }
14899        return SDL_SetError("DirectSound: Unsupported audio format");
14900    }
14901
14902    SDLAUDIOHIDDEN->mixlen = this->spec.size;
14903
14904    return 0;
14905}
14906
14907static void
14908DSOUND_Deinitialize(void)
14909{
14910    DSOUND_Unload();
14911}
14912
14913static int
14914DSOUND_Init(SDL_AudioDriverImpl * impl)
14915{
14916    if (!DSOUND_Load()) {
14917        return 0;
14918    }
14919
14920    impl->DetectDevices = DSOUND_DetectDevices;
14921    impl->OpenDevice = DSOUND_OpenDevice;
14922    impl->PlayDevice = DSOUND_PlayDevice;
14923    impl->WaitDevice = DSOUND_WaitDevice;
14924    impl->WaitDone = DSOUND_WaitDone;
14925    impl->GetDeviceBuf = DSOUND_GetDeviceBuf;
14926    impl->CloseDevice = DSOUND_CloseDevice;
14927    impl->Deinitialize = DSOUND_Deinitialize;
14928
14929    return 1;
14930}
14931
14932AudioBootStrap DSOUND_bootstrap = {
14933    "directsound", "DirectSound", DSOUND_Init, 0
14934};
14935
14936#endif
14937#if SDL_AUDIO_DRIVER_OSS
14938
14939#include <stdio.h>
14940#include <string.h>
14941#include <errno.h>
14942#include <unistd.h>
14943#include <fcntl.h>
14944#include <signal.h>
14945#include <sys/time.h>
14946#include <sys/ioctl.h>
14947#include <sys/stat.h>
14948
14949#if SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H
14950
14951#include <soundcard.h>
14952#else
14953
14954#include <sys/soundcard.h>
14955#endif
14956
14957#define SDL_AllocAudioMem   SDL_malloc
14958#define SDL_FreeAudioMem    SDL_free
14959#ifdef USE_BLOCKING_WRITES
14960#define OPEN_FLAGS_OUTPUT O_WRONLY
14961#define OPEN_FLAGS_INPUT O_RDONLY
14962#else
14963#define OPEN_FLAGS_OUTPUT (O_WRONLY|O_NONBLOCK)
14964#define OPEN_FLAGS_INPUT (O_RDONLY|O_NONBLOCK)
14965#endif
14966
14967void SDL_EnumUnixAudioDevices(int iscapture, int classic,
14968                              int (*test) (int fd), SDL_AddAudioDevice addfn);
14969#ifndef _SDL_dspaudio_h
14970#define _SDL_dspaudio_h
14971
14972#undef _THIS
14973#define _THIS   SDL_AudioDevice *this
14974
14975#undef SDLAUDIOHIDDEN
14976#define SDLAUDIOHIDDEN ((struct SDL_PrivateAudioDataDSP*)this->hidden)
14977struct SDL_PrivateAudioDataDSP
14978{
14979
14980    int audio_fd;
14981
14982    Uint8 *mixbuf;
14983    int mixlen;
14984};
14985#define FUDGE_TICKS 10
14986
14987#endif
14988
14989static void
14990DSP_DetectDevices(int iscapture, SDL_AddAudioDevice addfn)
14991{
14992    SDL_EnumUnixAudioDevices(iscapture, 0, NULL, addfn);
14993}
14994
14995static void
14996DSP_CloseDevice(_THIS)
14997{
14998    if (SDLAUDIOHIDDEN != NULL) {
14999        SDL_FreeAudioMem(SDLAUDIOHIDDEN->mixbuf);
15000        SDLAUDIOHIDDEN->mixbuf = NULL;
15001        if (SDLAUDIOHIDDEN->audio_fd >= 0) {
15002            close(SDLAUDIOHIDDEN->audio_fd);
15003            SDLAUDIOHIDDEN->audio_fd = -1;
15004        }
15005        SDL_free(SDLAUDIOHIDDEN);
15006        this->hidden = NULL;
15007    }
15008}
15009
15010static int
15011DSP_OpenDevice(_THIS, const char *devname, int iscapture)
15012{
15013    const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT);
15014    int format;
15015    int value;
15016    int frag_spec;
15017    SDL_AudioFormat test_format;
15018
15019    if (devname == NULL) {
15020        devname = SDL_GetAudioDeviceName(0, iscapture);
15021        if (devname == NULL) {
15022            return SDL_SetError("No such audio device");
15023        }
15024    }
15025
15026    if (this->spec.channels > 8)
15027        this->spec.channels = 8;
15028    else if (this->spec.channels > 4)
15029        this->spec.channels = 4;
15030    else if (this->spec.channels > 2)
15031        this->spec.channels = 2;
15032
15033    this->hidden = (struct SDL_PrivateAudioData *)
15034        SDL_malloc((sizeof *SDLAUDIOHIDDEN));
15035    if (SDLAUDIOHIDDEN == NULL) {
15036        return SDL_OutOfMemory();
15037    }
15038    SDL_memset(SDLAUDIOHIDDEN, 0, (sizeof *SDLAUDIOHIDDEN));
15039
15040    SDLAUDIOHIDDEN->audio_fd = open(devname, flags, 0);
15041    if (SDLAUDIOHIDDEN->audio_fd < 0) {
15042        DSP_CloseDevice(this);
15043        return SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
15044    }
15045    SDLAUDIOHIDDEN->mixbuf = NULL;
15046
15047    {
15048        long ctlflags;
15049        ctlflags = fcntl(SDLAUDIOHIDDEN->audio_fd, F_GETFL);
15050        ctlflags &= ~O_NONBLOCK;
15051        if (fcntl(SDLAUDIOHIDDEN->audio_fd, F_SETFL, ctlflags) < 0) {
15052            DSP_CloseDevice(this);
15053            return SDL_SetError("Couldn't set audio blocking mode");
15054        }
15055    }
15056
15057    if (ioctl(SDLAUDIOHIDDEN->audio_fd, SNDCTL_DSP_GETFMTS, &value) < 0) {
15058        perror("SNDCTL_DSP_GETFMTS");
15059        DSP_CloseDevice(this);
15060        return SDL_SetError("Couldn't get audio format list");
15061    }
15062
15063    format = 0;
15064    for (test_format = SDL_FirstAudioFormat(this->spec.format);
15065         !format && test_format;) {
15066#ifdef DEBUG_AUDIO
15067        fprintf(stderr, "Trying format 0x%4.4x\n", test_format);
15068#endif
15069        switch (test_format) {
15070        case AUDIO_U8:
15071            if (value & AFMT_U8) {
15072                format = AFMT_U8;
15073            }
15074            break;
15075        case AUDIO_S16LSB:
15076            if (value & AFMT_S16_LE) {
15077                format = AFMT_S16_LE;
15078            }
15079            break;
15080        case AUDIO_S16MSB:
15081            if (value & AFMT_S16_BE) {
15082                format = AFMT_S16_BE;
15083            }
15084            break;
15085#if 0
15086
15087        case AUDIO_S8:
15088            if (value & AFMT_S8) {
15089                format = AFMT_S8;
15090            }
15091            break;
15092        case AUDIO_U16LSB:
15093            if (value & AFMT_U16_LE) {
15094                format = AFMT_U16_LE;
15095            }
15096            break;
15097        case AUDIO_U16MSB:
15098            if (value & AFMT_U16_BE) {
15099                format = AFMT_U16_BE;
15100            }
15101            break;
15102#endif
15103        default:
15104            format = 0;
15105            break;
15106        }
15107        if (!format) {
15108            test_format = SDL_NextAudioFormat();
15109        }
15110    }
15111    if (format == 0) {
15112        DSP_CloseDevice(this);
15113        return SDL_SetError("Couldn't find any hardware audio formats");
15114    }
15115    this->spec.format = test_format;
15116
15117    value = format;
15118    if ((ioctl(SDLAUDIOHIDDEN->audio_fd, SNDCTL_DSP_SETFMT, &value) < 0) ||
15119        (value != format)) {
15120        perror("SNDCTL_DSP_SETFMT");
15121        DSP_CloseDevice(this);
15122        return SDL_SetError("Couldn't set audio format");
15123    }
15124
15125    value = this->spec.channels;
15126    if (ioctl(SDLAUDIOHIDDEN->audio_fd, SNDCTL_DSP_CHANNELS, &value) < 0) {
15127        perror("SNDCTL_DSP_CHANNELS");
15128        DSP_CloseDevice(this);
15129        return SDL_SetError("Cannot set the number of channels");
15130    }
15131    this->spec.channels = value;
15132
15133    value = this->spec.freq;
15134    if (ioctl(SDLAUDIOHIDDEN->audio_fd, SNDCTL_DSP_SPEED, &value) < 0) {
15135        perror("SNDCTL_DSP_SPEED");
15136        DSP_CloseDevice(this);
15137        return SDL_SetError("Couldn't set audio frequency");
15138    }
15139    this->spec.freq = value;
15140
15141    SDL_CalculateAudioSpec(&this->spec);
15142
15143    for (frag_spec = 0; (0x01U << frag_spec) < this->spec.size; ++frag_spec);
15144    if ((0x01U << frag_spec) != this->spec.size) {
15145        DSP_CloseDevice(this);
15146        return SDL_SetError("Fragment size must be a power of two");
15147    }
15148    frag_spec |= 0x00020000;
15149
15150#ifdef DEBUG_AUDIO
15151    fprintf(stderr, "Requesting %d fragments of size %d\n",
15152            (frag_spec >> 16), 1 << (frag_spec & 0xFFFF));
15153#endif
15154    if (ioctl(SDLAUDIOHIDDEN->audio_fd, SNDCTL_DSP_SETFRAGMENT, &frag_spec) < 0) {
15155        perror("SNDCTL_DSP_SETFRAGMENT");
15156    }
15157#ifdef DEBUG_AUDIO
15158    {
15159        audio_buf_info info;
15160        ioctl(SDLAUDIOHIDDEN->audio_fd, SNDCTL_DSP_GETOSPACE, &info);
15161        fprintf(stderr, "fragments = %d\n", info.fragments);
15162        fprintf(stderr, "fragstotal = %d\n", info.fragstotal);
15163        fprintf(stderr, "fragsize = %d\n", info.fragsize);
15164        fprintf(stderr, "bytes = %d\n", info.bytes);
15165    }
15166#endif
15167
15168    SDLAUDIOHIDDEN->mixlen = this->spec.size;
15169    SDLAUDIOHIDDEN->mixbuf = (Uint8 *) SDL_AllocAudioMem(SDLAUDIOHIDDEN->mixlen);
15170    if (SDLAUDIOHIDDEN->mixbuf == NULL) {
15171        DSP_CloseDevice(this);
15172        return SDL_OutOfMemory();
15173    }
15174    SDL_memset(SDLAUDIOHIDDEN->mixbuf, this->spec.silence, this->spec.size);
15175
15176    return 0;
15177}
15178
15179static void
15180DSP_PlayDevice(_THIS)
15181{
15182    const Uint8 *mixbuf = SDLAUDIOHIDDEN->mixbuf;
15183    const int mixlen = SDLAUDIOHIDDEN->mixlen;
15184    if (write(SDLAUDIOHIDDEN->audio_fd, mixbuf, mixlen) == -1) {
15185        perror("Audio write");
15186        this->enabled = 0;
15187    }
15188#ifdef DEBUG_AUDIO
15189    fprintf(stderr, "Wrote %d bytes of audio data\n", mixlen);
15190#endif
15191}
15192
15193static Uint8 *
15194DSP_GetDeviceBuf(_THIS)
15195{
15196    return (SDLAUDIOHIDDEN->mixbuf);
15197}
15198
15199static int
15200DSP_Init(SDL_AudioDriverImpl * impl)
15201{
15202
15203    impl->DetectDevices = DSP_DetectDevices;
15204    impl->OpenDevice = DSP_OpenDevice;
15205    impl->PlayDevice = DSP_PlayDevice;
15206    impl->GetDeviceBuf = DSP_GetDeviceBuf;
15207    impl->CloseDevice = DSP_CloseDevice;
15208
15209    return 1;
15210}
15211
15212AudioBootStrap DSP_bootstrap = {
15213    "dsp", "OSS /dev/dsp standard audio", DSP_Init, 0
15214};
15215
15216#endif
15217#define SDL_AllocAudioMem   SDL_malloc
15218#define SDL_FreeAudioMem    SDL_free
15219
15220#undef _THIS
15221#define _THIS SDL_AudioDevice *_this
15222
15223static SDL_AudioDriver current_audio;
15224static SDL_AudioDevice *open_devices[16];
15225
15226#define DEFAULT_OUTPUT_DEVNAME "System audio output device"
15227#define DEFAULT_INPUT_DEVNAME "System audio capture device"
15228
15229extern AudioBootStrap BSD_AUDIO_bootstrap;
15230extern AudioBootStrap DSP_bootstrap;
15231extern AudioBootStrap ALSA_bootstrap;
15232extern AudioBootStrap PULSEAUDIO_bootstrap;
15233extern AudioBootStrap QSAAUDIO_bootstrap;
15234extern AudioBootStrap SUNAUDIO_bootstrap;
15235extern AudioBootStrap ARTS_bootstrap;
15236extern AudioBootStrap ESD_bootstrap;
15237extern AudioBootStrap NAS_bootstrap;
15238extern AudioBootStrap XAUDIO2_bootstrap;
15239extern AudioBootStrap DSOUND_bootstrap;
15240extern AudioBootStrap WINMM_bootstrap;
15241extern AudioBootStrap PAUDIO_bootstrap;
15242extern AudioBootStrap HAIKUAUDIO_bootstrap;
15243extern AudioBootStrap COREAUDIO_bootstrap;
15244extern AudioBootStrap SNDMGR_bootstrap;
15245extern AudioBootStrap DISKAUD_bootstrap;
15246extern AudioBootStrap DUMMYAUD_bootstrap;
15247extern AudioBootStrap DCAUD_bootstrap;
15248extern AudioBootStrap DART_bootstrap;
15249extern AudioBootStrap NDSAUD_bootstrap;
15250extern AudioBootStrap FUSIONSOUND_bootstrap;
15251extern AudioBootStrap ANDROIDAUD_bootstrap;
15252extern AudioBootStrap PSPAUD_bootstrap;
15253extern AudioBootStrap SNDIO_bootstrap;
15254
15255static const AudioBootStrap *const bootstrap[] = {
15256#if SDL_AUDIO_DRIVER_PULSEAUDIO
15257    &PULSEAUDIO_bootstrap,
15258#endif
15259#if SDL_AUDIO_DRIVER_ALSA
15260    &ALSA_bootstrap,
15261#endif
15262#if SDL_AUDIO_DRIVER_SNDIO
15263    &SNDIO_bootstrap,
15264#endif
15265#if SDL_AUDIO_DRIVER_BSD
15266    &BSD_AUDIO_bootstrap,
15267#endif
15268#if SDL_AUDIO_DRIVER_OSS
15269    &DSP_bootstrap,
15270#endif
15271#if SDL_AUDIO_DRIVER_QSA
15272    &QSAAUDIO_bootstrap,
15273#endif
15274#if SDL_AUDIO_DRIVER_SUNAUDIO
15275    &SUNAUDIO_bootstrap,
15276#endif
15277#if SDL_AUDIO_DRIVER_ARTS
15278    &ARTS_bootstrap,
15279#endif
15280#if SDL_AUDIO_DRIVER_ESD
15281    &ESD_bootstrap,
15282#endif
15283#if SDL_AUDIO_DRIVER_NAS
15284    &NAS_bootstrap,
15285#endif
15286#if SDL_AUDIO_DRIVER_XAUDIO2
15287    &XAUDIO2_bootstrap,
15288#endif
15289#if SDL_AUDIO_DRIVER_DSOUND
15290    &DSOUND_bootstrap,
15291#endif
15292#if SDL_AUDIO_DRIVER_WINMM
15293    &WINMM_bootstrap,
15294#endif
15295#if SDL_AUDIO_DRIVER_PAUDIO
15296    &PAUDIO_bootstrap,
15297#endif
15298#if SDL_AUDIO_DRIVER_HAIKU
15299    &HAIKUAUDIO_bootstrap,
15300#endif
15301#if SDL_AUDIO_DRIVER_COREAUDIO
15302    &COREAUDIO_bootstrap,
15303#endif
15304#if SDL_AUDIO_DRIVER_DISK
15305    &DISKAUD_bootstrap,
15306#endif
15307#if SDL_AUDIO_DRIVER_DUMMY
15308    &DUMMYAUD_bootstrap,
15309#endif
15310#if SDL_AUDIO_DRIVER_FUSIONSOUND
15311    &FUSIONSOUND_bootstrap,
15312#endif
15313#if SDL_AUDIO_DRIVER_ANDROID
15314    &ANDROIDAUD_bootstrap,
15315#endif
15316#if SDL_AUDIO_DRIVER_PSP
15317    &PSPAUD_bootstrap,
15318#endif
15319    NULL
15320};
15321
15322static SDL_AudioDevice *
15323get_audio_device(SDL_AudioDeviceID id)
15324{
15325    id--;
15326    if ((id >= SDL_arraysize(open_devices)) || (open_devices[id] == NULL)) {
15327        SDL_SetError("Invalid audio device ID");
15328        return NULL;
15329    }
15330
15331    return open_devices[id];
15332}
15333
15334static void
15335SDL_AudioDetectDevices_Default(int iscapture, SDL_AddAudioDevice addfn)
15336{
15337}
15338
15339static void
15340SDL_AudioThreadInit_Default(_THIS)
15341{
15342}
15343
15344static void
15345SDL_AudioWaitDevice_Default(_THIS)
15346{
15347}
15348
15349static void
15350SDL_AudioPlayDevice_Default(_THIS)
15351{
15352}
15353
15354static Uint8 *
15355SDL_AudioGetDeviceBuf_Default(_THIS)
15356{
15357    return NULL;
15358}
15359
15360static void
15361SDL_AudioWaitDone_Default(_THIS)
15362{
15363}
15364
15365static void
15366SDL_AudioCloseDevice_Default(_THIS)
15367{
15368}
15369
15370static void
15371SDL_AudioDeinitialize_Default(void)
15372{
15373}
15374
15375static int
15376SDL_AudioOpenDevice_Default(_THIS, const char *devname, int iscapture)
15377{
15378    return -1;
15379}
15380
15381static void
15382SDL_AudioLockDevice_Default(SDL_AudioDevice * device)
15383{
15384    if (device->thread && (SDL_ThreadID() == device->threadid)) {
15385        return;
15386    }
15387    SDL_LockMutex(device->mixer_lock);
15388}
15389
15390static void
15391SDL_AudioUnlockDevice_Default(SDL_AudioDevice * device)
15392{
15393    if (device->thread && (SDL_ThreadID() == device->threadid)) {
15394        return;
15395    }
15396    SDL_UnlockMutex(device->mixer_lock);
15397}
15398
15399static void
15400finalize_audio_entry_points(void)
15401{
15402
15403#define FILL_STUB(x) \
15404        if (current_audio.impl.x == NULL) { \
15405            current_audio.impl.x = SDL_Audio##x##_Default; \
15406        }
15407    FILL_STUB(DetectDevices);
15408    FILL_STUB(OpenDevice);
15409    FILL_STUB(ThreadInit);
15410    FILL_STUB(WaitDevice);
15411    FILL_STUB(PlayDevice);
15412    FILL_STUB(GetDeviceBuf);
15413    FILL_STUB(WaitDone);
15414    FILL_STUB(CloseDevice);
15415    FILL_STUB(LockDevice);
15416    FILL_STUB(UnlockDevice);
15417    FILL_STUB(Deinitialize);
15418#undef FILL_STUB
15419}
15420
15421static void
15422SDL_StreamWrite(SDL_AudioStreamer * stream, Uint8 * buf, int length)
15423{
15424    int i;
15425
15426    for (i = 0; i < length; ++i) {
15427        stream->buffer[stream->write_pos] = buf[i];
15428        ++stream->write_pos;
15429    }
15430}
15431
15432static void
15433SDL_StreamRead(SDL_AudioStreamer * stream, Uint8 * buf, int length)
15434{
15435    int i;
15436
15437    for (i = 0; i < length; ++i) {
15438        buf[i] = stream->buffer[stream->read_pos];
15439        ++stream->read_pos;
15440    }
15441}
15442
15443static int
15444SDL_StreamLength(SDL_AudioStreamer * stream)
15445{
15446    return (stream->write_pos - stream->read_pos) % stream->max_len;
15447}
15448
15449#if 0
15450static int
15451SDL_StreamInit(SDL_AudioStreamer * stream, int max_len, Uint8 silence)
15452{
15453
15454    stream->buffer = (Uint8 *) SDL_malloc(max_len);
15455    if (stream->buffer == NULL) {
15456        return -1;
15457    }
15458
15459    stream->max_len = max_len;
15460    stream->read_pos = 0;
15461    stream->write_pos = 0;
15462
15463    SDL_memset(stream->buffer, silence, max_len);
15464
15465    return 0;
15466}
15467#endif
15468
15469static void
15470SDL_StreamDeinit(SDL_AudioStreamer * stream)
15471{
15472    SDL_free(stream->buffer);
15473}
15474
15475#if defined(ANDROID)
15476#include <android/log.h>
15477#endif
15478
15479int SDLCALL
15480SDL_RunAudio(void *devicep)
15481{
15482    SDL_AudioDevice *device = (SDL_AudioDevice *) devicep;
15483    Uint8 *stream;
15484    int stream_len;
15485    void *udata;
15486    void (SDLCALL * fill) (void *userdata, Uint8 * stream, int len);
15487    Uint32 delay;
15488
15489    Uint8 *istream;
15490    int istream_len = 0;
15491
15492    SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH);
15493
15494    device->threadid = SDL_ThreadID();
15495    current_audio.impl.ThreadInit(device);
15496
15497    fill = device->spec.callback;
15498    udata = device->spec.userdata;
15499
15500    device->use_streamer = 0;
15501
15502    if (device->convert.needed) {
15503#if 0
15504
15505        if (device->convert.len_mult != 1 || device->convert.len_div != 1) {
15506
15507            stream_max_len = 2 * device->spec.size;
15508            if (device->convert.len_mult > device->convert.len_div) {
15509                stream_max_len *= device->convert.len_mult;
15510                stream_max_len /= device->convert.len_div;
15511            }
15512            if (SDL_StreamInit(&device->streamer, stream_max_len, silence) <
15513                0)
15514                return -1;
15515            device->use_streamer = 1;
15516
15517            istream_len =
15518                device->spec.size * device->convert.len_div /
15519                device->convert.len_mult;
15520        }
15521#endif
15522        stream_len = device->convert.len;
15523    } else {
15524        stream_len = device->spec.size;
15525    }
15526
15527    delay = ((device->spec.samples * 1000) / device->spec.freq);
15528
15529    if (device->use_streamer == 1) {
15530
15531        while (device->enabled) {
15532
15533            if (device->paused) {
15534                SDL_Delay(delay);
15535                continue;
15536            }
15537
15538            if (SDL_StreamLength(&device->streamer) < stream_len) {
15539
15540                if (device->convert.needed) {
15541                    if (device->convert.buf) {
15542                        istream = device->convert.buf;
15543                    } else {
15544                        continue;
15545                    }
15546                } else {
15547
15548                    istream = current_audio.impl.GetDeviceBuf(device);
15549                    if (istream == NULL) {
15550                        istream = device->fake_stream;
15551                    }
15552                }
15553
15554                SDL_LockMutex(device->mixer_lock);
15555                (*fill) (udata, istream, istream_len);
15556                SDL_UnlockMutex(device->mixer_lock);
15557
15558                if (device->convert.needed) {
15559                    SDL_ConvertAudio(&device->convert);
15560                    if (istream == NULL) {
15561                        istream = device->fake_stream;
15562                    }
15563
15564                    SDL_StreamWrite(&device->streamer, device->convert.buf,
15565                                    device->convert.len_cvt);
15566                } else {
15567                    SDL_StreamWrite(&device->streamer, istream, istream_len);
15568                }
15569            }
15570
15571            if (SDL_StreamLength(&device->streamer) >= stream_len) {
15572
15573                if (device->convert.needed) {
15574                    if (device->convert.buf) {
15575                        stream = device->convert.buf;
15576                    } else {
15577                        continue;
15578                    }
15579                } else {
15580                    stream = current_audio.impl.GetDeviceBuf(device);
15581                    if (stream == NULL) {
15582                        stream = device->fake_stream;
15583                    }
15584                }
15585
15586                SDL_StreamRead(&device->streamer, stream, stream_len);
15587
15588                if (stream != device->fake_stream) {
15589                    current_audio.impl.PlayDevice(device);
15590
15591                    current_audio.impl.WaitDevice(device);
15592                } else {
15593                    SDL_Delay(delay);
15594                }
15595            }
15596
15597        }
15598    } else {
15599
15600        const int silence = (int) device->spec.silence;
15601
15602        while (device->enabled) {
15603
15604            if (device->convert.needed) {
15605                if (device->convert.buf) {
15606                    stream = device->convert.buf;
15607                } else {
15608                    continue;
15609                }
15610            } else {
15611                stream = current_audio.impl.GetDeviceBuf(device);
15612                if (stream == NULL) {
15613                    stream = device->fake_stream;
15614                }
15615            }
15616
15617            SDL_LockMutex(device->mixer_lock);
15618            if (device->paused) {
15619                SDL_memset(stream, silence, stream_len);
15620            } else {
15621                (*fill) (udata, stream, stream_len);
15622            }
15623            SDL_UnlockMutex(device->mixer_lock);
15624
15625            if (device->convert.needed) {
15626                SDL_ConvertAudio(&device->convert);
15627                stream = current_audio.impl.GetDeviceBuf(device);
15628                if (stream == NULL) {
15629                    stream = device->fake_stream;
15630                }
15631                SDL_memcpy(stream, device->convert.buf,
15632                           device->convert.len_cvt);
15633            }
15634
15635            if (stream != device->fake_stream) {
15636                current_audio.impl.PlayDevice(device);
15637
15638                current_audio.impl.WaitDevice(device);
15639            } else {
15640                SDL_Delay(delay);
15641            }
15642        }
15643    }
15644
15645    current_audio.impl.WaitDone(device);
15646
15647    if (device->use_streamer == 1)
15648        SDL_StreamDeinit(&device->streamer);
15649
15650    return (0);
15651}
15652
15653static SDL_AudioFormat
15654SDL_ParseAudioFormat(const char *string)
15655{
15656#define CHECK_FMT_STRING(x) if (SDL_strcmp(string, #x) == 0) return AUDIO_##x
15657    CHECK_FMT_STRING(U8);
15658    CHECK_FMT_STRING(S8);
15659    CHECK_FMT_STRING(U16LSB);
15660    CHECK_FMT_STRING(S16LSB);
15661    CHECK_FMT_STRING(U16MSB);
15662    CHECK_FMT_STRING(S16MSB);
15663    CHECK_FMT_STRING(U16SYS);
15664    CHECK_FMT_STRING(S16SYS);
15665    CHECK_FMT_STRING(U16);
15666    CHECK_FMT_STRING(S16);
15667    CHECK_FMT_STRING(S32LSB);
15668    CHECK_FMT_STRING(S32MSB);
15669    CHECK_FMT_STRING(S32SYS);
15670    CHECK_FMT_STRING(S32);
15671    CHECK_FMT_STRING(F32LSB);
15672    CHECK_FMT_STRING(F32MSB);
15673    CHECK_FMT_STRING(F32SYS);
15674    CHECK_FMT_STRING(F32);
15675#undef CHECK_FMT_STRING
15676    return 0;
15677}
15678
15679int
15680SDL_GetNumAudioDrivers(void)
15681{
15682    return (SDL_arraysize(bootstrap) - 1);
15683}
15684
15685const char *
15686SDL_GetAudioDriver(int index)
15687{
15688    if (index >= 0 && index < SDL_GetNumAudioDrivers()) {
15689        return (bootstrap[index]->name);
15690    }
15691    return (NULL);
15692}
15693
15694int
15695SDL_AudioInit(const char *driver_name)
15696{
15697    int i = 0;
15698    int initialized = 0;
15699    int tried_to_init = 0;
15700
15701    if (SDL_WasInit(SDL_INIT_AUDIO)) {
15702        SDL_AudioQuit();
15703    }
15704
15705    SDL_memset(&current_audio, '\0', sizeof(current_audio));
15706    SDL_memset(open_devices, '\0', sizeof(open_devices));
15707
15708    if (driver_name == NULL) {
15709        driver_name = SDL_getenv("SDL_AUDIODRIVER");
15710    }
15711
15712    for (i = 0; (!initialized) && (bootstrap[i]); ++i) {
15713
15714        const AudioBootStrap *backend = bootstrap[i];
15715        if ((driver_name && (SDL_strncasecmp(backend->name, driver_name, SDL_strlen(driver_name)) != 0)) ||
15716            (!driver_name && backend->demand_only)) {
15717            continue;
15718        }
15719
15720        tried_to_init = 1;
15721        SDL_memset(&current_audio, 0, sizeof(current_audio));
15722        current_audio.name = backend->name;
15723        current_audio.desc = backend->desc;
15724        initialized = backend->init(&current_audio.impl);
15725    }
15726
15727    if (!initialized) {
15728
15729        if (!tried_to_init) {
15730            if (driver_name) {
15731                SDL_SetError("Audio target '%s' not available", driver_name);
15732            } else {
15733                SDL_SetError("No available audio device");
15734            }
15735        }
15736
15737        SDL_memset(&current_audio, 0, sizeof(current_audio));
15738        return (-1);
15739    }
15740
15741    finalize_audio_entry_points();
15742
15743    return (0);
15744}
15745
15746const char *
15747SDL_GetCurrentAudioDriver()
15748{
15749    return current_audio.name;
15750}
15751
15752static void
15753free_device_list(char ***devices, int *devCount)
15754{
15755    int i = *devCount;
15756    if ((i > 0) && (*devices != NULL)) {
15757        while (i--) {
15758            SDL_free((*devices)[i]);
15759        }
15760    }
15761
15762    SDL_free(*devices);
15763
15764    *devices = NULL;
15765    *devCount = 0;
15766}
15767
15768static
15769void SDL_AddCaptureAudioDevice(const char *_name)
15770{
15771    char *name = NULL;
15772    void *ptr = SDL_realloc(current_audio.inputDevices,
15773                          (current_audio.inputDeviceCount+1) * sizeof(char*));
15774    if (ptr == NULL) {
15775        return;
15776    }
15777
15778    current_audio.inputDevices = (char **) ptr;
15779    name = SDL_strdup(_name);
15780    current_audio.inputDevices[current_audio.inputDeviceCount++] = name;
15781}
15782
15783static
15784void SDL_AddOutputAudioDevice(const char *_name)
15785{
15786    char *name = NULL;
15787    void *ptr = SDL_realloc(current_audio.outputDevices,
15788                          (current_audio.outputDeviceCount+1) * sizeof(char*));
15789    if (ptr == NULL) {
15790        return;
15791    }
15792
15793    current_audio.outputDevices = (char **) ptr;
15794    name = SDL_strdup(_name);
15795    current_audio.outputDevices[current_audio.outputDeviceCount++] = name;
15796}
15797
15798int
15799SDL_GetNumAudioDevices(int iscapture)
15800{
15801    int retval = 0;
15802
15803    if (!SDL_WasInit(SDL_INIT_AUDIO)) {
15804        return -1;
15805    }
15806
15807    if ((iscapture) && (!current_audio.impl.HasCaptureSupport)) {
15808        return 0;
15809    }
15810
15811    if ((iscapture) && (current_audio.impl.OnlyHasDefaultInputDevice)) {
15812        return 1;
15813    }
15814
15815    if ((!iscapture) && (current_audio.impl.OnlyHasDefaultOutputDevice)) {
15816        return 1;
15817    }
15818
15819    if (iscapture) {
15820        free_device_list(&current_audio.inputDevices,
15821                         &current_audio.inputDeviceCount);
15822        current_audio.impl.DetectDevices(iscapture, SDL_AddCaptureAudioDevice);
15823        retval = current_audio.inputDeviceCount;
15824    } else {
15825        free_device_list(&current_audio.outputDevices,
15826                         &current_audio.outputDeviceCount);
15827        current_audio.impl.DetectDevices(iscapture, SDL_AddOutputAudioDevice);
15828        retval = current_audio.outputDeviceCount;
15829    }
15830
15831    return retval;
15832}
15833
15834const char *
15835SDL_GetAudioDeviceName(int index, int iscapture)
15836{
15837    if (!SDL_WasInit(SDL_INIT_AUDIO)) {
15838        SDL_SetError("Audio subsystem is not initialized");
15839        return NULL;
15840    }
15841
15842    if ((iscapture) && (!current_audio.impl.HasCaptureSupport)) {
15843        SDL_SetError("No capture support");
15844        return NULL;
15845    }
15846
15847    if (index < 0) {
15848        goto no_such_device;
15849    }
15850
15851    if ((iscapture) && (current_audio.impl.OnlyHasDefaultInputDevice)) {
15852        if (index > 0) {
15853            goto no_such_device;
15854        }
15855        return DEFAULT_INPUT_DEVNAME;
15856    }
15857
15858    if ((!iscapture) && (current_audio.impl.OnlyHasDefaultOutputDevice)) {
15859        if (index > 0) {
15860            goto no_such_device;
15861        }
15862        return DEFAULT_OUTPUT_DEVNAME;
15863    }
15864
15865    if (iscapture) {
15866        if (index >= current_audio.inputDeviceCount) {
15867            goto no_such_device;
15868        }
15869        return current_audio.inputDevices[index];
15870    } else {
15871        if (index >= current_audio.outputDeviceCount) {
15872            goto no_such_device;
15873        }
15874        return current_audio.outputDevices[index];
15875    }
15876
15877no_such_device:
15878    SDL_SetError("No such device");
15879    return NULL;
15880}
15881
15882static void
15883close_audio_device(SDL_AudioDevice * device)
15884{
15885    device->enabled = 0;
15886    if (device->thread != NULL) {
15887        SDL_WaitThread(device->thread, NULL);
15888    }
15889    if (device->mixer_lock != NULL) {
15890        SDL_DestroyMutex(device->mixer_lock);
15891    }
15892    SDL_FreeAudioMem(device->fake_stream);
15893    if (device->convert.needed) {
15894        SDL_FreeAudioMem(device->convert.buf);
15895    }
15896    if (device->opened) {
15897        current_audio.impl.CloseDevice(device);
15898        device->opened = 0;
15899    }
15900    SDL_FreeAudioMem(device);
15901}
15902
15903static int
15904prepare_audiospec(const SDL_AudioSpec * orig, SDL_AudioSpec * prepared)
15905{
15906    SDL_memcpy(prepared, orig, sizeof(SDL_AudioSpec));
15907
15908    if (orig->callback == NULL) {
15909        SDL_SetError("SDL_OpenAudio() passed a NULL callback");
15910        return 0;
15911    }
15912
15913    if (orig->freq == 0) {
15914        const char *env = SDL_getenv("SDL_AUDIO_FREQUENCY");
15915        if ((!env) || ((prepared->freq = SDL_atoi(env)) == 0)) {
15916            prepared->freq = 22050;
15917        }
15918    }
15919
15920    if (orig->format == 0) {
15921        const char *env = SDL_getenv("SDL_AUDIO_FORMAT");
15922        if ((!env) || ((prepared->format = SDL_ParseAudioFormat(env)) == 0)) {
15923            prepared->format = AUDIO_S16;
15924        }
15925    }
15926
15927    switch (orig->channels) {
15928    case 0:{
15929            const char *env = SDL_getenv("SDL_AUDIO_CHANNELS");
15930            if ((!env) || ((prepared->channels = (Uint8) SDL_atoi(env)) == 0)) {
15931                prepared->channels = 2;
15932            }
15933            break;
15934        }
15935    case 1:
15936    case 2:
15937    case 4:
15938    case 6:
15939        break;
15940    default:
15941        SDL_SetError("Unsupported number of audio channels.");
15942        return 0;
15943    }
15944
15945    if (orig->samples == 0) {
15946        const char *env = SDL_getenv("SDL_AUDIO_SAMPLES");
15947        if ((!env) || ((prepared->samples = (Uint16) SDL_atoi(env)) == 0)) {
15948
15949            const int samples = (prepared->freq / 1000) * 46;
15950            int power2 = 1;
15951            while (power2 < samples) {
15952                power2 *= 2;
15953            }
15954            prepared->samples = power2;
15955        }
15956    }
15957
15958    SDL_CalculateAudioSpec(prepared);
15959
15960    return 1;
15961}
15962
15963static SDL_AudioDeviceID
15964open_audio_device(const char *devname, int iscapture,
15965                  const SDL_AudioSpec * desired, SDL_AudioSpec * obtained,
15966                  int allowed_changes, int min_id)
15967{
15968    SDL_AudioDeviceID id = 0;
15969    SDL_AudioSpec _obtained;
15970    SDL_AudioDevice *device;
15971    SDL_bool build_cvt;
15972    int i = 0;
15973
15974    if (!SDL_WasInit(SDL_INIT_AUDIO)) {
15975        SDL_SetError("Audio subsystem is not initialized");
15976        return 0;
15977    }
15978
15979    if ((iscapture) && (!current_audio.impl.HasCaptureSupport)) {
15980        SDL_SetError("No capture support");
15981        return 0;
15982    }
15983
15984    if (!obtained) {
15985        obtained = &_obtained;
15986    }
15987    if (!prepare_audiospec(desired, obtained)) {
15988        return 0;
15989    }
15990
15991    if (devname == NULL) {
15992        devname = SDL_getenv("SDL_AUDIO_DEVICE_NAME");
15993    }
15994
15995    if ((iscapture) && (current_audio.impl.OnlyHasDefaultInputDevice)) {
15996        if ((devname) && (SDL_strcmp(devname, DEFAULT_INPUT_DEVNAME) != 0)) {
15997            SDL_SetError("No such device");
15998            return 0;
15999        }
16000        devname = NULL;
16001
16002        for (i = 0; i < SDL_arraysize(open_devices); i++) {
16003            if ((open_devices[i]) && (open_devices[i]->iscapture)) {
16004                SDL_SetError("Audio device already open");
16005                return 0;
16006            }
16007        }
16008    }
16009
16010    if ((!iscapture) && (current_audio.impl.OnlyHasDefaultOutputDevice)) {
16011        if ((devname) && (SDL_strcmp(devname, DEFAULT_OUTPUT_DEVNAME) != 0)) {
16012            SDL_SetError("No such device");
16013            return 0;
16014        }
16015        devname = NULL;
16016
16017        for (i = 0; i < SDL_arraysize(open_devices); i++) {
16018            if ((open_devices[i]) && (!open_devices[i]->iscapture)) {
16019                SDL_SetError("Audio device already open");
16020                return 0;
16021            }
16022        }
16023    }
16024
16025    device = (SDL_AudioDevice *) SDL_AllocAudioMem(sizeof(SDL_AudioDevice));
16026    if (device == NULL) {
16027        SDL_OutOfMemory();
16028        return 0;
16029    }
16030    SDL_memset(device, '\0', sizeof(SDL_AudioDevice));
16031    device->spec = *obtained;
16032    device->enabled = 1;
16033    device->paused = 1;
16034    device->iscapture = iscapture;
16035
16036    if (!current_audio.impl.SkipMixerLock) {
16037        device->mixer_lock = SDL_CreateMutex();
16038        if (device->mixer_lock == NULL) {
16039            close_audio_device(device);
16040            SDL_SetError("Couldn't create mixer lock");
16041            return 0;
16042        }
16043    }
16044
16045    if ( ((iscapture) && (current_audio.inputDevices == NULL)) ||
16046         ((!iscapture) && (current_audio.outputDevices == NULL)) )
16047        SDL_GetNumAudioDevices(iscapture);
16048
16049    if (current_audio.impl.OpenDevice(device, devname, iscapture) < 0) {
16050        close_audio_device(device);
16051        return 0;
16052    }
16053    device->opened = 1;
16054
16055    device->fake_stream = (Uint8 *)SDL_AllocAudioMem(device->spec.size);
16056    if (device->fake_stream == NULL) {
16057        close_audio_device(device);
16058        SDL_OutOfMemory();
16059        return 0;
16060    }
16061
16062    build_cvt = SDL_FALSE;
16063    if (obtained->freq != device->spec.freq) {
16064        if (allowed_changes & SDL_AUDIO_ALLOW_FREQUENCY_CHANGE) {
16065            obtained->freq = device->spec.freq;
16066        } else {
16067            build_cvt = SDL_TRUE;
16068        }
16069    }
16070    if (obtained->format != device->spec.format) {
16071        if (allowed_changes & SDL_AUDIO_ALLOW_FORMAT_CHANGE) {
16072            obtained->format = device->spec.format;
16073        } else {
16074            build_cvt = SDL_TRUE;
16075        }
16076    }
16077    if (obtained->channels != device->spec.channels) {
16078        if (allowed_changes & SDL_AUDIO_ALLOW_CHANNELS_CHANGE) {
16079            obtained->channels = device->spec.channels;
16080        } else {
16081            build_cvt = SDL_TRUE;
16082        }
16083    }
16084
16085    if (device->spec.samples != obtained->samples) {
16086        obtained->samples = device->spec.samples;
16087        SDL_CalculateAudioSpec(obtained);
16088    }
16089
16090    if (build_cvt) {
16091
16092        if (SDL_BuildAudioCVT(&device->convert,
16093                              obtained->format, obtained->channels,
16094                              obtained->freq,
16095                              device->spec.format, device->spec.channels,
16096                              device->spec.freq) < 0) {
16097            close_audio_device(device);
16098            return 0;
16099        }
16100        if (device->convert.needed) {
16101            device->convert.len = (int) (((double) device->spec.size) /
16102                                         device->convert.len_ratio);
16103
16104            device->convert.buf =
16105                (Uint8 *) SDL_AllocAudioMem(device->convert.len *
16106                                            device->convert.len_mult);
16107            if (device->convert.buf == NULL) {
16108                close_audio_device(device);
16109                SDL_OutOfMemory();
16110                return 0;
16111            }
16112        }
16113    }
16114
16115    for (id = min_id - 1; id < SDL_arraysize(open_devices); id++) {
16116        if (open_devices[id] == NULL) {
16117            open_devices[id] = device;
16118            break;
16119        }
16120    }
16121
16122    if (id == SDL_arraysize(open_devices)) {
16123        SDL_SetError("Too many open audio devices");
16124        close_audio_device(device);
16125        return 0;
16126    }
16127
16128    if (!current_audio.impl.ProvidesOwnCallbackThread) {
16129
16130        char name[64];
16131        SDL_snprintf(name, sizeof (name), "SDLAudioDev%d", (int) (id + 1));
16132
16133#if defined(__WIN32__) && !defined(HAVE_LIBC)
16134#undef SDL_CreateThread
16135#if SDL_DYNAMIC_API
16136        device->thread = SDL_CreateThread_REAL(SDL_RunAudio, name, device, NULL, NULL);
16137#else
16138        device->thread = SDL_CreateThread(SDL_RunAudio, name, device, NULL, NULL);
16139#endif
16140#else
16141        device->thread = SDL_CreateThread(SDL_RunAudio, name, device);
16142#endif
16143        if (device->thread == NULL) {
16144            SDL_CloseAudioDevice(id + 1);
16145            SDL_SetError("Couldn't create audio thread");
16146            return 0;
16147        }
16148    }
16149
16150    return id + 1;
16151}
16152
16153int
16154SDL_OpenAudio(SDL_AudioSpec * desired, SDL_AudioSpec * obtained)
16155{
16156    SDL_AudioDeviceID id = 0;
16157
16158    if (!SDL_WasInit(SDL_INIT_AUDIO)) {
16159        if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
16160            return (-1);
16161        }
16162    }
16163
16164    if (open_devices[0] != NULL) {
16165        SDL_SetError("Audio device is already opened");
16166        return (-1);
16167    }
16168
16169    if (obtained) {
16170        id = open_audio_device(NULL, 0, desired, obtained,
16171                               SDL_AUDIO_ALLOW_ANY_CHANGE, 1);
16172    } else {
16173        id = open_audio_device(NULL, 0, desired, desired, 0, 1);
16174    }
16175
16176    SDL_assert((id == 0) || (id == 1));
16177    return ((id == 0) ? -1 : 0);
16178}
16179
16180SDL_AudioDeviceID
16181SDL_OpenAudioDevice(const char *device, int iscapture,
16182                    const SDL_AudioSpec * desired, SDL_AudioSpec * obtained,
16183                    int allowed_changes)
16184{
16185    return open_audio_device(device, iscapture, desired, obtained,
16186                             allowed_changes, 2);
16187}
16188
16189SDL_AudioStatus
16190SDL_GetAudioDeviceStatus(SDL_AudioDeviceID devid)
16191{
16192    SDL_AudioDevice *device = get_audio_device(devid);
16193    SDL_AudioStatus status = SDL_AUDIO_STOPPED;
16194    if (device && device->enabled) {
16195        if (device->paused) {
16196            status = SDL_AUDIO_PAUSED;
16197        } else {
16198            status = SDL_AUDIO_PLAYING;
16199        }
16200    }
16201    return (status);
16202}
16203
16204SDL_AudioStatus
16205SDL_GetAudioStatus(void)
16206{
16207    return SDL_GetAudioDeviceStatus(1);
16208}
16209
16210void
16211SDL_PauseAudioDevice(SDL_AudioDeviceID devid, int pause_on)
16212{
16213    SDL_AudioDevice *device = get_audio_device(devid);
16214    if (device) {
16215        current_audio.impl.LockDevice(device);
16216        device->paused = pause_on;
16217        current_audio.impl.UnlockDevice(device);
16218    }
16219}
16220
16221void
16222SDL_PauseAudio(int pause_on)
16223{
16224    SDL_PauseAudioDevice(1, pause_on);
16225}
16226
16227void
16228SDL_LockAudioDevice(SDL_AudioDeviceID devid)
16229{
16230
16231    SDL_AudioDevice *device = get_audio_device(devid);
16232    if (device) {
16233        current_audio.impl.LockDevice(device);
16234    }
16235}
16236
16237void
16238SDL_LockAudio(void)
16239{
16240    SDL_LockAudioDevice(1);
16241}
16242
16243void
16244SDL_UnlockAudioDevice(SDL_AudioDeviceID devid)
16245{
16246
16247    SDL_AudioDevice *device = get_audio_device(devid);
16248    if (device) {
16249        current_audio.impl.UnlockDevice(device);
16250    }
16251}
16252
16253void
16254SDL_UnlockAudio(void)
16255{
16256    SDL_UnlockAudioDevice(1);
16257}
16258
16259void
16260SDL_CloseAudioDevice(SDL_AudioDeviceID devid)
16261{
16262    SDL_AudioDevice *device = get_audio_device(devid);
16263    if (device) {
16264        close_audio_device(device);
16265        open_devices[devid - 1] = NULL;
16266    }
16267}
16268
16269void
16270SDL_CloseAudio(void)
16271{
16272    SDL_CloseAudioDevice(1);
16273}
16274
16275void
16276SDL_AudioQuit(void)
16277{
16278    SDL_AudioDeviceID i;
16279
16280    if (!current_audio.name) {
16281        return;
16282    }
16283
16284    for (i = 0; i < SDL_arraysize(open_devices); i++) {
16285        if (open_devices[i] != NULL) {
16286            SDL_CloseAudioDevice(i+1);
16287        }
16288    }
16289
16290    current_audio.impl.Deinitialize();
16291    free_device_list(&current_audio.outputDevices,
16292                     &current_audio.outputDeviceCount);
16293    free_device_list(&current_audio.inputDevices,
16294                     &current_audio.inputDeviceCount);
16295    SDL_memset(&current_audio, '\0', sizeof(current_audio));
16296    SDL_memset(open_devices, '\0', sizeof(open_devices));
16297}
16298
16299#define NUM_FORMATS 10
16300static int format_idx;
16301static int format_idx_sub;
16302static SDL_AudioFormat format_list[NUM_FORMATS][NUM_FORMATS] = {
16303    {AUDIO_U8, AUDIO_S8, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U16LSB,
16304     AUDIO_U16MSB, AUDIO_S32LSB, AUDIO_S32MSB, AUDIO_F32LSB, AUDIO_F32MSB},
16305    {AUDIO_S8, AUDIO_U8, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U16LSB,
16306     AUDIO_U16MSB, AUDIO_S32LSB, AUDIO_S32MSB, AUDIO_F32LSB, AUDIO_F32MSB},
16307    {AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U16LSB, AUDIO_U16MSB, AUDIO_S32LSB,
16308     AUDIO_S32MSB, AUDIO_F32LSB, AUDIO_F32MSB, AUDIO_U8, AUDIO_S8},
16309    {AUDIO_S16MSB, AUDIO_S16LSB, AUDIO_U16MSB, AUDIO_U16LSB, AUDIO_S32MSB,
16310     AUDIO_S32LSB, AUDIO_F32MSB, AUDIO_F32LSB, AUDIO_U8, AUDIO_S8},
16311    {AUDIO_U16LSB, AUDIO_U16MSB, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_S32LSB,
16312     AUDIO_S32MSB, AUDIO_F32LSB, AUDIO_F32MSB, AUDIO_U8, AUDIO_S8},
16313    {AUDIO_U16MSB, AUDIO_U16LSB, AUDIO_S16MSB, AUDIO_S16LSB, AUDIO_S32MSB,
16314     AUDIO_S32LSB, AUDIO_F32MSB, AUDIO_F32LSB, AUDIO_U8, AUDIO_S8},
16315    {AUDIO_S32LSB, AUDIO_S32MSB, AUDIO_F32LSB, AUDIO_F32MSB, AUDIO_S16LSB,
16316     AUDIO_S16MSB, AUDIO_U16LSB, AUDIO_U16MSB, AUDIO_U8, AUDIO_S8},
16317    {AUDIO_S32MSB, AUDIO_S32LSB, AUDIO_F32MSB, AUDIO_F32LSB, AUDIO_S16MSB,
16318     AUDIO_S16LSB, AUDIO_U16MSB, AUDIO_U16LSB, AUDIO_U8, AUDIO_S8},
16319    {AUDIO_F32LSB, AUDIO_F32MSB, AUDIO_S32LSB, AUDIO_S32MSB, AUDIO_S16LSB,
16320     AUDIO_S16MSB, AUDIO_U16LSB, AUDIO_U16MSB, AUDIO_U8, AUDIO_S8},
16321    {AUDIO_F32MSB, AUDIO_F32LSB, AUDIO_S32MSB, AUDIO_S32LSB, AUDIO_S16MSB,
16322     AUDIO_S16LSB, AUDIO_U16MSB, AUDIO_U16LSB, AUDIO_U8, AUDIO_S8},
16323};
16324
16325SDL_AudioFormat
16326SDL_FirstAudioFormat(SDL_AudioFormat format)
16327{
16328    for (format_idx = 0; format_idx < NUM_FORMATS; ++format_idx) {
16329        if (format_list[format_idx][0] == format) {
16330            break;
16331        }
16332    }
16333    format_idx_sub = 0;
16334    return (SDL_NextAudioFormat());
16335}
16336
16337SDL_AudioFormat
16338SDL_NextAudioFormat(void)
16339{
16340    if ((format_idx == NUM_FORMATS) || (format_idx_sub == NUM_FORMATS)) {
16341        return (0);
16342    }
16343    return (format_list[format_idx][format_idx_sub++]);
16344}
16345
16346void
16347SDL_CalculateAudioSpec(SDL_AudioSpec * spec)
16348{
16349    switch (spec->format) {
16350    case AUDIO_U8:
16351        spec->silence = 0x80;
16352        break;
16353    default:
16354        spec->silence = 0x00;
16355        break;
16356    }
16357    spec->size = SDL_AUDIO_BITSIZE(spec->format) / 8;
16358    spec->size *= spec->channels;
16359    spec->size *= spec->samples;
16360}
16361
16362void
16363SDL_MixAudio(Uint8 * dst, const Uint8 * src, Uint32 len, int volume)
16364{
16365
16366    SDL_AudioDevice *device = get_audio_device(1);
16367    if (device != NULL) {
16368        SDL_AudioFormat format;
16369        if (device->convert.needed) {
16370            format = device->convert.src_format;
16371        } else {
16372            format = device->spec.format;
16373        }
16374        SDL_MixAudioFormat(dst, src, format, len, volume);
16375    }
16376}
16377#if SDL_AUDIO_DRIVER_BSD || SDL_AUDIO_DRIVER_OSS || SDL_AUDIO_DRIVER_SUNAUDIO
16378
16379#include <fcntl.h>
16380#include <sys/types.h>
16381#include <sys/stat.h>
16382#include <unistd.h>
16383
16384#ifdef USE_BLOCKING_WRITES
16385#define OPEN_FLAGS_OUTPUT O_WRONLY
16386#define OPEN_FLAGS_INPUT O_RDONLY
16387#else
16388#define OPEN_FLAGS_OUTPUT (O_WRONLY|O_NONBLOCK)
16389#define OPEN_FLAGS_INPUT (O_RDONLY|O_NONBLOCK)
16390#endif
16391
16392void SDL_EnumUnixAudioDevices(int iscapture, int classic,
16393                              int (*test) (int fd), SDL_AddAudioDevice addfn);
16394
16395#ifndef _PATH_DEV_DSP
16396#if defined(__NETBSD__) || defined(__OPENBSD__)
16397#define _PATH_DEV_DSP  "/dev/audio"
16398#else
16399#define _PATH_DEV_DSP  "/dev/dsp"
16400#endif
16401#endif
16402#ifndef _PATH_DEV_DSP24
16403#define _PATH_DEV_DSP24 "/dev/sound/dsp"
16404#endif
16405#ifndef _PATH_DEV_AUDIO
16406#define _PATH_DEV_AUDIO "/dev/audio"
16407#endif
16408
16409static SDL_INLINE void
16410test_device(const char *fname, int flags, int (*test) (int fd),
16411            SDL_AddAudioDevice addfn)
16412{
16413    struct stat sb;
16414    if ((stat(fname, &sb) == 0) && (S_ISCHR(sb.st_mode))) {
16415        const int audio_fd = open(fname, flags, 0);
16416        if (audio_fd >= 0) {
16417            if (test(audio_fd)) {
16418                addfn(fname);
16419            }
16420            close(audio_fd);
16421        }
16422    }
16423}
16424
16425static int
16426test_stub(int fd)
16427{
16428    return 1;
16429}
16430
16431void
16432SDL_EnumUnixAudioDevices(int iscapture, int classic, int (*test)(int fd),
16433                         SDL_AddAudioDevice addfn)
16434{
16435    const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT);
16436    const char *audiodev;
16437    char audiopath[1024];
16438
16439    if (test == NULL)
16440        test = test_stub;
16441
16442    if (((audiodev = SDL_getenv("SDL_PATH_DSP")) == NULL) &&
16443        ((audiodev = SDL_getenv("AUDIODEV")) == NULL)) {
16444        if (classic) {
16445            audiodev = _PATH_DEV_AUDIO;
16446        } else {
16447            struct stat sb;
16448
16449            if (((stat("/dev/sound", &sb) == 0) && S_ISDIR(sb.st_mode))
16450                && ((stat(_PATH_DEV_DSP24, &sb) == 0)
16451                    && S_ISCHR(sb.st_mode))) {
16452                audiodev = _PATH_DEV_DSP24;
16453            } else {
16454                audiodev = _PATH_DEV_DSP;
16455            }
16456        }
16457    }
16458    test_device(audiodev, flags, test, addfn);
16459
16460    if (SDL_strlen(audiodev) < (sizeof(audiopath) - 3)) {
16461        int instance = 0;
16462        while (instance++ <= 64) {
16463            SDL_snprintf(audiopath, SDL_arraysize(audiopath),
16464                         "%s%d", audiodev, instance);
16465            test_device(audiopath, flags, test, addfn);
16466        }
16467    }
16468}
16469
16470#endif
16471#if SDL_AUDIO_DRIVER_WINMM
16472
16473#include <mmsystem.h>
16474
16475#ifndef _SDL_winmm_h
16476#define _SDL_winmm_h
16477
16478#undef _THIS
16479#define _THIS   SDL_AudioDevice *this
16480
16481#define NUM_BUFFERS 2
16482
16483#undef SDLAUDIOHIDDEN
16484#define SDLAUDIOHIDDEN ((struct SDL_PrivateAudioDataWINMM*)this->hidden)
16485struct SDL_PrivateAudioDataWINMM
16486{
16487    HWAVEOUT hout;
16488    HWAVEIN hin;
16489    HANDLE audio_sem;
16490    Uint8 *mixbuf;
16491    WAVEHDR wavebuf[NUM_BUFFERS];
16492    int next_buffer;
16493};
16494
16495#endif
16496
16497#ifndef WAVE_FORMAT_IEEE_FLOAT
16498#define WAVE_FORMAT_IEEE_FLOAT 0x0003
16499#endif
16500
16501#define DETECT_DEV_IMPL(typ, capstyp) \
16502static void DetectWave##typ##Devs(SDL_AddAudioDevice addfn) { \
16503    const UINT devcount = wave##typ##GetNumDevs(); \
16504    capstyp caps; \
16505    UINT i; \
16506    for (i = 0; i < devcount; i++) { \
16507        if (wave##typ##GetDevCaps(i,&caps,sizeof(caps))==MMSYSERR_NOERROR) { \
16508            char *name = WIN_StringToUTF8(caps.szPname); \
16509            if (name != NULL) { \
16510                addfn(name); \
16511                SDL_free(name); \
16512            } \
16513        } \
16514    } \
16515}
16516
16517DETECT_DEV_IMPL(Out, WAVEOUTCAPS)
16518DETECT_DEV_IMPL(In, WAVEINCAPS)
16519
16520static void
16521WINMM_DetectDevices(int iscapture, SDL_AddAudioDevice addfn)
16522{
16523    if (iscapture) {
16524        DetectWaveInDevs(addfn);
16525    } else {
16526        DetectWaveOutDevs(addfn);
16527    }
16528}
16529
16530static void CALLBACK
16531CaptureSound(HWAVEIN hwi, UINT uMsg, DWORD_PTR dwInstance,
16532          DWORD_PTR dwParam1, DWORD_PTR dwParam2)
16533{
16534    SDL_AudioDevice *this = (SDL_AudioDevice *) dwInstance;
16535
16536    if (uMsg != WIM_DATA)
16537        return;
16538
16539    ReleaseSemaphore(SDLAUDIOHIDDEN->audio_sem, 1, NULL);
16540}
16541
16542static void CALLBACK
16543FillSound(HWAVEOUT hwo, UINT uMsg, DWORD_PTR dwInstance,
16544          DWORD_PTR dwParam1, DWORD_PTR dwParam2)
16545{
16546    SDL_AudioDevice *this = (SDL_AudioDevice *) dwInstance;
16547
16548    if (uMsg != WOM_DONE)
16549        return;
16550
16551    ReleaseSemaphore(SDLAUDIOHIDDEN->audio_sem, 1, NULL);
16552}
16553
16554static int
16555SetMMerror(char *function, MMRESULT code)
16556{
16557    int len;
16558    char errbuf[MAXERRORLENGTH];
16559    wchar_t werrbuf[MAXERRORLENGTH];
16560
16561    SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: ", function);
16562    len = SDL_static_cast(int, SDL_strlen(errbuf));
16563
16564    waveOutGetErrorText(code, werrbuf, MAXERRORLENGTH - len);
16565    WideCharToMultiByte(CP_ACP, 0, werrbuf, -1, errbuf + len,
16566                        MAXERRORLENGTH - len, NULL, NULL);
16567
16568    return SDL_SetError("%s", errbuf);
16569}
16570
16571static void
16572WINMM_WaitDevice(_THIS)
16573{
16574
16575    WaitForSingleObject(SDLAUDIOHIDDEN->audio_sem, INFINITE);
16576}
16577
16578static Uint8 *
16579WINMM_GetDeviceBuf(_THIS)
16580{
16581    return (Uint8 *) (SDLAUDIOHIDDEN->
16582                      wavebuf[SDLAUDIOHIDDEN->next_buffer].lpData);
16583}
16584
16585static void
16586WINMM_PlayDevice(_THIS)
16587{
16588
16589    waveOutWrite(SDLAUDIOHIDDEN->hout,
16590                 &SDLAUDIOHIDDEN->wavebuf[SDLAUDIOHIDDEN->next_buffer],
16591                 sizeof(SDLAUDIOHIDDEN->wavebuf[0]));
16592    SDLAUDIOHIDDEN->next_buffer = (SDLAUDIOHIDDEN->next_buffer + 1) % NUM_BUFFERS;
16593}
16594
16595static void
16596WINMM_WaitDone(_THIS)
16597{
16598    int i, left;
16599
16600    do {
16601        left = NUM_BUFFERS;
16602        for (i = 0; i < NUM_BUFFERS; ++i) {
16603            if (SDLAUDIOHIDDEN->wavebuf[i].dwFlags & WHDR_DONE) {
16604                --left;
16605            }
16606        }
16607        if (left > 0) {
16608            SDL_Delay(100);
16609        }
16610    } while (left > 0);
16611}
16612
16613static void
16614WINMM_CloseDevice(_THIS)
16615{
16616
16617    if (SDLAUDIOHIDDEN != NULL) {
16618        int i;
16619
16620        if (SDLAUDIOHIDDEN->audio_sem) {
16621            CloseHandle(SDLAUDIOHIDDEN->audio_sem);
16622            SDLAUDIOHIDDEN->audio_sem = 0;
16623        }
16624
16625        for (i = 0; i < NUM_BUFFERS; ++i) {
16626            if (SDLAUDIOHIDDEN->wavebuf[i].dwUser != 0xFFFF) {
16627                waveOutUnprepareHeader(SDLAUDIOHIDDEN->hout,
16628                                       &SDLAUDIOHIDDEN->wavebuf[i],
16629                                       sizeof(SDLAUDIOHIDDEN->wavebuf[i]));
16630                SDLAUDIOHIDDEN->wavebuf[i].dwUser = 0xFFFF;
16631            }
16632        }
16633
16634        SDL_free(SDLAUDIOHIDDEN->mixbuf);
16635        SDLAUDIOHIDDEN->mixbuf = NULL;
16636
16637        if (SDLAUDIOHIDDEN->hin) {
16638            waveInClose(SDLAUDIOHIDDEN->hin);
16639            SDLAUDIOHIDDEN->hin = 0;
16640        }
16641
16642        if (SDLAUDIOHIDDEN->hout) {
16643            waveOutClose(SDLAUDIOHIDDEN->hout);
16644            SDLAUDIOHIDDEN->hout = 0;
16645        }
16646
16647        SDL_free(SDLAUDIOHIDDEN);
16648        this->hidden = NULL;
16649    }
16650}
16651
16652static SDL_bool
16653PrepWaveFormat(_THIS, UINT devId, WAVEFORMATEX *pfmt, const int iscapture)
16654{
16655    SDL_zerop(pfmt);
16656
16657    if (SDL_AUDIO_ISFLOAT(this->spec.format)) {
16658        pfmt->wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
16659    } else {
16660        pfmt->wFormatTag = WAVE_FORMAT_PCM;
16661    }
16662    pfmt->wBitsPerSample = SDL_AUDIO_BITSIZE(this->spec.format);
16663
16664    pfmt->nChannels = this->spec.channels;
16665    pfmt->nSamplesPerSec = this->spec.freq;
16666    pfmt->nBlockAlign = pfmt->nChannels * (pfmt->wBitsPerSample / 8);
16667    pfmt->nAvgBytesPerSec = pfmt->nSamplesPerSec * pfmt->nBlockAlign;
16668
16669    if (iscapture) {
16670        return (waveInOpen(0, devId, pfmt, 0, 0, WAVE_FORMAT_QUERY) == 0);
16671    } else {
16672        return (waveOutOpen(0, devId, pfmt, 0, 0, WAVE_FORMAT_QUERY) == 0);
16673    }
16674}
16675
16676static int
16677WINMM_OpenDevice(_THIS, const char *devname, int iscapture)
16678{
16679    SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
16680    int valid_datatype = 0;
16681    MMRESULT result;
16682    WAVEFORMATEX waveformat;
16683    UINT devId = WAVE_MAPPER;
16684    char *utf8 = NULL;
16685    UINT i;
16686
16687    if (devname != NULL) {
16688        if (iscapture) {
16689            const UINT devcount = waveInGetNumDevs();
16690            WAVEINCAPS caps;
16691            for (i = 0; (i < devcount) && (devId == WAVE_MAPPER); i++) {
16692                result = waveInGetDevCaps(i, &caps, sizeof (caps));
16693                if (result != MMSYSERR_NOERROR)
16694                    continue;
16695                else if ((utf8 = WIN_StringToUTF8(caps.szPname)) == NULL)
16696                    continue;
16697                else if (SDL_strcmp(devname, utf8) == 0)
16698                    devId = i;
16699                SDL_free(utf8);
16700            }
16701        } else {
16702            const UINT devcount = waveOutGetNumDevs();
16703            WAVEOUTCAPS caps;
16704            for (i = 0; (i < devcount) && (devId == WAVE_MAPPER); i++) {
16705                result = waveOutGetDevCaps(i, &caps, sizeof (caps));
16706                if (result != MMSYSERR_NOERROR)
16707                    continue;
16708                else if ((utf8 = WIN_StringToUTF8(caps.szPname)) == NULL)
16709                    continue;
16710                else if (SDL_strcmp(devname, utf8) == 0)
16711                    devId = i;
16712                SDL_free(utf8);
16713            }
16714        }
16715
16716        if (devId == WAVE_MAPPER) {
16717            return SDL_SetError("Requested device not found");
16718        }
16719    }
16720
16721    this->hidden = (struct SDL_PrivateAudioData *)
16722        SDL_malloc((sizeof *SDLAUDIOHIDDEN));
16723    if (SDLAUDIOHIDDEN == NULL) {
16724        return SDL_OutOfMemory();
16725    }
16726    SDL_memset(SDLAUDIOHIDDEN, 0, (sizeof *SDLAUDIOHIDDEN));
16727
16728    for (i = 0; i < NUM_BUFFERS; ++i)
16729        SDLAUDIOHIDDEN->wavebuf[i].dwUser = 0xFFFF;
16730
16731    if (this->spec.channels > 2)
16732        this->spec.channels = 2;
16733
16734    if (this->spec.samples < (this->spec.freq / 4))
16735        this->spec.samples = ((this->spec.freq / 4) + 3) & ~3;
16736
16737    while ((!valid_datatype) && (test_format)) {
16738        switch (test_format) {
16739        case AUDIO_U8:
16740        case AUDIO_S16:
16741        case AUDIO_S32:
16742        case AUDIO_F32:
16743            this->spec.format = test_format;
16744            if (PrepWaveFormat(this, devId, &waveformat, iscapture)) {
16745                valid_datatype = 1;
16746            } else {
16747                test_format = SDL_NextAudioFormat();
16748            }
16749            break;
16750
16751        default:
16752            test_format = SDL_NextAudioFormat();
16753            break;
16754        }
16755    }
16756
16757    if (!valid_datatype) {
16758        WINMM_CloseDevice(this);
16759        return SDL_SetError("Unsupported audio format");
16760    }
16761
16762    SDL_CalculateAudioSpec(&this->spec);
16763
16764    if (iscapture) {
16765        result = waveInOpen(&SDLAUDIOHIDDEN->hin, devId, &waveformat,
16766                             (DWORD_PTR) CaptureSound, (DWORD_PTR) this,
16767                             CALLBACK_FUNCTION);
16768    } else {
16769        result = waveOutOpen(&SDLAUDIOHIDDEN->hout, devId, &waveformat,
16770                             (DWORD_PTR) FillSound, (DWORD_PTR) this,
16771                             CALLBACK_FUNCTION);
16772    }
16773
16774    if (result != MMSYSERR_NOERROR) {
16775        WINMM_CloseDevice(this);
16776        return SetMMerror("waveOutOpen()", result);
16777    }
16778#ifdef SOUND_DEBUG
16779
16780    {
16781        WAVEOUTCAPS caps;
16782
16783        result = waveOutGetDevCaps((UINT) SDLAUDIOHIDDEN->hout,
16784                                   &caps, sizeof(caps));
16785        if (result != MMSYSERR_NOERROR) {
16786            WINMM_CloseDevice(this);
16787            return SetMMerror("waveOutGetDevCaps()", result);
16788        }
16789        printf("Audio device: %s\n", caps.szPname);
16790    }
16791#endif
16792
16793    SDLAUDIOHIDDEN->audio_sem =
16794        CreateSemaphore(NULL, NUM_BUFFERS - 1, NUM_BUFFERS, NULL);
16795    if (SDLAUDIOHIDDEN->audio_sem == NULL) {
16796        WINMM_CloseDevice(this);
16797        return SDL_SetError("Couldn't create semaphore");
16798    }
16799
16800    SDLAUDIOHIDDEN->mixbuf =
16801        (Uint8 *) SDL_malloc(NUM_BUFFERS * this->spec.size);
16802    if (SDLAUDIOHIDDEN->mixbuf == NULL) {
16803        WINMM_CloseDevice(this);
16804        return SDL_OutOfMemory();
16805    }
16806    for (i = 0; i < NUM_BUFFERS; ++i) {
16807        SDL_memset(&SDLAUDIOHIDDEN->wavebuf[i], 0,
16808                   sizeof(SDLAUDIOHIDDEN->wavebuf[i]));
16809        SDLAUDIOHIDDEN->wavebuf[i].dwBufferLength = this->spec.size;
16810        SDLAUDIOHIDDEN->wavebuf[i].dwFlags = WHDR_DONE;
16811        SDLAUDIOHIDDEN->wavebuf[i].lpData =
16812            (LPSTR) & SDLAUDIOHIDDEN->mixbuf[i * this->spec.size];
16813        result = waveOutPrepareHeader(SDLAUDIOHIDDEN->hout,
16814                                      &SDLAUDIOHIDDEN->wavebuf[i],
16815                                      sizeof(SDLAUDIOHIDDEN->wavebuf[i]));
16816        if (result != MMSYSERR_NOERROR) {
16817            WINMM_CloseDevice(this);
16818            return SetMMerror("waveOutPrepareHeader()", result);
16819        }
16820    }
16821
16822    return 0;
16823}
16824
16825static int
16826WINMM_Init(SDL_AudioDriverImpl * impl)
16827{
16828
16829    impl->DetectDevices = WINMM_DetectDevices;
16830    impl->OpenDevice = WINMM_OpenDevice;
16831    impl->PlayDevice = WINMM_PlayDevice;
16832    impl->WaitDevice = WINMM_WaitDevice;
16833    impl->WaitDone = WINMM_WaitDone;
16834    impl->GetDeviceBuf = WINMM_GetDeviceBuf;
16835    impl->CloseDevice = WINMM_CloseDevice;
16836
16837    return 1;
16838}
16839
16840AudioBootStrap WINMM_bootstrap = {
16841    "winmm", "Windows Waveform Audio", WINMM_Init, 0
16842};
16843
16844#endif
16845#if SDL_AUDIO_DRIVER_XAUDIO2
16846
16847#ifdef __GNUC__
16848
16849#  define SDL_XAUDIO2_HAS_SDK 1
16850#elif defined(__WINRT__)
16851
16852#  define SDL_XAUDIO2_HAS_SDK
16853#else
16854
16855#include <dxsdkver.h>
16856#if (!defined(_DXSDK_BUILD_MAJOR) || (_DXSDK_BUILD_MAJOR < 1284))
16857#  pragma message("Your DirectX SDK is too old. Disabling XAudio2 support.")
16858#else
16859#  define SDL_XAUDIO2_HAS_SDK 1
16860#endif
16861#endif
16862
16863#ifdef SDL_XAUDIO2_HAS_SDK
16864
16865#ifdef WINVER
16866#if WINVER >= 0x0602
16867#define SDL_XAUDIO2_WIN8 1
16868#endif
16869#endif
16870
16871#ifdef __WINRT__
16872#define uuid(x)
16873#define DX_BUILD
16874#endif
16875
16876#define INITGUID 1
16877#include <xaudio2.h>
16878
16879#undef _THIS
16880#define _THIS   SDL_AudioDevice *this
16881
16882#ifdef __WINRT__
16883#include "SDL_xaudio2_winrthelpers.h"
16884#endif
16885
16886#ifdef __GNUC__
16887#ifdef THIS
16888#undef THIS
16889#endif
16890#define THIS    INTERFACE *p
16891#ifdef THIS_
16892#undef THIS_
16893#endif
16894#define THIS_   INTERFACE *p,
16895#endif
16896
16897#undef SDLAUDIOHIDDEN
16898#define SDLAUDIOHIDDEN ((struct SDL_PrivateAudioDataXAUDIO2*)this->hidden)
16899struct SDL_PrivateAudioDataXAUDIO2
16900{
16901    IXAudio2 *ixa2;
16902    IXAudio2SourceVoice *source;
16903    IXAudio2MasteringVoice *mastering;
16904    SDL_sem * semaphore;
16905    Uint8 *mixbuf;
16906    int mixlen;
16907    Uint8 *nextbuf;
16908};
16909
16910static void
16911XAUDIO2_DetectDevices(int iscapture, SDL_AddAudioDevice addfn)
16912{
16913    IXAudio2 *ixa2 = NULL;
16914    UINT32 devcount = 0;
16915    UINT32 i = 0;
16916
16917    if (iscapture) {
16918        SDL_SetError("XAudio2: capture devices unsupported.");
16919        return;
16920    } else if (XAudio2Create(&ixa2, 0, XAUDIO2_DEFAULT_PROCESSOR) != S_OK) {
16921        SDL_SetError("XAudio2: XAudio2Create() failed at detection.");
16922        return;
16923    } else if (IXAudio2_GetDeviceCount(ixa2, &devcount) != S_OK) {
16924        SDL_SetError("XAudio2: IXAudio2::GetDeviceCount() failed.");
16925        IXAudio2_Release(ixa2);
16926        return;
16927    }
16928
16929    for (i = 0; i < devcount; i++) {
16930        XAUDIO2_DEVICE_DETAILS details;
16931        if (IXAudio2_GetDeviceDetails(ixa2, i, &details) == S_OK) {
16932            char *str = WIN_StringToUTF8(details.DisplayName);
16933            if (str != NULL) {
16934                addfn(str);
16935                SDL_free(str);
16936            }
16937        }
16938    }
16939
16940    IXAudio2_Release(ixa2);
16941}
16942
16943static void STDMETHODCALLTYPE
16944VoiceCBOnBufferEnd(THIS_ void *data)
16945{
16946
16947    SDL_AudioDevice *this = (SDL_AudioDevice *) data;
16948    SDL_SemPost(SDLAUDIOHIDDEN->semaphore);
16949}
16950
16951static void STDMETHODCALLTYPE
16952VoiceCBOnVoiceError(THIS_ void *data, HRESULT Error)
16953{
16954
16955    SDL_assert(0 && "write me!");
16956}
16957
16958static void STDMETHODCALLTYPE VoiceCBOnStreamEnd(THIS) {}
16959static void STDMETHODCALLTYPE VoiceCBOnVoiceProcessPassStart(THIS_ UINT32 b) {}
16960static void STDMETHODCALLTYPE VoiceCBOnVoiceProcessPassEnd(THIS) {}
16961static void STDMETHODCALLTYPE VoiceCBOnBufferStart(THIS_ void *data) {}
16962static void STDMETHODCALLTYPE VoiceCBOnLoopEnd(THIS_ void *data) {}
16963
16964static Uint8 *
16965XAUDIO2_GetDeviceBuf(_THIS)
16966{
16967    return SDLAUDIOHIDDEN->nextbuf;
16968}
16969
16970static void
16971XAUDIO2_PlayDevice(_THIS)
16972{
16973    XAUDIO2_BUFFER buffer;
16974    Uint8 *mixbuf = SDLAUDIOHIDDEN->mixbuf;
16975    Uint8 *nextbuf = SDLAUDIOHIDDEN->nextbuf;
16976    const int mixlen = SDLAUDIOHIDDEN->mixlen;
16977    IXAudio2SourceVoice *source = SDLAUDIOHIDDEN->source;
16978    HRESULT result = S_OK;
16979
16980    if (!this->enabled) {
16981        return;
16982    }
16983
16984    SDL_zero(buffer);
16985    buffer.AudioBytes = mixlen;
16986    buffer.pAudioData = nextbuf;
16987    buffer.pContext = this;
16988
16989    if (nextbuf == mixbuf) {
16990        nextbuf += mixlen;
16991    } else {
16992        nextbuf = mixbuf;
16993    }
16994    SDLAUDIOHIDDEN->nextbuf = nextbuf;
16995
16996    result = IXAudio2SourceVoice_SubmitSourceBuffer(source, &buffer, NULL);
16997    if (result == XAUDIO2_E_DEVICE_INVALIDATED) {
16998
16999    }
17000
17001    if (result != S_OK) {
17002        IXAudio2SourceVoice_FlushSourceBuffers(source);
17003        this->enabled = 0;
17004    }
17005}
17006
17007static void
17008XAUDIO2_WaitDevice(_THIS)
17009{
17010    if (this->enabled) {
17011        SDL_SemWait(SDLAUDIOHIDDEN->semaphore);
17012    }
17013}
17014
17015static void
17016XAUDIO2_WaitDone(_THIS)
17017{
17018    IXAudio2SourceVoice *source = SDLAUDIOHIDDEN->source;
17019    XAUDIO2_VOICE_STATE state;
17020    SDL_assert(!this->enabled);
17021    IXAudio2SourceVoice_Discontinuity(source);
17022#if SDL_XAUDIO2_WIN8
17023    IXAudio2SourceVoice_GetState(source, &state, 0);
17024#else
17025    IXAudio2SourceVoice_GetState(source, &state);
17026#endif
17027    while (state.BuffersQueued > 0) {
17028        SDL_SemWait(SDLAUDIOHIDDEN->semaphore);
17029#if SDL_XAUDIO2_WIN8
17030        IXAudio2SourceVoice_GetState(source, &state, 0);
17031#else
17032        IXAudio2SourceVoice_GetState(source, &state);
17033#endif
17034    }
17035}
17036
17037static void
17038XAUDIO2_CloseDevice(_THIS)
17039{
17040    if (SDLAUDIOHIDDEN != NULL) {
17041        IXAudio2 *ixa2 = SDLAUDIOHIDDEN->ixa2;
17042        IXAudio2SourceVoice *source = SDLAUDIOHIDDEN->source;
17043        IXAudio2MasteringVoice *mastering = SDLAUDIOHIDDEN->mastering;
17044
17045        if (source != NULL) {
17046            IXAudio2SourceVoice_Stop(source, 0, XAUDIO2_COMMIT_NOW);
17047            IXAudio2SourceVoice_FlushSourceBuffers(source);
17048            IXAudio2SourceVoice_DestroyVoice(source);
17049        }
17050        if (ixa2 != NULL) {
17051            IXAudio2_StopEngine(ixa2);
17052        }
17053        if (mastering != NULL) {
17054            IXAudio2MasteringVoice_DestroyVoice(mastering);
17055        }
17056        if (ixa2 != NULL) {
17057            IXAudio2_Release(ixa2);
17058        }
17059        SDL_free(SDLAUDIOHIDDEN->mixbuf);
17060        if (SDLAUDIOHIDDEN->semaphore != NULL) {
17061            SDL_DestroySemaphore(SDLAUDIOHIDDEN->semaphore);
17062        }
17063
17064        SDL_free(SDLAUDIOHIDDEN);
17065        this->hidden = NULL;
17066    }
17067}
17068
17069static int
17070XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture)
17071{
17072    HRESULT result = S_OK;
17073    WAVEFORMATEX waveformat;
17074    int valid_format = 0;
17075    SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
17076    IXAudio2 *ixa2 = NULL;
17077    IXAudio2SourceVoice *source = NULL;
17078#if defined(SDL_XAUDIO2_WIN8)
17079    LPCWSTR devId = NULL;
17080#else
17081    UINT32 devId = 0;
17082#endif
17083
17084    static IXAudio2VoiceCallbackVtbl callbacks_vtable = {
17085        VoiceCBOnVoiceProcessPassStart,
17086        VoiceCBOnVoiceProcessPassEnd,
17087        VoiceCBOnStreamEnd,
17088        VoiceCBOnBufferStart,
17089        VoiceCBOnBufferEnd,
17090        VoiceCBOnLoopEnd,
17091        VoiceCBOnVoiceError
17092    };
17093
17094    static IXAudio2VoiceCallback callbacks = { &callbacks_vtable };
17095
17096    if (iscapture) {
17097        return SDL_SetError("XAudio2: capture devices unsupported.");
17098    } else if (XAudio2Create(&ixa2, 0, XAUDIO2_DEFAULT_PROCESSOR) != S_OK) {
17099        return SDL_SetError("XAudio2: XAudio2Create() failed at open.");
17100    }
17101
17102#if ! defined(__WINRT__)
17103    if (devname != NULL) {
17104        UINT32 devcount = 0;
17105        UINT32 i = 0;
17106
17107        if (IXAudio2_GetDeviceCount(ixa2, &devcount) != S_OK) {
17108            IXAudio2_Release(ixa2);
17109            return SDL_SetError("XAudio2: IXAudio2_GetDeviceCount() failed.");
17110        }
17111        for (i = 0; i < devcount; i++) {
17112            XAUDIO2_DEVICE_DETAILS details;
17113            if (IXAudio2_GetDeviceDetails(ixa2, i, &details) == S_OK) {
17114                char *str = WIN_StringToUTF8(details.DisplayName);
17115                if (str != NULL) {
17116                    const int match = (SDL_strcmp(str, devname) == 0);
17117                    SDL_free(str);
17118                    if (match) {
17119                        devId = i;
17120                        break;
17121                    }
17122                }
17123            }
17124        }
17125
17126        if (i == devcount) {
17127            IXAudio2_Release(ixa2);
17128            return SDL_SetError("XAudio2: Requested device not found.");
17129        }
17130    }
17131#endif
17132
17133    this->hidden = (struct SDL_PrivateAudioData *)
17134        SDL_malloc((sizeof *SDLAUDIOHIDDEN));
17135    if (SDLAUDIOHIDDEN == NULL) {
17136        IXAudio2_Release(ixa2);
17137        return SDL_OutOfMemory();
17138    }
17139    SDL_memset(SDLAUDIOHIDDEN, 0, (sizeof *SDLAUDIOHIDDEN));
17140
17141    SDLAUDIOHIDDEN->ixa2 = ixa2;
17142    SDLAUDIOHIDDEN->semaphore = SDL_CreateSemaphore(1);
17143    if (SDLAUDIOHIDDEN->semaphore == NULL) {
17144        XAUDIO2_CloseDevice(this);
17145        return SDL_SetError("XAudio2: CreateSemaphore() failed!");
17146    }
17147
17148    while ((!valid_format) && (test_format)) {
17149        switch (test_format) {
17150        case AUDIO_U8:
17151        case AUDIO_S16:
17152        case AUDIO_S32:
17153        case AUDIO_F32:
17154            this->spec.format = test_format;
17155            valid_format = 1;
17156            break;
17157        }
17158        test_format = SDL_NextAudioFormat();
17159    }
17160
17161    if (!valid_format) {
17162        XAUDIO2_CloseDevice(this);
17163        return SDL_SetError("XAudio2: Unsupported audio format");
17164    }
17165
17166    SDL_CalculateAudioSpec(&this->spec);
17167
17168    SDLAUDIOHIDDEN->mixlen = this->spec.size;
17169    SDLAUDIOHIDDEN->mixbuf = (Uint8 *) SDL_malloc(2 * SDLAUDIOHIDDEN->mixlen);
17170    if (SDLAUDIOHIDDEN->mixbuf == NULL) {
17171        XAUDIO2_CloseDevice(this);
17172        return SDL_OutOfMemory();
17173    }
17174    SDLAUDIOHIDDEN->nextbuf = SDLAUDIOHIDDEN->mixbuf;
17175    SDL_memset(SDLAUDIOHIDDEN->mixbuf, 0, 2 * SDLAUDIOHIDDEN->mixlen);
17176
17177#if SDL_XAUDIO2_WIN8
17178    result = IXAudio2_CreateMasteringVoice(ixa2, &SDLAUDIOHIDDEN->mastering,
17179                                           XAUDIO2_DEFAULT_CHANNELS,
17180                                           this->spec.freq, 0, devId, NULL, AudioCategory_GameEffects);
17181#else
17182    result = IXAudio2_CreateMasteringVoice(ixa2, &SDLAUDIOHIDDEN->mastering,
17183                                           XAUDIO2_DEFAULT_CHANNELS,
17184                                           this->spec.freq, 0, devId, NULL);
17185#endif
17186    if (result != S_OK) {
17187        XAUDIO2_CloseDevice(this);
17188        return SDL_SetError("XAudio2: Couldn't create mastering voice");
17189    }
17190
17191    SDL_zero(waveformat);
17192    if (SDL_AUDIO_ISFLOAT(this->spec.format)) {
17193        waveformat.wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
17194    } else {
17195        waveformat.wFormatTag = WAVE_FORMAT_PCM;
17196    }
17197    waveformat.wBitsPerSample = SDL_AUDIO_BITSIZE(this->spec.format);
17198    waveformat.nChannels = this->spec.channels;
17199    waveformat.nSamplesPerSec = this->spec.freq;
17200    waveformat.nBlockAlign =
17201        waveformat.nChannels * (waveformat.wBitsPerSample / 8);
17202    waveformat.nAvgBytesPerSec =
17203        waveformat.nSamplesPerSec * waveformat.nBlockAlign;
17204    waveformat.cbSize = sizeof(waveformat);
17205
17206#ifdef __WINRT__
17207
17208    result = IXAudio2_CreateSourceVoice(ixa2, &source, &waveformat,
17209                                        0,
17210                                        1.0f, &callbacks, NULL, NULL);
17211#else
17212    result = IXAudio2_CreateSourceVoice(ixa2, &source, &waveformat,
17213                                        XAUDIO2_VOICE_NOSRC |
17214                                        XAUDIO2_VOICE_NOPITCH,
17215                                        1.0f, &callbacks, NULL, NULL);
17216
17217#endif
17218    if (result != S_OK) {
17219        XAUDIO2_CloseDevice(this);
17220        return SDL_SetError("XAudio2: Couldn't create source voice");
17221    }
17222    SDLAUDIOHIDDEN->source = source;
17223
17224    result = IXAudio2_StartEngine(ixa2);
17225    if (result != S_OK) {
17226        XAUDIO2_CloseDevice(this);
17227        return SDL_SetError("XAudio2: Couldn't start engine");
17228    }
17229
17230    result = IXAudio2SourceVoice_Start(source, 0, XAUDIO2_COMMIT_NOW);
17231    if (result != S_OK) {
17232        XAUDIO2_CloseDevice(this);
17233        return SDL_SetError("XAudio2: Couldn't start source voice");
17234    }
17235
17236    return 0;
17237}
17238
17239static void
17240XAUDIO2_Deinitialize(void)
17241{
17242#if defined(__WIN32__)
17243    WIN_CoUninitialize();
17244#endif
17245}
17246
17247#endif
17248
17249static int
17250XAUDIO2_Init(SDL_AudioDriverImpl * impl)
17251{
17252#ifndef SDL_XAUDIO2_HAS_SDK
17253    SDL_SetError("XAudio2: SDL was built without XAudio2 support (old DirectX SDK).");
17254    return 0;
17255#else
17256
17257    IXAudio2 *ixa2 = NULL;
17258#if defined(__WIN32__)
17259
17260    if (FAILED(WIN_CoInitialize())) {
17261        SDL_SetError("XAudio2: CoInitialize() failed");
17262        return 0;
17263    }
17264#endif
17265
17266    if (XAudio2Create(&ixa2, 0, XAUDIO2_DEFAULT_PROCESSOR) != S_OK) {
17267#if defined(__WIN32__)
17268        WIN_CoUninitialize();
17269#endif
17270        SDL_SetError("XAudio2: XAudio2Create() failed at initialization");
17271        return 0;
17272    }
17273    IXAudio2_Release(ixa2);
17274
17275    impl->DetectDevices = XAUDIO2_DetectDevices;
17276    impl->OpenDevice = XAUDIO2_OpenDevice;
17277    impl->PlayDevice = XAUDIO2_PlayDevice;
17278    impl->WaitDevice = XAUDIO2_WaitDevice;
17279    impl->WaitDone = XAUDIO2_WaitDone;
17280    impl->GetDeviceBuf = XAUDIO2_GetDeviceBuf;
17281    impl->CloseDevice = XAUDIO2_CloseDevice;
17282    impl->Deinitialize = XAUDIO2_Deinitialize;
17283
17284    return 1;
17285#endif
17286}
17287
17288AudioBootStrap XAUDIO2_bootstrap = {
17289    "xaudio2", "XAudio2", XAUDIO2_Init, 0
17290};
17291
17292#endif
17293#if !SDL_THREAD_PTHREAD
17294
17295struct SDL_cond
17296{
17297    SDL_mutex *lock;
17298    int waiting;
17299    int signals;
17300    SDL_sem *wait_sem;
17301    SDL_sem *wait_done;
17302};
17303
17304SDL_cond *
17305SDL_CreateCond(void)
17306{
17307    SDL_cond *cond;
17308
17309    cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond));
17310    if (cond) {
17311        cond->lock = SDL_CreateMutex();
17312        cond->wait_sem = SDL_CreateSemaphore(0);
17313        cond->wait_done = SDL_CreateSemaphore(0);
17314        cond->waiting = cond->signals = 0;
17315        if (!cond->lock || !cond->wait_sem || !cond->wait_done) {
17316            SDL_DestroyCond(cond);
17317            cond = NULL;
17318        }
17319    } else {
17320        SDL_OutOfMemory();
17321    }
17322    return (cond);
17323}
17324
17325void
17326SDL_DestroyCond(SDL_cond * cond)
17327{
17328    if (cond) {
17329        if (cond->wait_sem) {
17330            SDL_DestroySemaphore(cond->wait_sem);
17331        }
17332        if (cond->wait_done) {
17333            SDL_DestroySemaphore(cond->wait_done);
17334        }
17335        if (cond->lock) {
17336            SDL_DestroyMutex(cond->lock);
17337        }
17338        SDL_free(cond);
17339    }
17340}
17341
17342int
17343SDL_CondSignal(SDL_cond * cond)
17344{
17345    if (!cond) {
17346        return SDL_SetError("Passed a NULL condition variable");
17347    }
17348
17349    SDL_LockMutex(cond->lock);
17350    if (cond->waiting > cond->signals) {
17351        ++cond->signals;
17352        SDL_SemPost(cond->wait_sem);
17353        SDL_UnlockMutex(cond->lock);
17354        SDL_SemWait(cond->wait_done);
17355    } else {
17356        SDL_UnlockMutex(cond->lock);
17357    }
17358
17359    return 0;
17360}
17361
17362int
17363SDL_CondBroadcast(SDL_cond * cond)
17364{
17365    if (!cond) {
17366        return SDL_SetError("Passed a NULL condition variable");
17367    }
17368
17369    SDL_LockMutex(cond->lock);
17370    if (cond->waiting > cond->signals) {
17371        int i, num_waiting;
17372
17373        num_waiting = (cond->waiting - cond->signals);
17374        cond->signals = cond->waiting;
17375        for (i = 0; i < num_waiting; ++i) {
17376            SDL_SemPost(cond->wait_sem);
17377        }
17378
17379        SDL_UnlockMutex(cond->lock);
17380        for (i = 0; i < num_waiting; ++i) {
17381            SDL_SemWait(cond->wait_done);
17382        }
17383    } else {
17384        SDL_UnlockMutex(cond->lock);
17385    }
17386
17387    return 0;
17388}
17389
17390int
17391SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
17392{
17393    int retval;
17394
17395    if (!cond) {
17396        return SDL_SetError("Passed a NULL condition variable");
17397    }
17398
17399    SDL_LockMutex(cond->lock);
17400    ++cond->waiting;
17401    SDL_UnlockMutex(cond->lock);
17402
17403    SDL_UnlockMutex(mutex);
17404
17405    if (ms == SDL_MUTEX_MAXWAIT) {
17406        retval = SDL_SemWait(cond->wait_sem);
17407    } else {
17408        retval = SDL_SemWaitTimeout(cond->wait_sem, ms);
17409    }
17410
17411    SDL_LockMutex(cond->lock);
17412    if (cond->signals > 0) {
17413
17414        if (retval > 0) {
17415            SDL_SemWait(cond->wait_sem);
17416        }
17417
17418        SDL_SemPost(cond->wait_done);
17419
17420        --cond->signals;
17421    }
17422    --cond->waiting;
17423    SDL_UnlockMutex(cond->lock);
17424
17425    SDL_LockMutex(mutex);
17426
17427    return retval;
17428}
17429
17430int
17431SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex)
17432{
17433    return SDL_CondWaitTimeout(cond, mutex, SDL_MUTEX_MAXWAIT);
17434}
17435
17436#endif
17437#if !SDL_THREAD_PTHREAD || defined(__MACOSX__) || defined(__IPHONEOS__)
17438#if !SDL_THREAD_WINDOWS
17439
17440#if SDL_THREADS_DISABLED
17441
17442SDL_sem *
17443SDL_CreateSemaphore(Uint32 initial_value)
17444{
17445    SDL_SetError("SDL not built with thread support");
17446    return (SDL_sem *) 0;
17447}
17448
17449void
17450SDL_DestroySemaphore(SDL_sem * sem)
17451{
17452}
17453
17454int
17455SDL_SemTryWait(SDL_sem * sem)
17456{
17457    return SDL_SetError("SDL not built with thread support");
17458}
17459
17460int
17461SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
17462{
17463    return SDL_SetError("SDL not built with thread support");
17464}
17465
17466int
17467SDL_SemWait(SDL_sem * sem)
17468{
17469    return SDL_SetError("SDL not built with thread support");
17470}
17471
17472Uint32
17473SDL_SemValue(SDL_sem * sem)
17474{
17475    return 0;
17476}
17477
17478int
17479SDL_SemPost(SDL_sem * sem)
17480{
17481    return SDL_SetError("SDL not built with thread support");
17482}
17483
17484#else
17485
17486struct SDL_semaphore
17487{
17488    Uint32 count;
17489    Uint32 waiters_count;
17490    SDL_mutex *count_lock;
17491    SDL_cond *count_nonzero;
17492};
17493
17494SDL_sem *
17495SDL_CreateSemaphore(Uint32 initial_value)
17496{
17497    SDL_sem *sem;
17498
17499    sem = (SDL_sem *) SDL_malloc(sizeof(*sem));
17500    if (!sem) {
17501        SDL_OutOfMemory();
17502        return NULL;
17503    }
17504    sem->count = initial_value;
17505    sem->waiters_count = 0;
17506
17507    sem->count_lock = SDL_CreateMutex();
17508    sem->count_nonzero = SDL_CreateCond();
17509    if (!sem->count_lock || !sem->count_nonzero) {
17510        SDL_DestroySemaphore(sem);
17511        return NULL;
17512    }
17513
17514    return sem;
17515}
17516
17517void
17518SDL_DestroySemaphore(SDL_sem * sem)
17519{
17520    if (sem) {
17521        sem->count = 0xFFFFFFFF;
17522        while (sem->waiters_count > 0) {
17523            SDL_CondSignal(sem->count_nonzero);
17524            SDL_Delay(10);
17525        }
17526        SDL_DestroyCond(sem->count_nonzero);
17527        if (sem->count_lock) {
17528            SDL_LockMutex(sem->count_lock);
17529            SDL_UnlockMutex(sem->count_lock);
17530            SDL_DestroyMutex(sem->count_lock);
17531        }
17532        SDL_free(sem);
17533    }
17534}
17535
17536int
17537SDL_SemTryWait(SDL_sem * sem)
17538{
17539    int retval;
17540
17541    if (!sem) {
17542        return SDL_SetError("Passed a NULL semaphore");
17543    }
17544
17545    retval = SDL_MUTEX_TIMEDOUT;
17546    SDL_LockMutex(sem->count_lock);
17547    if (sem->count > 0) {
17548        --sem->count;
17549        retval = 0;
17550    }
17551    SDL_UnlockMutex(sem->count_lock);
17552
17553    return retval;
17554}
17555
17556int
17557SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
17558{
17559    int retval;
17560
17561    if (!sem) {
17562        return SDL_SetError("Passed a NULL semaphore");
17563    }
17564
17565    if (timeout == 0) {
17566        return SDL_SemTryWait(sem);
17567    }
17568
17569    SDL_LockMutex(sem->count_lock);
17570    ++sem->waiters_count;
17571    retval = 0;
17572    while ((sem->count == 0) && (retval != SDL_MUTEX_TIMEDOUT)) {
17573        retval = SDL_CondWaitTimeout(sem->count_nonzero,
17574                                     sem->count_lock, timeout);
17575    }
17576    --sem->waiters_count;
17577    if (retval == 0) {
17578        --sem->count;
17579    }
17580    SDL_UnlockMutex(sem->count_lock);
17581
17582    return retval;
17583}
17584
17585int
17586SDL_SemWait(SDL_sem * sem)
17587{
17588    return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT);
17589}
17590
17591Uint32
17592SDL_SemValue(SDL_sem * sem)
17593{
17594    Uint32 value;
17595
17596    value = 0;
17597    if (sem) {
17598        SDL_LockMutex(sem->count_lock);
17599        value = sem->count;
17600        SDL_UnlockMutex(sem->count_lock);
17601    }
17602    return value;
17603}
17604
17605int
17606SDL_SemPost(SDL_sem * sem)
17607{
17608    if (!sem) {
17609        return SDL_SetError("Passed a NULL semaphore");
17610    }
17611
17612    SDL_LockMutex(sem->count_lock);
17613    if (sem->waiters_count > 0) {
17614        SDL_CondSignal(sem->count_nonzero);
17615    }
17616    ++sem->count;
17617    SDL_UnlockMutex(sem->count_lock);
17618
17619    return 0;
17620}
17621
17622#endif
17623
17624#endif
17625#endif
17626#if SDL_THREAD_PTHREAD
17627
17628#define _GNU_SOURCE
17629#include <pthread.h>
17630#include <errno.h>
17631
17632#if !SDL_THREAD_PTHREAD_RECURSIVE_MUTEX && \
17633    !SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP
17634#define FAKE_RECURSIVE_MUTEX 1
17635#endif
17636
17637struct SDL_mutex
17638{
17639    pthread_mutex_t id;
17640#if FAKE_RECURSIVE_MUTEX
17641    int recursive;
17642    pthread_t owner;
17643#endif
17644};
17645
17646SDL_mutex *
17647SDL_CreateMutex(void)
17648{
17649    SDL_mutex *mutex;
17650    pthread_mutexattr_t attr;
17651
17652    mutex = (SDL_mutex *) SDL_calloc(1, sizeof(*mutex));
17653    if (mutex) {
17654        pthread_mutexattr_init(&attr);
17655#if SDL_THREAD_PTHREAD_RECURSIVE_MUTEX
17656        pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
17657#elif SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP
17658        pthread_mutexattr_setkind_np(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
17659#else
17660
17661#endif
17662        if (pthread_mutex_init(&mutex->id, &attr) != 0) {
17663            SDL_SetError("pthread_mutex_init() failed");
17664            SDL_free(mutex);
17665            mutex = NULL;
17666        }
17667    } else {
17668        SDL_OutOfMemory();
17669    }
17670    return (mutex);
17671}
17672
17673void
17674SDL_DestroyMutex(SDL_mutex * mutex)
17675{
17676    if (mutex) {
17677        pthread_mutex_destroy(&mutex->id);
17678        SDL_free(mutex);
17679    }
17680}
17681
17682int
17683SDL_LockMutex(SDL_mutex * mutex)
17684{
17685#if FAKE_RECURSIVE_MUTEX
17686    pthread_t this_thread;
17687#endif
17688
17689    if (mutex == NULL) {
17690        return SDL_SetError("Passed a NULL mutex");
17691    }
17692
17693#if FAKE_RECURSIVE_MUTEX
17694    this_thread = pthread_self();
17695    if (mutex->owner == this_thread) {
17696        ++mutex->recursive;
17697    } else {
17698
17699        if (pthread_mutex_lock(&mutex->id) == 0) {
17700            mutex->owner = this_thread;
17701            mutex->recursive = 0;
17702        } else {
17703            return SDL_SetError("pthread_mutex_lock() failed");
17704        }
17705    }
17706#else
17707    if (pthread_mutex_lock(&mutex->id) < 0) {
17708        return SDL_SetError("pthread_mutex_lock() failed");
17709    }
17710#endif
17711    return 0;
17712}
17713
17714int
17715SDL_TryLockMutex(SDL_mutex * mutex)
17716{
17717    int retval;
17718#if FAKE_RECURSIVE_MUTEX
17719    pthread_t this_thread;
17720#endif
17721
17722    if (mutex == NULL) {
17723        return SDL_SetError("Passed a NULL mutex");
17724    }
17725
17726    retval = 0;
17727#if FAKE_RECURSIVE_MUTEX
17728    this_thread = pthread_self();
17729    if (mutex->owner == this_thread) {
17730        ++mutex->recursive;
17731    } else {
17732
17733        if (pthread_mutex_lock(&mutex->id) == 0) {
17734            mutex->owner = this_thread;
17735            mutex->recursive = 0;
17736        } else if (errno == EBUSY) {
17737            retval = SDL_MUTEX_TIMEDOUT;
17738        } else {
17739            retval = SDL_SetError("pthread_mutex_trylock() failed");
17740        }
17741    }
17742#else
17743    if (pthread_mutex_trylock(&mutex->id) != 0) {
17744        if (errno == EBUSY) {
17745            retval = SDL_MUTEX_TIMEDOUT;
17746        } else {
17747            retval = SDL_SetError("pthread_mutex_trylock() failed");
17748        }
17749    }
17750#endif
17751    return retval;
17752}
17753
17754int
17755SDL_UnlockMutex(SDL_mutex * mutex)
17756{
17757    if (mutex == NULL) {
17758        return SDL_SetError("Passed a NULL mutex");
17759    }
17760
17761#if FAKE_RECURSIVE_MUTEX
17762
17763    if (pthread_self() == mutex->owner) {
17764        if (mutex->recursive) {
17765            --mutex->recursive;
17766        } else {
17767
17768            mutex->owner = 0;
17769            pthread_mutex_unlock(&mutex->id);
17770        }
17771    } else {
17772        return SDL_SetError("mutex not owned by this thread");
17773    }
17774
17775#else
17776    if (pthread_mutex_unlock(&mutex->id) < 0) {
17777        return SDL_SetError("pthread_mutex_unlock() failed");
17778    }
17779#endif
17780
17781    return 0;
17782}
17783
17784#endif
17785#if SDL_THREAD_PTHREAD
17786
17787#include <sys/time.h>
17788#include <unistd.h>
17789#include <errno.h>
17790#include <pthread.h>
17791
17792#ifndef _SDL_mutex_c_h
17793#define _SDL_mutex_c_h
17794
17795//struct SDL_mutex
17796//{
17797//    pthread_mutex_t id;
17798//};
17799
17800#endif
17801
17802struct SDL_cond
17803{
17804    pthread_cond_t cond;
17805};
17806
17807SDL_cond *
17808SDL_CreateCond(void)
17809{
17810    SDL_cond *cond;
17811
17812    cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond));
17813    if (cond) {
17814        if (pthread_cond_init(&cond->cond, NULL) < 0) {
17815            SDL_SetError("pthread_cond_init() failed");
17816            SDL_free(cond);
17817            cond = NULL;
17818        }
17819    }
17820    return (cond);
17821}
17822
17823void
17824SDL_DestroyCond(SDL_cond * cond)
17825{
17826    if (cond) {
17827        pthread_cond_destroy(&cond->cond);
17828        SDL_free(cond);
17829    }
17830}
17831
17832int
17833SDL_CondSignal(SDL_cond * cond)
17834{
17835    int retval;
17836
17837    if (!cond) {
17838        return SDL_SetError("Passed a NULL condition variable");
17839    }
17840
17841    retval = 0;
17842    if (pthread_cond_signal(&cond->cond) != 0) {
17843        return SDL_SetError("pthread_cond_signal() failed");
17844    }
17845    return retval;
17846}
17847
17848int
17849SDL_CondBroadcast(SDL_cond * cond)
17850{
17851    int retval;
17852
17853    if (!cond) {
17854        return SDL_SetError("Passed a NULL condition variable");
17855    }
17856
17857    retval = 0;
17858    if (pthread_cond_broadcast(&cond->cond) != 0) {
17859        return SDL_SetError("pthread_cond_broadcast() failed");
17860    }
17861    return retval;
17862}
17863
17864int
17865SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
17866{
17867    int retval;
17868    struct timeval delta;
17869    struct timespec abstime;
17870
17871    if (!cond) {
17872        return SDL_SetError("Passed a NULL condition variable");
17873    }
17874
17875    gettimeofday(&delta, NULL);
17876
17877    abstime.tv_sec = delta.tv_sec + (ms / 1000);
17878    abstime.tv_nsec = (delta.tv_usec + (ms % 1000) * 1000) * 1000;
17879    if (abstime.tv_nsec > 1000000000) {
17880        abstime.tv_sec += 1;
17881        abstime.tv_nsec -= 1000000000;
17882    }
17883
17884  tryagain:
17885    retval = pthread_cond_timedwait(&cond->cond, &mutex->id, &abstime);
17886    switch (retval) {
17887    case EINTR:
17888        goto tryagain;
17889        break;
17890    case ETIMEDOUT:
17891        retval = SDL_MUTEX_TIMEDOUT;
17892        break;
17893    case 0:
17894        break;
17895    default:
17896        retval = SDL_SetError("pthread_cond_timedwait() failed");
17897    }
17898    return retval;
17899}
17900
17901int
17902SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex)
17903{
17904    if (!cond) {
17905        return SDL_SetError("Passed a NULL condition variable");
17906    } else if (pthread_cond_wait(&cond->cond, &mutex->id) != 0) {
17907        return SDL_SetError("pthread_cond_wait() failed");
17908    }
17909    return 0;
17910}
17911
17912#endif
17913#if SDL_THREAD_PTHREAD
17914
17915#include <errno.h>
17916#include <pthread.h>
17917#include <semaphore.h>
17918#include <sys/time.h>
17919
17920#if defined(__MACOSX__) || defined(__IPHONEOS__)
17921#else
17922
17923struct SDL_semaphore
17924{
17925    sem_t sem;
17926};
17927
17928SDL_sem *
17929SDL_CreateSemaphore(Uint32 initial_value)
17930{
17931    SDL_sem *sem = (SDL_sem *) SDL_malloc(sizeof(SDL_sem));
17932    if (sem) {
17933        if (sem_init(&sem->sem, 0, initial_value) < 0) {
17934            SDL_SetError("sem_init() failed");
17935            SDL_free(sem);
17936            sem = NULL;
17937        }
17938    } else {
17939        SDL_OutOfMemory();
17940    }
17941    return sem;
17942}
17943
17944void
17945SDL_DestroySemaphore(SDL_sem * sem)
17946{
17947    if (sem) {
17948        sem_destroy(&sem->sem);
17949        SDL_free(sem);
17950    }
17951}
17952
17953int
17954SDL_SemTryWait(SDL_sem * sem)
17955{
17956    int retval;
17957
17958    if (!sem) {
17959        return SDL_SetError("Passed a NULL semaphore");
17960    }
17961    retval = SDL_MUTEX_TIMEDOUT;
17962    if (sem_trywait(&sem->sem) == 0) {
17963        retval = 0;
17964    }
17965    return retval;
17966}
17967
17968int
17969SDL_SemWait(SDL_sem * sem)
17970{
17971    int retval;
17972
17973    if (!sem) {
17974        return SDL_SetError("Passed a NULL semaphore");
17975    }
17976
17977    retval = sem_wait(&sem->sem);
17978    if (retval < 0) {
17979        retval = SDL_SetError("sem_wait() failed");
17980    }
17981    return retval;
17982}
17983
17984int
17985SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
17986{
17987    int retval;
17988#ifdef HAVE_SEM_TIMEDWAIT
17989    struct timeval now;
17990    struct timespec ts_timeout;
17991#else
17992    Uint32 end;
17993#endif
17994
17995    if (!sem) {
17996        return SDL_SetError("Passed a NULL semaphore");
17997    }
17998
17999    if (timeout == 0) {
18000        return SDL_SemTryWait(sem);
18001    }
18002    if (timeout == SDL_MUTEX_MAXWAIT) {
18003        return SDL_SemWait(sem);
18004    }
18005
18006#ifdef HAVE_SEM_TIMEDWAIT
18007
18008    gettimeofday(&now, NULL);
18009
18010    now.tv_usec += (timeout % 1000) * 1000;
18011    now.tv_sec += timeout / 1000;
18012
18013    if ( now.tv_usec >= 1000000 ) {
18014        now.tv_usec -= 1000000;
18015        now.tv_sec ++;
18016    }
18017
18018    ts_timeout.tv_sec = now.tv_sec;
18019    ts_timeout.tv_nsec = now.tv_usec * 1000;
18020
18021    do {
18022        retval = sem_timedwait(&sem->sem, &ts_timeout);
18023    } while (retval < 0 && errno == EINTR);
18024
18025    if (retval < 0) {
18026        if (errno == ETIMEDOUT) {
18027            retval = SDL_MUTEX_TIMEDOUT;
18028        } else {
18029            SDL_SetError(strerror(errno));
18030        }
18031    }
18032#else
18033    end = SDL_GetTicks() + timeout;
18034    while ((retval = SDL_SemTryWait(sem)) == SDL_MUTEX_TIMEDOUT) {
18035        if ((SDL_GetTicks() - end) >= 0) {
18036            break;
18037        }
18038        SDL_Delay(0);
18039    }
18040#endif
18041
18042    return retval;
18043}
18044
18045Uint32
18046SDL_SemValue(SDL_sem * sem)
18047{
18048    int ret = 0;
18049    if (sem) {
18050        sem_getvalue(&sem->sem, &ret);
18051        if (ret < 0) {
18052            ret = 0;
18053        }
18054    }
18055    return (Uint32) ret;
18056}
18057
18058int
18059SDL_SemPost(SDL_sem * sem)
18060{
18061    int retval;
18062
18063    if (!sem) {
18064        return SDL_SetError("Passed a NULL semaphore");
18065    }
18066
18067    retval = sem_post(&sem->sem);
18068    if (retval < 0) {
18069        SDL_SetError("sem_post() failed");
18070    }
18071    return retval;
18072}
18073
18074#endif
18075
18076#endif
18077#if SDL_THREAD_PTHREAD
18078
18079#include <pthread.h>
18080
18081#if HAVE_PTHREAD_NP_H
18082#include <pthread_np.h>
18083#endif
18084
18085#include <signal.h>
18086
18087#ifdef __LINUX__
18088#include <sys/time.h>
18089#include <sys/resource.h>
18090#include <sys/syscall.h>
18091#include <unistd.h>
18092#endif
18093
18094#if defined(__LINUX__) || defined(__MACOSX__) || defined(__IPHONEOS__)
18095#include <dlfcn.h>
18096#ifndef RTLD_DEFAULT
18097#define RTLD_DEFAULT NULL
18098#endif
18099#endif
18100
18101#ifdef __ANDROID__
18102#include "../../core/android/SDL_android.h"
18103#endif
18104
18105static const int sig_list[] = {
18106    SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH,
18107    SIGVTALRM, SIGPROF, 0
18108};
18109
18110static void *
18111RunThread(void *data)
18112{
18113#ifdef __ANDROID__
18114    Android_JNI_SetupThread();
18115#endif
18116    SDL_RunThread(data);
18117    return NULL;
18118}
18119
18120#if defined(__MACOSX__) || defined(__IPHONEOS__)
18121static SDL_bool checked_setname = SDL_FALSE;
18122static int (*ppthread_setname_np)(const char*) = NULL;
18123#elif defined(__LINUX__)
18124static SDL_bool checked_setname = SDL_FALSE;
18125static int (*ppthread_setname_np)(pthread_t, const char*) = NULL;
18126#endif
18127int
18128SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
18129{
18130    pthread_attr_t type;
18131
18132    #if defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__LINUX__)
18133    if (!checked_setname) {
18134        void *fn = dlsym(RTLD_DEFAULT, "pthread_setname_np");
18135        #if defined(__MACOSX__) || defined(__IPHONEOS__)
18136        ppthread_setname_np = (int(*)(const char*)) fn;
18137        #elif defined(__LINUX__)
18138        ppthread_setname_np = (int(*)(pthread_t, const char*)) fn;
18139        #endif
18140        checked_setname = SDL_TRUE;
18141    }
18142    #endif
18143
18144    if (pthread_attr_init(&type) != 0) {
18145        return SDL_SetError("Couldn't initialize pthread attributes");
18146    }
18147    pthread_attr_setdetachstate(&type, PTHREAD_CREATE_JOINABLE);
18148
18149    if (pthread_create(&thread->handle, &type, RunThread, args) != 0) {
18150        return SDL_SetError("Not enough resources to create thread");
18151    }
18152
18153    return 0;
18154}
18155
18156void
18157SDL_SYS_SetupThread(const char *name)
18158{
18159    int i;
18160    sigset_t mask;
18161
18162    if (name != NULL) {
18163        #if defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__LINUX__)
18164        SDL_assert(checked_setname);
18165        if (ppthread_setname_np != NULL) {
18166            #if defined(__MACOSX__) || defined(__IPHONEOS__)
18167            ppthread_setname_np(name);
18168            #elif defined(__LINUX__)
18169            ppthread_setname_np(pthread_self(), name);
18170            #endif
18171        }
18172        #elif HAVE_PTHREAD_SETNAME_NP
18173            pthread_setname_np(pthread_self(), name);
18174        #elif HAVE_PTHREAD_SET_NAME_NP
18175            pthread_set_name_np(pthread_self(), name);
18176        #endif
18177    }
18178
18179    sigemptyset(&mask);
18180    for (i = 0; sig_list[i]; ++i) {
18181        sigaddset(&mask, sig_list[i]);
18182    }
18183    pthread_sigmask(SIG_BLOCK, &mask, 0);
18184
18185#ifdef PTHREAD_CANCEL_ASYNCHRONOUS
18186
18187    {
18188        int oldstate;
18189        pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);
18190    }
18191#endif
18192}
18193
18194SDL_threadID
18195SDL_ThreadID(void)
18196{
18197    return ((SDL_threadID) pthread_self());
18198}
18199
18200int
18201SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
18202{
18203#ifdef __LINUX__
18204    int value;
18205
18206    if (priority == SDL_THREAD_PRIORITY_LOW) {
18207        value = 19;
18208    } else if (priority == SDL_THREAD_PRIORITY_HIGH) {
18209        value = -20;
18210    } else {
18211        value = 0;
18212    }
18213    if (setpriority(PRIO_PROCESS, syscall(SYS_gettid), value) < 0) {
18214
18215        return SDL_SetError("setpriority() failed");
18216    }
18217    return 0;
18218#else
18219    struct sched_param sched;
18220    int policy;
18221    pthread_t thread = pthread_self();
18222
18223    if (pthread_getschedparam(thread, &policy, &sched) < 0) {
18224        return SDL_SetError("pthread_getschedparam() failed");
18225    }
18226    if (priority == SDL_THREAD_PRIORITY_LOW) {
18227        sched.sched_priority = sched_get_priority_min(policy);
18228    } else if (priority == SDL_THREAD_PRIORITY_HIGH) {
18229        sched.sched_priority = sched_get_priority_max(policy);
18230    } else {
18231        int min_priority = sched_get_priority_min(policy);
18232        int max_priority = sched_get_priority_max(policy);
18233        sched.sched_priority = (min_priority + (max_priority - min_priority) / 2);
18234    }
18235    if (pthread_setschedparam(thread, policy, &sched) < 0) {
18236        return SDL_SetError("pthread_setschedparam() failed");
18237    }
18238    return 0;
18239#endif
18240}
18241
18242void
18243SDL_SYS_WaitThread(SDL_Thread * thread)
18244{
18245    pthread_join(thread->handle, 0);
18246}
18247
18248#endif
18249#define ARRAY_CHUNKSIZE	32
18250
18251static int SDL_maxthreads = 0;
18252static int SDL_numthreads = 0;
18253static SDL_Thread **SDL_Threads = NULL;
18254static SDL_mutex *thread_lock = NULL;
18255
18256static int
18257SDL_ThreadsInit(void)
18258{
18259    int retval;
18260
18261    retval = 0;
18262    thread_lock = SDL_CreateMutex();
18263    if (thread_lock == NULL) {
18264        retval = -1;
18265    }
18266    return (retval);
18267}
18268
18269#if 0
18270static void
18271SDL_ThreadsQuit(void)
18272{
18273    SDL_mutex *mutex;
18274
18275    mutex = thread_lock;
18276    thread_lock = NULL;
18277    if (mutex != NULL) {
18278        SDL_DestroyMutex(mutex);
18279    }
18280}
18281#endif
18282
18283static void
18284SDL_AddThread(SDL_Thread * thread)
18285{
18286
18287    if (!thread_lock) {
18288        if (SDL_ThreadsInit() < 0) {
18289            return;
18290        }
18291    }
18292    SDL_LockMutex(thread_lock);
18293
18294#ifdef DEBUG_THREADS
18295    printf("Adding thread (%d already - %d max)\n",
18296           SDL_numthreads, SDL_maxthreads);
18297#endif
18298    if (SDL_numthreads == SDL_maxthreads) {
18299        SDL_Thread **threads;
18300        threads = (SDL_Thread **) SDL_realloc(SDL_Threads,
18301                                              (SDL_maxthreads +
18302                                               ARRAY_CHUNKSIZE) *
18303                                              (sizeof *threads));
18304        if (threads == NULL) {
18305            SDL_OutOfMemory();
18306            goto done;
18307        }
18308        SDL_maxthreads += ARRAY_CHUNKSIZE;
18309        SDL_Threads = threads;
18310    }
18311    SDL_Threads[SDL_numthreads++] = thread;
18312  done:
18313    SDL_mutexV(thread_lock);
18314}
18315
18316static void
18317SDL_DelThread(SDL_Thread * thread)
18318{
18319    int i;
18320
18321    if (!thread_lock) {
18322        return;
18323    }
18324    SDL_LockMutex(thread_lock);
18325    for (i = 0; i < SDL_numthreads; ++i) {
18326        if (thread == SDL_Threads[i]) {
18327            break;
18328        }
18329    }
18330    if (i < SDL_numthreads) {
18331        if (--SDL_numthreads > 0) {
18332            while (i < SDL_numthreads) {
18333                SDL_Threads[i] = SDL_Threads[i + 1];
18334                ++i;
18335            }
18336        } else {
18337            SDL_maxthreads = 0;
18338            SDL_free(SDL_Threads);
18339            SDL_Threads = NULL;
18340        }
18341#ifdef DEBUG_THREADS
18342        printf("Deleting thread (%d left - %d max)\n",
18343               SDL_numthreads, SDL_maxthreads);
18344#endif
18345    }
18346    SDL_mutexV(thread_lock);
18347
18348#if 0
18349    if (SDL_Threads == NULL) {
18350        SDL_ThreadsQuit();
18351    }
18352#endif
18353}
18354
18355static SDL_error SDL_global_error;
18356
18357SDL_error *
18358SDL_GetErrBuf(void)
18359{
18360    SDL_error *errbuf;
18361
18362    errbuf = &SDL_global_error;
18363    if (SDL_Threads) {
18364        int i;
18365        SDL_threadID this_thread;
18366
18367        this_thread = SDL_ThreadID();
18368        SDL_LockMutex(thread_lock);
18369        for (i = 0; i < SDL_numthreads; ++i) {
18370            if (this_thread == SDL_Threads[i]->threadid) {
18371                errbuf = &SDL_Threads[i]->errbuf;
18372                break;
18373            }
18374        }
18375        SDL_mutexV(thread_lock);
18376    }
18377    return (errbuf);
18378}
18379
18380typedef struct
18381{
18382    int (SDLCALL * func) (void *);
18383    void *data;
18384    SDL_Thread *info;
18385    SDL_sem *wait;
18386} thread_args;
18387
18388void
18389SDL_RunThread(void *data)
18390{
18391    thread_args *args = (thread_args *) data;
18392    int (SDLCALL * userfunc) (void *) = args->func;
18393    void *userdata = args->data;
18394    int *statusloc = &args->info->status;
18395
18396    SDL_SYS_SetupThread(args->info->name);
18397
18398    args->info->threadid = SDL_ThreadID();
18399
18400    SDL_SemPost(args->wait);
18401
18402    *statusloc = userfunc(userdata);
18403}
18404
18405#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
18406#undef SDL_CreateThread
18407DECLSPEC SDL_Thread *SDLCALL
18408SDL_CreateThread(int (SDLCALL * fn) (void *),
18409                 const char *name, void *data,
18410                 pfnSDL_CurrentBeginThread pfnBeginThread,
18411                 pfnSDL_CurrentEndThread pfnEndThread)
18412#else
18413DECLSPEC SDL_Thread *SDLCALL
18414SDL_CreateThread(int (SDLCALL * fn) (void *),
18415                 const char *name, void *data)
18416#endif
18417{
18418    SDL_Thread *thread;
18419    thread_args *args;
18420    int ret;
18421
18422    thread = (SDL_Thread *) SDL_malloc(sizeof(*thread));
18423    if (thread == NULL) {
18424        SDL_OutOfMemory();
18425        return (NULL);
18426    }
18427    SDL_memset(thread, 0, (sizeof *thread));
18428    thread->status = -1;
18429
18430    if (name != NULL) {
18431        thread->name = SDL_strdup(name);
18432        if (thread->name == NULL) {
18433            SDL_OutOfMemory();
18434            SDL_free(thread);
18435            return (NULL);
18436        }
18437    }
18438
18439    args = (thread_args *) SDL_malloc(sizeof(*args));
18440    if (args == NULL) {
18441        SDL_OutOfMemory();
18442        SDL_free(thread->name);
18443        SDL_free(thread);
18444        return (NULL);
18445    }
18446    args->func = fn;
18447    args->data = data;
18448    args->info = thread;
18449    args->wait = SDL_CreateSemaphore(0);
18450    if (args->wait == NULL) {
18451        SDL_free(thread->name);
18452        SDL_free(thread);
18453        SDL_free(args);
18454        return (NULL);
18455    }
18456
18457    SDL_AddThread(thread);
18458
18459#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
18460    ret = SDL_SYS_CreateThread(thread, args, pfnBeginThread, pfnEndThread);
18461#else
18462    ret = SDL_SYS_CreateThread(thread, args);
18463#endif
18464    if (ret >= 0) {
18465
18466        SDL_SemWait(args->wait);
18467    } else {
18468
18469        SDL_DelThread(thread);
18470        SDL_free(thread->name);
18471        SDL_free(thread);
18472        thread = NULL;
18473    }
18474    SDL_DestroySemaphore(args->wait);
18475    SDL_free(args);
18476
18477    return (thread);
18478}
18479
18480SDL_threadID
18481SDL_GetThreadID(SDL_Thread * thread)
18482{
18483    SDL_threadID id;
18484
18485    if (thread) {
18486        id = thread->threadid;
18487    } else {
18488        id = SDL_ThreadID();
18489    }
18490    return id;
18491}
18492
18493const char *
18494SDL_GetThreadName(SDL_Thread * thread)
18495{
18496    return thread->name;
18497}
18498
18499int
18500SDL_SetThreadPriority(SDL_ThreadPriority priority)
18501{
18502    return SDL_SYS_SetThreadPriority(priority);
18503}
18504
18505void
18506SDL_WaitThread(SDL_Thread * thread, int *status)
18507{
18508    if (thread) {
18509        SDL_SYS_WaitThread(thread);
18510        if (status) {
18511            *status = thread->status;
18512        }
18513        SDL_DelThread(thread);
18514        SDL_free(thread->name);
18515        SDL_free(thread);
18516    }
18517}
18518#if SDL_THREAD_WINDOWS
18519
18520struct SDL_mutex
18521{
18522    CRITICAL_SECTION cs;
18523};
18524
18525SDL_mutex *
18526SDL_CreateMutex(void)
18527{
18528    SDL_mutex *mutex;
18529
18530    mutex = (SDL_mutex *) SDL_malloc(sizeof(*mutex));
18531    if (mutex) {
18532
18533        InitializeCriticalSectionAndSpinCount(&mutex->cs, 2000);
18534    } else {
18535        SDL_OutOfMemory();
18536    }
18537    return (mutex);
18538}
18539
18540void
18541SDL_DestroyMutex(SDL_mutex * mutex)
18542{
18543    if (mutex) {
18544        DeleteCriticalSection(&mutex->cs);
18545        SDL_free(mutex);
18546    }
18547}
18548
18549int
18550SDL_LockMutex(SDL_mutex * mutex)
18551{
18552    if (mutex == NULL) {
18553        return SDL_SetError("Passed a NULL mutex");
18554    }
18555
18556    EnterCriticalSection(&mutex->cs);
18557    return (0);
18558}
18559
18560int
18561SDL_TryLockMutex(SDL_mutex * mutex)
18562{
18563    int retval = 0;
18564    if (mutex == NULL) {
18565        return SDL_SetError("Passed a NULL mutex");
18566    }
18567
18568    if (TryEnterCriticalSection(&mutex->cs) == 0) {
18569        retval = SDL_MUTEX_TIMEDOUT;
18570    }
18571    return retval;
18572}
18573
18574int
18575SDL_UnlockMutex(SDL_mutex * mutex)
18576{
18577    if (mutex == NULL) {
18578        return SDL_SetError("Passed a NULL mutex");
18579    }
18580
18581    LeaveCriticalSection(&mutex->cs);
18582    return (0);
18583}
18584
18585#endif
18586#if SDL_THREAD_WINDOWS
18587
18588struct SDL_semaphore
18589{
18590    HANDLE id;
18591    LONG count;
18592};
18593
18594SDL_sem *
18595SDL_CreateSemaphore(Uint32 initial_value)
18596{
18597    SDL_sem *sem;
18598
18599    sem = (SDL_sem *) SDL_malloc(sizeof(*sem));
18600    if (sem) {
18601
18602        sem->id = CreateSemaphore(NULL, initial_value, 32 * 1024, NULL);
18603        sem->count = initial_value;
18604        if (!sem->id) {
18605            SDL_SetError("Couldn't create semaphore");
18606            SDL_free(sem);
18607            sem = NULL;
18608        }
18609    } else {
18610        SDL_OutOfMemory();
18611    }
18612    return (sem);
18613}
18614
18615void
18616SDL_DestroySemaphore(SDL_sem * sem)
18617{
18618    if (sem) {
18619        if (sem->id) {
18620            CloseHandle(sem->id);
18621            sem->id = 0;
18622        }
18623        SDL_free(sem);
18624    }
18625}
18626
18627int
18628SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
18629{
18630    int retval;
18631    DWORD dwMilliseconds;
18632
18633    if (!sem) {
18634        return SDL_SetError("Passed a NULL sem");
18635    }
18636
18637    if (timeout == SDL_MUTEX_MAXWAIT) {
18638        dwMilliseconds = INFINITE;
18639    } else {
18640        dwMilliseconds = (DWORD) timeout;
18641    }
18642    switch (WaitForSingleObject(sem->id, dwMilliseconds)) {
18643    case WAIT_OBJECT_0:
18644        InterlockedDecrement(&sem->count);
18645        retval = 0;
18646        break;
18647    case WAIT_TIMEOUT:
18648        retval = SDL_MUTEX_TIMEDOUT;
18649        break;
18650    default:
18651        retval = SDL_SetError("WaitForSingleObject() failed");
18652        break;
18653    }
18654    return retval;
18655}
18656
18657int
18658SDL_SemTryWait(SDL_sem * sem)
18659{
18660    return SDL_SemWaitTimeout(sem, 0);
18661}
18662
18663int
18664SDL_SemWait(SDL_sem * sem)
18665{
18666    return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT);
18667}
18668
18669Uint32
18670SDL_SemValue(SDL_sem * sem)
18671{
18672    if (!sem) {
18673        SDL_SetError("Passed a NULL sem");
18674        return 0;
18675    }
18676    return (Uint32)sem->count;
18677}
18678
18679int
18680SDL_SemPost(SDL_sem * sem)
18681{
18682    if (!sem) {
18683        return SDL_SetError("Passed a NULL sem");
18684    }
18685
18686    InterlockedIncrement(&sem->count);
18687    if (ReleaseSemaphore(sem->id, 1, NULL) == FALSE) {
18688        InterlockedDecrement(&sem->count);
18689        return SDL_SetError("ReleaseSemaphore() failed");
18690    }
18691    return 0;
18692}
18693
18694#endif
18695#if SDL_THREAD_WINDOWS
18696
18697#ifndef SDL_PASSED_BEGINTHREAD_ENDTHREAD
18698
18699#include <process.h>
18700
18701#if (defined(__MINGW32__) && (__GNUC__ < 4))
18702typedef unsigned long (__cdecl *pfnSDL_CurrentBeginThread) (void *, unsigned,
18703        unsigned (__stdcall *func)(void *), void *arg,
18704        unsigned, unsigned *threadID);
18705typedef void (__cdecl *pfnSDL_CurrentEndThread)(unsigned code);
18706
18707#elif defined(__WATCOMC__)
18708
18709#if __WATCOMC__ < 1240
18710#define __watcall
18711#endif
18712typedef unsigned long (__watcall * pfnSDL_CurrentBeginThread) (void *,
18713                                                               unsigned,
18714                                                               unsigned
18715                                                               (__stdcall *
18716                                                                func) (void
18717                                                                       *),
18718                                                               void *arg,
18719                                                               unsigned,
18720                                                               unsigned
18721                                                               *threadID);
18722typedef void (__watcall * pfnSDL_CurrentEndThread) (unsigned code);
18723
18724#else
18725typedef uintptr_t(__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned,
18726                                                        unsigned (__stdcall *
18727                                                                  func) (void
18728                                                                         *),
18729                                                        void *arg, unsigned,
18730                                                        unsigned *threadID);
18731typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code);
18732#endif
18733#endif
18734
18735typedef struct ThreadStartParms
18736{
18737    void *args;
18738    pfnSDL_CurrentEndThread pfnCurrentEndThread;
18739} tThreadStartParms, *pThreadStartParms;
18740
18741static DWORD
18742RunThread(void *data)
18743{
18744    pThreadStartParms pThreadParms = (pThreadStartParms) data;
18745    pfnSDL_CurrentEndThread pfnEndThread = pThreadParms->pfnCurrentEndThread;
18746    void *args = pThreadParms->args;
18747    SDL_free(pThreadParms);
18748    SDL_RunThread(args);
18749    if (pfnEndThread != NULL)
18750        pfnEndThread(0);
18751    return (0);
18752}
18753
18754static DWORD WINAPI
18755RunThreadViaCreateThread(LPVOID data)
18756{
18757  return RunThread(data);
18758}
18759
18760static unsigned __stdcall
18761RunThreadViaBeginThreadEx(void *data)
18762{
18763  return (unsigned) RunThread(data);
18764}
18765
18766#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
18767int
18768SDL_SYS_CreateThread(SDL_Thread * thread, void *args,
18769                     pfnSDL_CurrentBeginThread pfnBeginThread,
18770                     pfnSDL_CurrentEndThread pfnEndThread)
18771{
18772#else
18773int
18774SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
18775{
18776    pfnSDL_CurrentBeginThread pfnBeginThread = _beginthreadex;
18777    pfnSDL_CurrentEndThread pfnEndThread = _endthreadex;
18778#endif
18779    pThreadStartParms pThreadParms =
18780        (pThreadStartParms) SDL_malloc(sizeof(tThreadStartParms));
18781    if (!pThreadParms) {
18782        return SDL_OutOfMemory();
18783    }
18784
18785    pThreadParms->pfnCurrentEndThread = pfnEndThread;
18786
18787    pThreadParms->args = args;
18788
18789    if (pfnBeginThread) {
18790        unsigned threadid = 0;
18791        thread->handle = (SYS_ThreadHandle)
18792            ((size_t) pfnBeginThread(NULL, 0, RunThreadViaBeginThreadEx,
18793                                     pThreadParms, 0, &threadid));
18794    } else {
18795        DWORD threadid = 0;
18796        thread->handle = CreateThread(NULL, 0, RunThreadViaCreateThread,
18797                                      pThreadParms, 0, &threadid);
18798    }
18799    if (thread->handle == NULL) {
18800        return SDL_SetError("Not enough resources to create thread");
18801    }
18802    return 0;
18803}
18804
18805#ifdef _MSC_VER
18806#pragma pack(push,8)
18807typedef struct tagTHREADNAME_INFO
18808{
18809    DWORD dwType;
18810    LPCSTR szName;
18811    DWORD dwThreadID;
18812    DWORD dwFlags;
18813} THREADNAME_INFO;
18814#pragma pack(pop)
18815#endif
18816
18817void
18818SDL_SYS_SetupThread(const char *name)
18819{
18820    if (name != NULL) {
18821        #if 0
18822        #ifdef _MSC_VER
18823
18824        THREADNAME_INFO inf;
18825        inf.dwType = 0x1000;
18826        inf.szName = name;
18827        inf.dwThreadID = (DWORD) -1;
18828        inf.dwFlags = 0;
18829
18830        __try
18831        {
18832            RaiseException(0x406D1388, 0, sizeof(inf)/sizeof(DWORD), (DWORD*)&inf);
18833        }
18834        __except(EXCEPTION_CONTINUE_EXECUTION)
18835        {
18836
18837        }
18838        #endif
18839        #endif
18840    }
18841}
18842
18843SDL_threadID
18844SDL_ThreadID(void)
18845{
18846    return ((SDL_threadID) GetCurrentThreadId());
18847}
18848
18849int
18850SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
18851{
18852    int value;
18853
18854    if (priority == SDL_THREAD_PRIORITY_LOW) {
18855        value = THREAD_PRIORITY_LOWEST;
18856    } else if (priority == SDL_THREAD_PRIORITY_HIGH) {
18857        value = THREAD_PRIORITY_HIGHEST;
18858    } else {
18859        value = THREAD_PRIORITY_NORMAL;
18860    }
18861    if (!SetThreadPriority(GetCurrentThread(), value)) {
18862        return WIN_SetError("SetThreadPriority()");
18863    }
18864    return 0;
18865}
18866
18867void
18868SDL_SYS_WaitThread(SDL_Thread * thread)
18869{
18870    WaitForSingleObject(thread->handle, INFINITE);
18871    CloseHandle(thread->handle);
18872}
18873
18874#endif
18875#ifdef SDL_TIMER_UNIX
18876
18877#include <stdio.h>
18878#include <sys/time.h>
18879#include <unistd.h>
18880#include <errno.h>
18881
18882#if HAVE_NANOSLEEP || HAVE_CLOCK_GETTIME
18883#include <time.h>
18884#endif
18885#ifdef __APPLE__
18886#include <mach/mach_time.h>
18887#endif
18888
18889#if HAVE_CLOCK_GETTIME
18890static struct timespec start_ts;
18891#elif defined(__APPLE__)
18892static uint64_t start_mach;
18893mach_timebase_info_data_t mach_base_info;
18894#endif
18895static SDL_bool has_monotonic_time = SDL_FALSE;
18896static struct timeval start_tv;
18897static SDL_bool ticks_started = SDL_FALSE;
18898
18899void
18900SDL_TicksInit(void)
18901{
18902    if (ticks_started) {
18903        return;
18904    }
18905    ticks_started = SDL_TRUE;
18906
18907#if HAVE_CLOCK_GETTIME
18908    if (clock_gettime(CLOCK_MONOTONIC, &start_ts) == 0) {
18909        has_monotonic_time = SDL_TRUE;
18910    } else
18911#elif defined(__APPLE__)
18912    kern_return_t ret = mach_timebase_info(&mach_base_info);
18913    if (ret == 0) {
18914        has_monotonic_time = SDL_TRUE;
18915        start_mach = mach_absolute_time();
18916    } else
18917#endif
18918    {
18919        gettimeofday(&start_tv, NULL);
18920    }
18921}
18922
18923void
18924SDL_TicksQuit(void)
18925{
18926    ticks_started = SDL_FALSE;
18927}
18928
18929Uint32
18930SDL_GetTicks(void)
18931{
18932    Uint32 ticks;
18933    if (!ticks_started) {
18934        SDL_TicksInit();
18935    }
18936
18937    if (has_monotonic_time) {
18938#if HAVE_CLOCK_GETTIME
18939        struct timespec now;
18940        clock_gettime(CLOCK_MONOTONIC, &now);
18941        ticks = (now.tv_sec - start_ts.tv_sec) * 1000 + (now.tv_nsec -
18942                                                 start_ts.tv_nsec) / 1000000;
18943#elif defined(__APPLE__)
18944        uint64_t now = mach_absolute_time();
18945        ticks = (((now - start_mach) * mach_base_info.numer) / mach_base_info.denom) / 1000000;
18946#endif
18947    } else {
18948        struct timeval now;
18949
18950        gettimeofday(&now, NULL);
18951        ticks =
18952            (now.tv_sec - start_tv.tv_sec) * 1000 + (now.tv_usec -
18953                                                  start_tv.tv_usec) / 1000;
18954    }
18955    return (ticks);
18956}
18957
18958Uint64
18959SDL_GetPerformanceCounter(void)
18960{
18961    Uint64 ticks;
18962    if (!ticks_started) {
18963        SDL_TicksInit();
18964    }
18965
18966    if (has_monotonic_time) {
18967#if HAVE_CLOCK_GETTIME
18968        struct timespec now;
18969
18970        clock_gettime(CLOCK_MONOTONIC, &now);
18971        ticks = now.tv_sec;
18972        ticks *= 1000000000;
18973        ticks += now.tv_nsec;
18974#elif defined(__APPLE__)
18975        ticks = mach_absolute_time();
18976#endif
18977    } else {
18978        struct timeval now;
18979
18980        gettimeofday(&now, NULL);
18981        ticks = now.tv_sec;
18982        ticks *= 1000000;
18983        ticks += now.tv_usec;
18984    }
18985    return (ticks);
18986}
18987
18988Uint64
18989SDL_GetPerformanceFrequency(void)
18990{
18991    if (!ticks_started) {
18992        SDL_TicksInit();
18993    }
18994
18995    if (has_monotonic_time) {
18996#if HAVE_CLOCK_GETTIME
18997        return 1000000000;
18998#elif defined(__APPLE__)
18999        Uint64 freq = mach_base_info.denom;
19000        freq *= 1000000000;
19001        freq /= mach_base_info.numer;
19002        return freq;
19003#endif
19004    }
19005
19006    return 1000000;
19007}
19008
19009void
19010SDL_Delay(Uint32 ms)
19011{
19012    int was_error;
19013
19014#if HAVE_NANOSLEEP
19015    struct timespec elapsed, tv;
19016#else
19017    struct timeval tv;
19018    Uint32 then, now, elapsed;
19019#endif
19020
19021#if HAVE_NANOSLEEP
19022    elapsed.tv_sec = ms / 1000;
19023    elapsed.tv_nsec = (ms % 1000) * 1000000;
19024#else
19025    then = SDL_GetTicks();
19026#endif
19027    do {
19028        errno = 0;
19029
19030#if HAVE_NANOSLEEP
19031        tv.tv_sec = elapsed.tv_sec;
19032        tv.tv_nsec = elapsed.tv_nsec;
19033        was_error = nanosleep(&tv, &elapsed);
19034#else
19035
19036        now = SDL_GetTicks();
19037        elapsed = (now - then);
19038        then = now;
19039        if (elapsed >= ms) {
19040            break;
19041        }
19042        ms -= elapsed;
19043        tv.tv_sec = ms / 1000;
19044        tv.tv_usec = (ms % 1000) * 1000;
19045
19046        was_error = select(0, NULL, NULL, NULL, &tv);
19047#endif
19048    } while (was_error && (errno == EINTR));
19049}
19050
19051#endif
19052#ifdef SDL_TIMER_WINDOWS
19053
19054#include <mmsystem.h>
19055
19056static DWORD start;
19057static BOOL ticks_started = FALSE;
19058
19059#ifndef USE_GETTICKCOUNT
19060
19061static BOOL hires_timer_available;
19062
19063static LARGE_INTEGER hires_start_ticks;
19064
19065static LARGE_INTEGER hires_ticks_per_second;
19066
19067#ifndef __WINRT__
19068static void
19069timeSetPeriod(UINT uPeriod)
19070{
19071    static UINT timer_period = 0;
19072
19073    if (uPeriod != timer_period) {
19074        if (timer_period) {
19075            timeEndPeriod(timer_period);
19076        }
19077
19078        timer_period = uPeriod;
19079
19080        if (timer_period) {
19081            timeBeginPeriod(timer_period);
19082        }
19083    }
19084}
19085
19086static void
19087SDL_TimerResolutionChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
19088{
19089    UINT uPeriod;
19090
19091    if (hint && *hint) {
19092        uPeriod = SDL_atoi(hint);
19093    } else {
19094        uPeriod = 1;
19095    }
19096    if (uPeriod || oldValue != hint) {
19097        timeSetPeriod(uPeriod);
19098    }
19099}
19100#endif
19101
19102#endif
19103
19104void
19105SDL_TicksInit(void)
19106{
19107    if (ticks_started) {
19108        return;
19109    }
19110    ticks_started = SDL_TRUE;
19111
19112#ifdef USE_GETTICKCOUNT
19113    start = GetTickCount();
19114#else
19115
19116    if (QueryPerformanceFrequency(&hires_ticks_per_second) == TRUE) {
19117        hires_timer_available = TRUE;
19118        QueryPerformanceCounter(&hires_start_ticks);
19119    } else {
19120        hires_timer_available = FALSE;
19121#ifdef __WINRT__
19122        start = 0;
19123#else
19124        timeSetPeriod(1);
19125        start = timeGetTime();
19126
19127        SDL_AddHintCallback(SDL_HINT_TIMER_RESOLUTION,
19128                            SDL_TimerResolutionChanged, NULL);
19129#endif
19130    }
19131#endif
19132}
19133
19134void
19135SDL_TicksQuit(void)
19136{
19137#ifndef USE_GETTICKCOUNT
19138    if (!hires_timer_available) {
19139#ifndef __WINRT__
19140        SDL_DelHintCallback(SDL_HINT_TIMER_RESOLUTION,
19141                            SDL_TimerResolutionChanged, NULL);
19142
19143        timeSetPeriod(0);
19144#endif
19145    }
19146#endif
19147
19148    ticks_started = SDL_FALSE;
19149}
19150
19151Uint32
19152SDL_GetTicks(void)
19153{
19154    DWORD now;
19155#ifndef USE_GETTICKCOUNT
19156    LARGE_INTEGER hires_now;
19157#endif
19158
19159    if (!ticks_started) {
19160        SDL_TicksInit();
19161    }
19162
19163#ifdef USE_GETTICKCOUNT
19164    now = GetTickCount();
19165#else
19166    if (hires_timer_available) {
19167        QueryPerformanceCounter(&hires_now);
19168
19169        hires_now.QuadPart -= hires_start_ticks.QuadPart;
19170        hires_now.QuadPart *= 1000;
19171        hires_now.QuadPart /= hires_ticks_per_second.QuadPart;
19172
19173        return (DWORD) hires_now.QuadPart;
19174    } else {
19175#ifdef __WINRT__
19176        now = 0;
19177#else
19178        now = timeGetTime();
19179#endif
19180    }
19181#endif
19182
19183    return (now - start);
19184}
19185
19186Uint64
19187SDL_GetPerformanceCounter(void)
19188{
19189    LARGE_INTEGER counter;
19190
19191    if (!QueryPerformanceCounter(&counter)) {
19192        return SDL_GetTicks();
19193    }
19194    return counter.QuadPart;
19195}
19196
19197Uint64
19198SDL_GetPerformanceFrequency(void)
19199{
19200    LARGE_INTEGER frequency;
19201
19202    if (!QueryPerformanceFrequency(&frequency)) {
19203        return 1000;
19204    }
19205    return frequency.QuadPart;
19206}
19207
19208#ifdef __WINRT__
19209static void
19210Sleep(DWORD timeout)
19211{
19212    static HANDLE mutex = 0;
19213    if ( ! mutex )
19214    {
19215        mutex = CreateEventEx(0, 0, 0, EVENT_ALL_ACCESS);
19216    }
19217    WaitForSingleObjectEx(mutex, timeout, FALSE);
19218}
19219#endif
19220
19221void
19222SDL_Delay(Uint32 ms)
19223{
19224    Sleep(ms);
19225}
19226
19227#endif
19228
19229int SDL_ConvertAudio(SDL_AudioCVT* c) { return 0; }
19230int SDL_BuildAudioCVT(SDL_AudioCVT* c,SDL_AudioFormat sf, Uint8 sc, int sr, SDL_AudioFormat df, Uint8 dc, int dr) { return 0; }
19231void SDL_MixAudioFormat(Uint8 * dst, const Uint8 * src, SDL_AudioFormat format, Uint32 len, int volume) { }
19232static char SDL_Audio_Init_Done = 0;
19233Uint32 SDL_WasInit(Uint32 flags) { return (flags &16 ? SDL_Audio_Init_Done : 0); }
19234int SDL_InitSubSystem(Uint32 flags) { return (flags &16 ? (SDL_Audio_Init_Done = 1) : 0); }
19235#ifdef __WIN32__
19236char* WIN_StringToUTF8(const unsigned short* s) { int l = WideCharToMultiByte(CP_UTF8,0,(LPCWSTR)s,-1,0,0,0,0); char* b = (char*)malloc(l); WideCharToMultiByte(CP_UTF8, 0, (LPWSTR)s, -1, b, l, NULL, NULL); return b; }
19237unsigned short* WIN_UTF8ToString(const char* s) { int l = MultiByteToWideChar(CP_UTF8,0,s,-1,NULL,0); unsigned short* b = (unsigned short*)malloc(l*sizeof(short)); MultiByteToWideChar(CP_UTF8,0,s,-1,(LPWSTR)b,l); return b; }
19238#if (defined(_MSC_VER) && (!defined(WINAPI_FAMILY) || WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP))
19239#pragma comment (lib, "winmm.lib")
19240#endif
19241#endif