hedgewars/SDLh.pas
branchhedgeroid
changeset 15532 7030706266df
parent 15386 fcdb6e3a9d36
child 15929 128ace913837
equal deleted inserted replaced
7861:bc7b6aa5d67a 15532:7030706266df
     1 (*
     1 (*
     2  * Hedgewars, a free turn based strategy game
     2  * Hedgewars, a free turn based strategy game
     3  * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
     3  * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
     4  *
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     5  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation; version 2 of the License
     7  * the Free Software Foundation; version 2 of the License
     8  *
     8  *
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details.
    12  * GNU General Public License for more details.
    13  *
    13  *
    14  * You should have received a copy of the GNU General Public License
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program; if not, write to the Free Software
    15  * along with this program; if not, write to the Free Software
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    17  *)
    17  *)
    18 
    18 
    19 {$INCLUDE "options.inc"}
    19 {$INCLUDE "options.inc"}
    20 
    20 
    21 unit SDLh;
    21 unit SDLh;
    25     {$DEFINE UNIX}
    25     {$DEFINE UNIX}
    26 {$ENDIF}
    26 {$ENDIF}
    27 {$IFDEF FREEBSD}
    27 {$IFDEF FREEBSD}
    28     {$DEFINE UNIX}
    28     {$DEFINE UNIX}
    29 {$ENDIF}
    29 {$ENDIF}
       
    30 {$IFDEF OPENBSD}
       
    31     {$DEFINE UNIX}
       
    32 {$ENDIF}
    30 {$IFDEF DARWIN}
    33 {$IFDEF DARWIN}
    31     {$DEFINE UNIX}
    34     {$DEFINE UNIX}
    32 {$ENDIF}
    35 {$ENDIF}
    33 {$IFDEF HAIKU}
    36 {$IFDEF HAIKU}
    34     {$DEFINE UNIX}
    37     {$DEFINE UNIX}
    35 {$ENDIF}
    38 {$ENDIF}
    36 
    39 
    37 {$IFDEF UNIX}
    40 {$IFDEF UNIX}
    38     {$IFNDEF DARWIN}
       
    39         {$linklib c}
       
    40     {$ENDIF}
       
    41     {$IFDEF HAIKU}
    41     {$IFDEF HAIKU}
    42         {$linklib root}
    42         {$linklib root}
    43     {$ELSE}
    43     {$ELSE}
    44         {$IFNDEF ANDROID}
    44         {$IFNDEF ANDROID}
    45         {$linklib pthread}
    45             {$linklib pthread}
    46     {$ENDIF}
    46         {$ENDIF}
    47     {$ENDIF}
    47     {$ENDIF}
    48 {$ENDIF}
    48 {$ENDIF}
    49 
    49 
    50 {$IFDEF FPC}
    50 {$IFDEF FPC}
    51     {$PACKRECORDS C}
    51     {$PACKRECORDS C}
    54     type PByte = ^Byte;
    54     type PByte = ^Byte;
    55     type PInteger = ^Integer;
    55     type PInteger = ^Integer;
    56     type PLongInt = ^LongInt;
    56     type PLongInt = ^LongInt;
    57 {$ENDIF}
    57 {$ENDIF}
    58 
    58 
    59 {$IFDEF DARWIN}
       
    60     {$IFNDEF IPHONEOS}
       
    61         {$PASCALMAINNAME SDL_main}
       
    62         {$linkframework Cocoa}
       
    63         {$linkframework SDL}
       
    64         {$linkframework SDL_net}
       
    65         {$linkframework SDL_image}
       
    66         {$linkframework SDL_ttf}
       
    67         {$linkframework SDL_mixer}
       
    68         {$linkframework OpenGL}
       
    69     {$ENDIF}
       
    70 {$ENDIF}
       
    71 
       
    72 
       
    73 (*  SDL  *)
    59 (*  SDL  *)
    74 const
    60 const
    75 {$IFDEF WIN32}
    61 {$IFDEF WINDOWS}
    76     SDLLibName = 'SDL.dll';
    62     SDLLibName = {$IFDEF VCPKG_DEBUG}'SDL2d.dll'{$ELSE}'SDL2.dll'{$ENDIF};
    77     SDL_TTFLibName = 'SDL_ttf.dll';
    63     SDL_TTFLibName = 'SDL2_ttf.dll';
    78     SDL_MixerLibName = 'SDL_mixer.dll';
    64     SDL_MixerLibName = 'SDL2_mixer.dll';
    79     SDL_ImageLibName = 'SDL_image.dll';
    65     SDL_ImageLibName = 'SDL2_image.dll';
    80     SDL_NetLibName = 'SDL_net.dll';
    66     SDL_NetLibName = 'SDL2_net.dll';
    81 {$ELSE}
    67 {$ELSE}
    82     {$IFDEF DARWIN}
    68     SDLLibName = 'libSDL2';
    83     SDLLibName = 'SDL';
    69     SDL_TTFLibName = 'libSDL2_ttf';
    84     SDL_TTFLibName = 'SDL_ttf';
    70     SDL_MixerLibName = 'libSDL2_mixer';
    85     SDL_MixerLibName = 'SDL_mixer';
    71     SDL_ImageLibName = 'libSDL2_image';
    86     SDL_ImageLibName = 'SDL_image';
    72     SDL_NetLibName = 'libSDL2_net';
    87     SDL_NetLibName = 'SDL_net';
       
    88     {$ELSE}
       
    89     SDLLibName = 'libSDL.so';
       
    90     SDL_TTFLibName = 'libSDL_ttf.so';
       
    91     SDL_MixerLibName = 'libSDL_mixer.so';
       
    92     SDL_ImageLibName = 'libSDL_image.so';
       
    93     SDL_NetLibName = 'libSDL_net.so';
       
    94     {$ENDIF}
       
    95 {$ENDIF}
    73 {$ENDIF}
    96 
    74 
    97 /////////////////////////////////////////////////////////////////
    75 /////////////////////////////////////////////////////////////////
    98 /////////////////////  CONSTANT DEFINITIONS /////////////////////
    76 /////////////////////  CONSTANT DEFINITIONS /////////////////////
    99 /////////////////////////////////////////////////////////////////
    77 /////////////////////////////////////////////////////////////////
   100 
    78 
       
    79     SDL_FALSE = 0;
       
    80     SDL_TRUE = 1;
       
    81 
   101     // SDL_Init() flags
    82     // SDL_Init() flags
   102     SDL_INIT_TIMER       = $00000001;
    83     SDL_INIT_TIMER          = $00000001;
   103     SDL_INIT_AUDIO       = $00000010;
    84     SDL_INIT_AUDIO          = $00000010;
   104     SDL_INIT_VIDEO       = $00000020;
    85     SDL_INIT_VIDEO          = $00000020; // implies SDL_INIT_EVENTS (sdl2)
   105     SDL_INIT_JOYSTICK    = $00000200;
    86     SDL_INIT_JOYSTICK       = $00000200; // implies SDL_INIT_EVENTS (sdl2)
   106 {$IFDEF SDL13}
    87     SDL_INIT_HAPTIC         = $00001000;
   107     SDL_INIT_HAPTIC      = $00001000;
    88     SDL_INIT_GAMECONTROLLER = $00002000; // implies SDL_INIT_JOYSTICK
   108 {$ELSE}
    89     SDL_INIT_EVENTS         = $00004000;
   109     SDL_INIT_CDROM       = $00000100;
    90     SDL_INIT_NOPARACHUTE    = $00100000;
   110     SDL_INIT_EVENTTHREAD = $01000000;
    91     //SDL_INIT_EVERYTHING                // unsafe, init subsystems one at a time
   111 {$ENDIF}
    92 
   112     SDL_INIT_NOPARACHUTE = $00100000;
    93     SDL_ALLEVENTS        = $FFFFFFFF;    // dummy event type to prevent stack corruption
   113     SDL_INIT_EVERYTHING  = $0000FFFF;
       
   114 
       
   115     SDL_ALLEVENTS        = $FFFFFFFF;
       
   116     SDL_APPINPUTFOCUS    = $02;
    94     SDL_APPINPUTFOCUS    = $02;
       
    95 
       
    96     // (some) audio formats from SDL_audio.h
       
    97     AUDIO_S16LSB         = $8010; // Signed 16-bit samples, in little-endian byte order
       
    98     AUDIO_S16MSB         = $9010; // Signed 16-bit samples, in big-endian byte order
       
    99     AUDIO_S16SYS         = {$IFDEF ENDIAN_LITTLE}AUDIO_S16LSB{$ELSE}AUDIO_S16MSB{$ENDIF};
       
   100 
       
   101     // default audio format from SDL_mixer.h
       
   102     //MIX_DEFAULT_FORMAT   = AUDIO_S16SYS;
       
   103     MIX_DEFAULT_FORMAT   = {$IFDEF ENDIAN_LITTLE}AUDIO_S16LSB{$ELSE}AUDIO_S16MSB{$ENDIF};
   117 
   104 
   118     SDL_BUTTON_LEFT      = 1;
   105     SDL_BUTTON_LEFT      = 1;
   119     SDL_BUTTON_MIDDLE    = 2;
   106     SDL_BUTTON_MIDDLE    = 2;
   120     SDL_BUTTON_RIGHT     = 3;
   107     SDL_BUTTON_RIGHT     = 3;
   121     SDL_BUTTON_WHEELUP   = 4;
   108     SDL_BUTTON_X1        = 4;
   122     SDL_BUTTON_WHEELDOWN = 5;
   109     SDL_BUTTON_X2        = 5;
   123 
   110 
   124 {$IFDEF SDL13}
   111     // SDL_ShowCursor consts
       
   112     SDL_QUERY = -1;
       
   113     SDL_DISABLE = 0;
       
   114     SDL_ENABLE = 1;
       
   115 
       
   116     SDL_TEXTEDITINGEVENT_TEXT_SIZE = 32;
       
   117     SDL_TEXTINPUTEVENT_TEXT_SIZE   = 32;
       
   118 
   125     // SDL_Event types
   119     // SDL_Event types
   126     SDL_FIRSTEVENT        = 0;
   120     // pascal does not support unions as is, so we list here every possible event
       
   121     // and later associate a struct type each
       
   122     SDL_FIRSTEVENT        = 0;              // type
       
   123     SDL_COMMONDEVENT      = 1;              // type and timestamp
   127     SDL_QUITEV            = $100;
   124     SDL_QUITEV            = $100;
       
   125     SDL_APP_TERMINATING   = $101;
       
   126     SDL_APP_LOWMEMORY     = $102;
       
   127     SDL_APP_WILLENTERBACKGROUND = $103;
       
   128     SDL_APP_DIDENTERBACKGROUND = $104;
       
   129     SDL_APP_WILLENTERFOREGROUND = $105;
       
   130     SDL_APP_DIDENTERFOREGROUND = $106;
   128     SDL_WINDOWEVENT       = $200;
   131     SDL_WINDOWEVENT       = $200;
   129     SDL_SYSWMEVENT        = $201;
   132     SDL_SYSWMEVENT        = $201;
   130     SDL_KEYDOWN           = $300;
   133     SDL_KEYDOWN           = $300;
   131     SDL_KEYUP             = $301;
   134     SDL_KEYUP             = $301;
   132     SDL_TEXTEDITING       = $302;
   135     SDL_TEXTEDITING       = $302;
   133     SDL_TEXTINPUT         = $303;
   136     SDL_TEXTINPUT         = $303;
   134     SDL_MOUSEMOTION       = $400;
   137     SDL_MOUSEMOTION       = $400;
   135     SDL_MOUSEBUTTONDOWN   = $401;
   138     SDL_MOUSEBUTTONDOWN   = $401;
   136     SDL_MOUSEBUTTONUP     = $402;
   139     SDL_MOUSEBUTTONUP     = $402;
   137     SDL_MOUSEWHEEL        = $403;
   140     SDL_MOUSEWHEEL        = $403;
   138     SDL_INPUTMOTION       = $500;
       
   139     SDL_INPUTBUTTONDOWN   = $501;
       
   140     SDL_INPUTBUTTONUP     = $502;
       
   141     SDL_INPUTWHEEL        = $503;
       
   142     SDL_INPUTPROXIMITYIN  = $504;
       
   143     SDL_INPUTPROXIMITYOUT = $505;
       
   144     SDL_JOYAXISMOTION     = $600;
   141     SDL_JOYAXISMOTION     = $600;
   145     SDL_JOYBALLMOTION     = $601;
   142     SDL_JOYBALLMOTION     = $601;
   146     SDL_JOYHATMOTION      = $602;
   143     SDL_JOYHATMOTION      = $602;
   147     SDL_JOYBUTTONDOWN     = $603;
   144     SDL_JOYBUTTONDOWN     = $603;
   148     SDL_JOYBUTTONUP       = $604;
   145     SDL_JOYBUTTONUP       = $604;
       
   146     SDL_JOYDEVICEADDED    = $605;
       
   147     SDL_JOYDEVICEREMOVED  = $606;
       
   148     SDL_CONTROLLERAXISMOTION = $650;
       
   149     SDL_CONTROLLERBUTTONDOWN = $651;
       
   150     SDL_CONTROLLERBUTTONUP = $652;
       
   151     SDL_CONTROLLERDEVICEADDED = $653;
       
   152     SDL_CONTROLLERDEVICEREMOVED = $654;
       
   153     SDL_CONTROLLERDEVICEREMAPPED = $655;
   149     SDL_FINGERDOWN        = $700;
   154     SDL_FINGERDOWN        = $700;
   150     SDL_FINGERUP          = $701;
   155     SDL_FINGERUP          = $701;
   151     SDL_FINGERMOTION      = $702;
   156     SDL_FINGERMOTION      = $702;
   152     SDL_TOUCHBUTTONDOWN   = $703;
       
   153     SDL_TOUCHBUTTONUP     = $704;
       
   154     SDL_DOLLARGESTURE     = $800;
   157     SDL_DOLLARGESTURE     = $800;
   155     SDL_DOLLARRECORD      = $801;
   158     SDL_DOLLARRECORD      = $801;
   156     SDL_MULTIGESTURE      = $802;
   159     SDL_MULTIGESTURE      = $802;
   157     SDL_CLIPBOARDUPDATE   = $900;
   160     SDL_CLIPBOARDUPDATE   = $900;
   158     SDL_DROPFILE          = $1000;
   161     SDL_DROPFILE          = $1000;
   159     SDL_USEREVENT         = $8000;
   162     SDL_USEREVENT         = $8000;
   160     SDL_LASTEVENT         = $FFFF;
   163     SDL_LASTEVENT         = $FFFF;
   161     // no compatibility events $7000
       
   162 
   164 
   163     // SDL_Surface flags
   165     // SDL_Surface flags
   164     SDL_SWSURFACE   = $00000000;  //*< Not used */
   166     SDL_SWSURFACE   = $00000000;  //*< Not used */
   165     SDL_PREALLOC    = $00000001;  //*< Surface uses preallocated memory */
   167     SDL_PREALLOC    = $00000001;  //*< Surface uses preallocated memory */
   166     SDL_RLEACCEL    = $00000002;  //*< Surface is RLE encoded */
   168     SDL_RLEACCEL    = $00000002;  //*< Surface is RLE encoded */
   167     SDL_DONTFREE    = $00000004;  //*< Surface is referenced internally */
   169     SDL_DONTFREE    = $00000004;  //*< Surface is referenced internally */
   168     SDL_SRCALPHA    = $00010000;
   170     SDL_SRCCOLORKEY = $00020000;  // compatibility only
   169     SDL_SRCCOLORKEY = $00020000;
   171 
   170     SDL_ANYFORMAT   = $00100000;
   172     // SDL_RendererFlags
   171     SDL_HWPALETTE   = $00200000;
       
   172     SDL_DOUBLEBUF   = $00400000;
       
   173     SDL_FULLSCREEN  = $00800000;
       
   174     SDL_RESIZABLE   = $01000000;
       
   175     SDL_NOFRAME     = $02000000;
       
   176     SDL_OPENGL      = $04000000;
       
   177     SDL_HWSURFACE   = $08000001;  //*< Not used */
       
   178     SDL_ASYNCBLIT   = $08000000;  //*< Not used */
       
   179     SDL_RLEACCELOK  = $08000000;  //*< Not used */
       
   180     SDL_HWACCEL     = $08000000;  //*< Not used */
       
   181 
       
   182     // SDL_Renderer flags
       
   183     SDL_RENDERER_SOFTWARE     = $00000001;     //*< The renderer is a software fallback */
   173     SDL_RENDERER_SOFTWARE     = $00000001;     //*< The renderer is a software fallback */
   184     SDL_RENDERER_ACCELERATED  = $00000002;     //*< The renderer uses hardware acceleration */
   174     SDL_RENDERER_ACCELERATED  = $00000002;     //*< The renderer uses hardware acceleration */
   185     SDL_RENDERER_PRESENTVSYNC = $00000004;
   175     SDL_RENDERER_PRESENTVSYNC = $00000004;     //*< Present is synchronized with the refresh rate */
   186 
   176     SDL_RENDERER_TARGETTEXTURE = $00000008;    //*< The renderer supports rendering to texture */
   187     // SDL_WindowFlags (enum)
   177 
       
   178     // SDL_WindowFlags
   188     SDL_WINDOW_FULLSCREEN    = $00000001;      //*< fullscreen window, implies borderless */
   179     SDL_WINDOW_FULLSCREEN    = $00000001;      //*< fullscreen window, implies borderless */
   189     SDL_WINDOW_OPENGL        = $00000002;      //*< window usable with OpenGL context */
   180     SDL_WINDOW_OPENGL        = $00000002;      //*< window usable with OpenGL context */
   190     SDL_WINDOW_SHOWN         = $00000004;      //*< window is visible */
   181     SDL_WINDOW_SHOWN         = $00000004;      //*< window is visible */
   191     SDL_WINDOW_HIDDEN        = $00000008;      //*< window is not visible */
   182     SDL_WINDOW_HIDDEN        = $00000008;      //*< window is not visible */
   192     SDL_WINDOW_BORDERLESS    = $00000010;      //*< no window decoration */
   183     SDL_WINDOW_BORDERLESS    = $00000010;      //*< no window decoration */
   194     SDL_WINDOW_MINIMIZED     = $00000040;      //*< window is minimized */
   185     SDL_WINDOW_MINIMIZED     = $00000040;      //*< window is minimized */
   195     SDL_WINDOW_MAXIMIZED     = $00000080;      //*< window is maximized */
   186     SDL_WINDOW_MAXIMIZED     = $00000080;      //*< window is maximized */
   196     SDL_WINDOW_INPUT_GRABBED = $00000100;      //*< window has grabbed input focus */
   187     SDL_WINDOW_INPUT_GRABBED = $00000100;      //*< window has grabbed input focus */
   197     SDL_WINDOW_INPUT_FOCUS   = $00000200;      //*< window has input focus */
   188     SDL_WINDOW_INPUT_FOCUS   = $00000200;      //*< window has input focus */
   198     SDL_WINDOW_MOUSE_FOCUS   = $00000400;      //*< window has mouse focus */
   189     SDL_WINDOW_MOUSE_FOCUS   = $00000400;      //*< window has mouse focus */
       
   190     SDL_WINDOW_FULLSCREEN_DESKTOP = $00001001; //*< fullscreen as maximed window */
   199     SDL_WINDOW_FOREIGN       = $00000800;      //*< window not created by SDL */
   191     SDL_WINDOW_FOREIGN       = $00000800;      //*< window not created by SDL */
   200 
   192 
   201     SDL_WINDOWPOS_CENTERED_MASK = $2FFF0000;
   193     SDL_WINDOWPOS_CENTERED_MASK = $2FFF0000;
   202 
   194 
   203     // SDL_WindowEventID (enum)
   195     // SDL_WindowEventID
   204     SDL_WINDOWEVENT_NONE         = 0;    //*< Never used
   196     SDL_WINDOWEVENT_NONE         = 0;    //*< Never used
   205     SDL_WINDOWEVENT_SHOWN        = 1;    //*< Window has been shown
   197     SDL_WINDOWEVENT_SHOWN        = 1;    //*< Window has been shown
   206     SDL_WINDOWEVENT_HIDDEN       = 2;    //*< Window has been hidden
   198     SDL_WINDOWEVENT_HIDDEN       = 2;    //*< Window has been hidden
   207     SDL_WINDOWEVENT_EXPOSED      = 3;    //*< Window has been exposed and should be redrawn
   199     SDL_WINDOWEVENT_EXPOSED      = 3;    //*< Window has been exposed and should be redrawn
   208     SDL_WINDOWEVENT_MOVED        = 4;    //*< Window has been moved to data1, data2
   200     SDL_WINDOWEVENT_MOVED        = 4;    //*< Window has been moved to data1, data2
   214     SDL_WINDOWEVENT_ENTER        = 10;   //*< Window has gained mouse focus
   206     SDL_WINDOWEVENT_ENTER        = 10;   //*< Window has gained mouse focus
   215     SDL_WINDOWEVENT_LEAVE        = 11;   //*< Window has lost mouse focus
   207     SDL_WINDOWEVENT_LEAVE        = 11;   //*< Window has lost mouse focus
   216     SDL_WINDOWEVENT_FOCUS_GAINED = 12;   //*< Window has gained keyboard focus
   208     SDL_WINDOWEVENT_FOCUS_GAINED = 12;   //*< Window has gained keyboard focus
   217     SDL_WINDOWEVENT_FOCUS_LOST   = 13;   //*< Window has lost keyboard focus
   209     SDL_WINDOWEVENT_FOCUS_LOST   = 13;   //*< Window has lost keyboard focus
   218     SDL_WINDOWEVENT_CLOSE        = 14;   //*< The window manager requests that the window be closed */
   210     SDL_WINDOWEVENT_CLOSE        = 14;   //*< The window manager requests that the window be closed */
   219 {$ELSE}
       
   220     // SDL_Event types
       
   221     SDL_NOEVENT         = 0;
       
   222     SDL_ACTIVEEVENT     = 1;
       
   223     SDL_KEYDOWN         = 2;
       
   224     SDL_KEYUP           = 3;
       
   225     SDL_MOUSEMOTION     = 4;
       
   226     SDL_MOUSEBUTTONDOWN = 5;
       
   227     SDL_MOUSEBUTTONUP   = 6;
       
   228     SDL_JOYAXISMOTION   = 7;
       
   229     SDL_JOYBALLMOTION   = 8;
       
   230     SDL_JOYHATMOTION    = 9;
       
   231     SDL_JOYBUTTONDOWN   = 10;
       
   232     SDL_JOYBUTTONUP     = 11;
       
   233     SDL_QUITEV          = 12;
       
   234     SDL_VIDEORESIZE     = 16;
       
   235 
       
   236     // SDL_Surface flags
       
   237     SDL_SWSURFACE   = $00000000;
       
   238     SDL_HWSURFACE   = $00000001;
       
   239     SDL_OPENGL      = $00000002;
       
   240     SDL_ASYNCBLIT   = $00000004;
       
   241     SDL_RESIZABLE   = $00000010;
       
   242     SDL_NOFRAME     = $00000020;
       
   243     SDL_HWACCEL     = $00000100;
       
   244     SDL_SRCCOLORKEY = $00001000;
       
   245     SDL_RLEACCEL    = $00004000;
       
   246     SDL_SRCALPHA    = $00010000;
       
   247     SDL_ANYFORMAT   = $00100000;
       
   248     SDL_HWPALETTE   = $20000000;
       
   249     SDL_DOUBLEBUF   = $40000000;
       
   250     SDL_FULLSCREEN  = $80000000;
       
   251 {$ENDIF}
       
   252 
   211 
   253 {$IFDEF ENDIAN_LITTLE}
   212 {$IFDEF ENDIAN_LITTLE}
   254     RMask = $000000FF;
   213     RMask = $000000FF;
   255     GMask = $0000FF00;
   214     GMask = $0000FF00;
   256     BMask = $00FF0000;
   215     BMask = $00FF0000;
   257     AMask = $FF000000;
   216     AMask = $FF000000;
   258     RShift = 0;
   217     RShift = 0;
   259     GShift = 8;
   218     GShift = 8;
   260     BShift = 16;
   219     BShift = 16;
   261     AShift = 24;
   220     AShift = 24;
       
   221     AByteIndex = 3;
   262 {$ELSE}
   222 {$ELSE}
   263     RMask = $FF000000;
   223     RMask = $FF000000;
   264     GMask = $00FF0000;
   224     GMask = $00FF0000;
   265     BMask = $0000FF00;
   225     BMask = $0000FF00;
   266     AMask = $000000FF;
   226     AMask = $000000FF;
   267     RShift = 24;
   227     RShift = 24;
   268     GShift = 16;
   228     GShift = 16;
   269     BShift = 8;
   229     BShift = 8;
   270     AShift = 0;
   230     AShift = 0;
       
   231     AByteIndex = 0;
   271 {$ENDIF}
   232 {$ENDIF}
   272 
   233 
   273     KMOD_NONE   = $0000;
   234     KMOD_NONE   = $0000;
   274     KMOD_LSHIFT = $0001;
   235     KMOD_LSHIFT = $0001;
   275     KMOD_RSHIFT = $0002;
   236     KMOD_RSHIFT = $0002;
   282     KMOD_NUM    = $1000;
   243     KMOD_NUM    = $1000;
   283     KMOD_CAPS   = $2000;
   244     KMOD_CAPS   = $2000;
   284     KMOD_MODE   = $4000;
   245     KMOD_MODE   = $4000;
   285 
   246 
   286     {* SDL_mixer *}
   247     {* SDL_mixer *}
   287     MIX_MAX_VOLUME = 128;
   248     MIX_MAX_VOLUME      = 128;
   288     MIX_INIT_FLAC  = $00000001;
   249     MIX_INIT_FLAC       = $00000001;
   289     MIX_INIT_MOD   = $00000002;
   250     MIX_INIT_MOD        = $00000002;
   290     MIX_INIT_MP3   = $00000004;
   251     MIX_INIT_MODPLUG    = $00000004;
   291     MIX_INIT_OGG   = $00000008;
   252     MIX_INIT_MP3        = $00000008;
       
   253     MIX_INIT_OGG        = $00000010;
       
   254     MIX_INIT_FLUIDSYNTH = $00000020;
       
   255     MIX_INIT_OPUS       = $00000040;
   292 
   256 
   293     {* SDL_TTF *}
   257     {* SDL_TTF *}
   294     TTF_STYLE_NORMAL = 0;
   258     TTF_STYLE_NORMAL = 0;
   295     TTF_STYLE_BOLD   = 1;
   259     TTF_STYLE_BOLD   = 1;
   296     TTF_STYLE_ITALIC = 2;
   260     TTF_STYLE_ITALIC = 2;
   309     {* SDL_image *}
   273     {* SDL_image *}
   310     IMG_INIT_JPG = $00000001;
   274     IMG_INIT_JPG = $00000001;
   311     IMG_INIT_PNG = $00000002;
   275     IMG_INIT_PNG = $00000002;
   312     IMG_INIT_TIF = $00000004;
   276     IMG_INIT_TIF = $00000004;
   313 
   277 
       
   278     {* SDL_keycode *}
       
   279     SDLK_UNKNOWN = 0;
       
   280     SDLK_BACKSPACE = 8;
       
   281     SDLK_RETURN    = 13;
       
   282     SDLK_ESCAPE    = 27;
       
   283     SDLK_a         = 97;
       
   284     SDLK_c         = 99;
       
   285     SDLK_q         = 113;
       
   286     SDLK_v         = 118;
       
   287     SDLK_w         = 119;
       
   288     SDLK_x         = 120;
       
   289     SDLK_DELETE    = 127;
       
   290     SDLK_KP_ENTER  = 271;
       
   291     SDLK_UP        = 273;
       
   292     SDLK_DOWN      = 274;
       
   293     SDLK_RIGHT     = 275;
       
   294     SDLK_LEFT      = 276;
       
   295     SDLK_HOME      = 278;
       
   296     SDLK_END       = 279;
       
   297     SDLK_PAGEUP    = 280;
       
   298     SDLK_PAGEDOWN  = 281;
       
   299 
       
   300     // special keycodes (for modifier keys etc. will have this bit set)
       
   301     SDLK_SCANCODE_MASK = (1 shl 30);
       
   302 
       
   303     SDL_SCANCODE_UNKNOWN = 0;
       
   304     SDL_SCANCODE_A = 4;
       
   305     SDL_SCANCODE_B = 5;
       
   306     SDL_SCANCODE_C = 6;
       
   307     SDL_SCANCODE_D = 7;
       
   308     SDL_SCANCODE_E = 8;
       
   309     SDL_SCANCODE_F = 9;
       
   310     SDL_SCANCODE_G = 10;
       
   311     SDL_SCANCODE_H = 11;
       
   312     SDL_SCANCODE_I = 12;
       
   313     SDL_SCANCODE_J = 13;
       
   314     SDL_SCANCODE_K = 14;
       
   315     SDL_SCANCODE_L = 15;
       
   316     SDL_SCANCODE_M = 16;
       
   317     SDL_SCANCODE_N = 17;
       
   318     SDL_SCANCODE_O = 18;
       
   319     SDL_SCANCODE_P = 19;
       
   320     SDL_SCANCODE_Q = 20;
       
   321     SDL_SCANCODE_R = 21;
       
   322     SDL_SCANCODE_S = 22;
       
   323     SDL_SCANCODE_T = 23;
       
   324     SDL_SCANCODE_U = 24;
       
   325     SDL_SCANCODE_V = 25;
       
   326     SDL_SCANCODE_W = 26;
       
   327     SDL_SCANCODE_X = 27;
       
   328     SDL_SCANCODE_Y = 28;
       
   329     SDL_SCANCODE_Z = 29;
       
   330     SDL_SCANCODE_1 = 30;
       
   331     SDL_SCANCODE_2 = 31;
       
   332     SDL_SCANCODE_3 = 32;
       
   333     SDL_SCANCODE_4 = 33;
       
   334     SDL_SCANCODE_5 = 34;
       
   335     SDL_SCANCODE_6 = 35;
       
   336     SDL_SCANCODE_7 = 36;
       
   337     SDL_SCANCODE_8 = 37;
       
   338     SDL_SCANCODE_9 = 38;
       
   339     SDL_SCANCODE_0 = 39;
       
   340     SDL_SCANCODE_RETURN = 40;
       
   341     SDL_SCANCODE_ESCAPE = 41;
       
   342     SDL_SCANCODE_BACKSPACE = 42;
       
   343     SDL_SCANCODE_TAB = 43;
       
   344     SDL_SCANCODE_SPACE = 44;
       
   345     SDL_SCANCODE_MINUS = 45;
       
   346     SDL_SCANCODE_EQUALS = 46;
       
   347     SDL_SCANCODE_LEFTBRACKET = 47;
       
   348     SDL_SCANCODE_RIGHTBRACKET = 48;
       
   349     SDL_SCANCODE_BACKSLASH = 49;
       
   350     SDL_SCANCODE_NONUSHASH = 50;
       
   351     SDL_SCANCODE_SEMICOLON = 51;
       
   352     SDL_SCANCODE_APOSTROPHE = 52;
       
   353     SDL_SCANCODE_GRAVE = 53;
       
   354     SDL_SCANCODE_COMMA = 54;
       
   355     SDL_SCANCODE_PERIOD = 55;
       
   356     SDL_SCANCODE_SLASH = 56;
       
   357     SDL_SCANCODE_CAPSLOCK = 57;
       
   358     SDL_SCANCODE_F1 = 58;
       
   359     SDL_SCANCODE_F2 = 59;
       
   360     SDL_SCANCODE_F3 = 60;
       
   361     SDL_SCANCODE_F4 = 61;
       
   362     SDL_SCANCODE_F5 = 62;
       
   363     SDL_SCANCODE_F6 = 63;
       
   364     SDL_SCANCODE_F7 = 64;
       
   365     SDL_SCANCODE_F8 = 65;
       
   366     SDL_SCANCODE_F9 = 66;
       
   367     SDL_SCANCODE_F10 = 67;
       
   368     SDL_SCANCODE_F11 = 68;
       
   369     SDL_SCANCODE_F12 = 69;
       
   370     SDL_SCANCODE_PRINTSCREEN = 70;
       
   371     SDL_SCANCODE_SCROLLLOCK = 71;
       
   372     SDL_SCANCODE_PAUSE = 72;
       
   373     SDL_SCANCODE_INSERT = 73;
       
   374     SDL_SCANCODE_HOME = 74;
       
   375     SDL_SCANCODE_PAGEUP = 75;
       
   376     SDL_SCANCODE_DELETE = 76;
       
   377     SDL_SCANCODE_END = 77;
       
   378     SDL_SCANCODE_PAGEDOWN = 78;
       
   379     SDL_SCANCODE_RIGHT = 79;
       
   380     SDL_SCANCODE_LEFT = 80;
       
   381     SDL_SCANCODE_DOWN = 81;
       
   382     SDL_SCANCODE_UP = 82;
       
   383     SDL_SCANCODE_NUMLOCKCLEAR = 83;
       
   384     SDL_SCANCODE_KP_DIVIDE = 84;
       
   385     SDL_SCANCODE_KP_MULTIPLY = 85;
       
   386     SDL_SCANCODE_KP_MINUS = 86;
       
   387     SDL_SCANCODE_KP_PLUS = 87;
       
   388     SDL_SCANCODE_KP_ENTER = 88;
       
   389     SDL_SCANCODE_KP_1 = 89;
       
   390     SDL_SCANCODE_KP_2 = 90;
       
   391     SDL_SCANCODE_KP_3 = 91;
       
   392     SDL_SCANCODE_KP_4 = 92;
       
   393     SDL_SCANCODE_KP_5 = 93;
       
   394     SDL_SCANCODE_KP_6 = 94;
       
   395     SDL_SCANCODE_KP_7 = 95;
       
   396     SDL_SCANCODE_KP_8 = 96;
       
   397     SDL_SCANCODE_KP_9 = 97;
       
   398     SDL_SCANCODE_KP_0 = 98;
       
   399     SDL_SCANCODE_KP_PERIOD = 99;
       
   400     SDL_SCANCODE_NONUSBACKSLASH = 100;
       
   401     SDL_SCANCODE_APPLICATION = 101;
       
   402     SDL_SCANCODE_POWER = 102;
       
   403     SDL_SCANCODE_KP_EQUALS = 103;
       
   404     SDL_SCANCODE_F13 = 104;
       
   405     SDL_SCANCODE_F14 = 105;
       
   406     SDL_SCANCODE_F15 = 106;
       
   407     SDL_SCANCODE_F16 = 107;
       
   408     SDL_SCANCODE_F17 = 108;
       
   409     SDL_SCANCODE_F18 = 109;
       
   410     SDL_SCANCODE_F19 = 110;
       
   411     SDL_SCANCODE_F20 = 111;
       
   412     SDL_SCANCODE_F21 = 112;
       
   413     SDL_SCANCODE_F22 = 113;
       
   414     SDL_SCANCODE_F23 = 114;
       
   415     SDL_SCANCODE_F24 = 115;
       
   416     SDL_SCANCODE_EXECUTE = 116;
       
   417     SDL_SCANCODE_HELP = 117;
       
   418     SDL_SCANCODE_MENU = 118;
       
   419     SDL_SCANCODE_SELECT = 119;
       
   420     SDL_SCANCODE_STOP = 120;
       
   421     SDL_SCANCODE_AGAIN = 121;
       
   422     SDL_SCANCODE_UNDO = 122;
       
   423     SDL_SCANCODE_CUT = 123;
       
   424     SDL_SCANCODE_COPY = 124;
       
   425     SDL_SCANCODE_PASTE = 125;
       
   426     SDL_SCANCODE_FIND = 126;
       
   427     SDL_SCANCODE_MUTE = 127;
       
   428     SDL_SCANCODE_VOLUMEUP = 128;
       
   429     SDL_SCANCODE_VOLUMEDOWN = 129;
       
   430     SDL_SCANCODE_KP_COMMA = 133;
       
   431     SDL_SCANCODE_KP_EQUALSAS400 = 134;
       
   432     SDL_SCANCODE_INTERNATIONAL1 = 135;
       
   433     SDL_SCANCODE_INTERNATIONAL2 = 136;
       
   434     SDL_SCANCODE_INTERNATIONAL3 = 137;
       
   435     SDL_SCANCODE_INTERNATIONAL4 = 138;
       
   436     SDL_SCANCODE_INTERNATIONAL5 = 139;
       
   437     SDL_SCANCODE_INTERNATIONAL6 = 140;
       
   438     SDL_SCANCODE_INTERNATIONAL7 = 141;
       
   439     SDL_SCANCODE_INTERNATIONAL8 = 142;
       
   440     SDL_SCANCODE_INTERNATIONAL9 = 143;
       
   441     SDL_SCANCODE_LANG1 = 144; (*< Hangul/English toggle *)
       
   442     SDL_SCANCODE_LANG2 = 145; (*< Hanja conversion *)
       
   443     SDL_SCANCODE_LANG3 = 146; (*< Katakana *)
       
   444     SDL_SCANCODE_LANG4 = 147; (*< Hiragana *)
       
   445     SDL_SCANCODE_LANG5 = 148; (*< Zenkaku/Hankaku *)
       
   446     SDL_SCANCODE_LANG6 = 149; (*< reserved *)
       
   447     SDL_SCANCODE_LANG7 = 150; (*< reserved *)
       
   448     SDL_SCANCODE_LANG8 = 151; (*< reserved *)
       
   449     SDL_SCANCODE_LANG9 = 152; (*< reserved *)
       
   450     SDL_SCANCODE_ALTERASE = 153;
       
   451     SDL_SCANCODE_SYSREQ = 154;
       
   452     SDL_SCANCODE_CANCEL = 155;
       
   453     SDL_SCANCODE_CLEAR = 156;
       
   454     SDL_SCANCODE_PRIOR = 157;
       
   455     SDL_SCANCODE_RETURN2 = 158;
       
   456     SDL_SCANCODE_SEPARATOR = 159;
       
   457     SDL_SCANCODE_OUT = 160;
       
   458     SDL_SCANCODE_OPER = 161;
       
   459     SDL_SCANCODE_CLEARAGAIN = 162;
       
   460     SDL_SCANCODE_CRSEL = 163;
       
   461     SDL_SCANCODE_EXSEL = 164;
       
   462     SDL_SCANCODE_KP_00 = 176;
       
   463     SDL_SCANCODE_KP_000 = 177;
       
   464     SDL_SCANCODE_THOUSANDSSEPARATOR = 178;
       
   465     SDL_SCANCODE_DECIMALSEPARATOR = 179;
       
   466     SDL_SCANCODE_CURRENCYUNIT = 180;
       
   467     SDL_SCANCODE_CURRENCYSUBUNIT = 181;
       
   468     SDL_SCANCODE_KP_LEFTPAREN = 182;
       
   469     SDL_SCANCODE_KP_RIGHTPAREN = 183;
       
   470     SDL_SCANCODE_KP_LEFTBRACE = 184;
       
   471     SDL_SCANCODE_KP_RIGHTBRACE = 185;
       
   472     SDL_SCANCODE_KP_TAB = 186;
       
   473     SDL_SCANCODE_KP_BACKSPACE = 187;
       
   474     SDL_SCANCODE_KP_A = 188;
       
   475     SDL_SCANCODE_KP_B = 189;
       
   476     SDL_SCANCODE_KP_C = 190;
       
   477     SDL_SCANCODE_KP_D = 191;
       
   478     SDL_SCANCODE_KP_E = 192;
       
   479     SDL_SCANCODE_KP_F = 193;
       
   480     SDL_SCANCODE_KP_XOR = 194;
       
   481     SDL_SCANCODE_KP_PERCENT = 196;
       
   482     SDL_SCANCODE_KP_LESS = 197;
       
   483     SDL_SCANCODE_KP_GREATER = 198;
       
   484     SDL_SCANCODE_KP_AMPERSAND = 199;
       
   485     SDL_SCANCODE_KP_DBLAMPERSAND = 200;
       
   486     SDL_SCANCODE_KP_VERTICALBAR = 201;
       
   487     SDL_SCANCODE_KP_DBLVERTICALBAR = 202;
       
   488     SDL_SCANCODE_KP_COLON = 203;
       
   489     SDL_SCANCODE_KP_HASH = 204;
       
   490     SDL_SCANCODE_KP_SPACE = 205;
       
   491     SDL_SCANCODE_KP_AT = 206;
       
   492     SDL_SCANCODE_KP_EXCLAM = 207;
       
   493     SDL_SCANCODE_KP_MEMSTORE = 208;
       
   494     SDL_SCANCODE_KP_MEMRECALL = 209;
       
   495     SDL_SCANCODE_KP_MEMCLEAR = 210;
       
   496     SDL_SCANCODE_KP_MEMADD = 211;
       
   497     SDL_SCANCODE_KP_MEMSUBTRACT = 212;
       
   498     SDL_SCANCODE_KP_MEMMULTIPLY = 213;
       
   499     SDL_SCANCODE_KP_MEMDIVIDE = 214;
       
   500     SDL_SCANCODE_KP_PLUSMINUS = 215;
       
   501     SDL_SCANCODE_KP_CLEAR = 216;
       
   502     SDL_SCANCODE_KP_CLEARENTRY = 217;
       
   503     SDL_SCANCODE_KP_BINARY = 218;
       
   504     SDL_SCANCODE_KP_OCTAL = 219;
       
   505     SDL_SCANCODE_KP_DECIMAL = 220;
       
   506     SDL_SCANCODE_KP_HEXADECIMAL = 221;
       
   507     SDL_SCANCODE_LCTRL = 224;
       
   508     SDL_SCANCODE_LSHIFT = 225;
       
   509     SDL_SCANCODE_LALT = 226;
       
   510     SDL_SCANCODE_LGUI = 227;
       
   511     SDL_SCANCODE_RCTRL = 228;
       
   512     SDL_SCANCODE_RSHIFT = 229;
       
   513     SDL_SCANCODE_RALT = 230;
       
   514     SDL_SCANCODE_RGUI = 231;
       
   515     SDL_SCANCODE_MODE = 257;
       
   516     SDL_SCANCODE_AUDIONEXT = 258;
       
   517     SDL_SCANCODE_AUDIOPREV = 259;
       
   518     SDL_SCANCODE_AUDIOSTOP = 260;
       
   519     SDL_SCANCODE_AUDIOPLAY = 261;
       
   520     SDL_SCANCODE_AUDIOMUTE = 262;
       
   521     SDL_SCANCODE_MEDIASELECT = 263;
       
   522     SDL_SCANCODE_WWW = 264;
       
   523     SDL_SCANCODE_MAIL = 265;
       
   524     SDL_SCANCODE_CALCULATOR = 266;
       
   525     SDL_SCANCODE_COMPUTER = 267;
       
   526     SDL_SCANCODE_AC_SEARCH = 268;
       
   527     SDL_SCANCODE_AC_HOME = 269;
       
   528     SDL_SCANCODE_AC_BACK = 270;
       
   529     SDL_SCANCODE_AC_FORWARD = 271;
       
   530     SDL_SCANCODE_AC_STOP = 272;
       
   531     SDL_SCANCODE_AC_REFRESH = 273;
       
   532     SDL_SCANCODE_AC_BOOKMARKS = 274;
       
   533     SDL_SCANCODE_BRIGHTNESSDOWN = 275;
       
   534     SDL_SCANCODE_BRIGHTNESSUP = 276;
       
   535     SDL_SCANCODE_DISPLAYSWITCH = 277;
       
   536     SDL_SCANCODE_KBDILLUMTOGGLE = 278;
       
   537     SDL_SCANCODE_KBDILLUMDOWN = 279;
       
   538     SDL_SCANCODE_KBDILLUMUP = 280;
       
   539     SDL_SCANCODE_EJECT = 281;
       
   540     SDL_SCANCODE_SLEEP = 282;
       
   541     SDL_SCANCODE_APP1 = 283;
       
   542     SDL_SCANCODE_APP2 = 284;
   314 
   543 
   315 /////////////////////////////////////////////////////////////////
   544 /////////////////////////////////////////////////////////////////
   316 ///////////////////////  TYPE DEFINITIONS ///////////////////////
   545 ///////////////////////  TYPE DEFINITIONS ///////////////////////
   317 /////////////////////////////////////////////////////////////////
   546 /////////////////////////////////////////////////////////////////
   318 
   547 
   319 // two important reference points for the wanderers of this area
   548 // two important reference points for the wanderers of this area
   320 // http://www.freepascal.org/docs-html/ref/refsu5.html
   549 // https://www.freepascal.org/docs-html/ref/refsu5.html
   321 // http://www.freepascal.org/docs-html/prog/progsu144.html
   550 // https://www.freepascal.org/docs-html/prog/progsu144.html
   322 
   551 
   323 type
   552 type
   324 {$IFDEF SDL13}
       
   325     PSDL_Window   = Pointer;
   553     PSDL_Window   = Pointer;
   326     PSDL_Renderer = Pointer;
   554     PSDL_Renderer = Pointer;
   327     PSDL_Texture  = Pointer;
   555     PSDL_Texture  = Pointer;
   328     PSDL_GLContext= Pointer;
   556     PSDL_GLContext= Pointer;
       
   557     TSDL_TouchId  = Int64;
   329     TSDL_FingerId = Int64;
   558     TSDL_FingerId = Int64;
   330     TSDL_TouchId  = Int64;
   559     TSDL_Keycode = LongInt;
   331 {$ENDIF}
   560     TSDL_Scancode = LongInt;
       
   561     TSDL_JoystickID = LongInt;
       
   562     TSDL_bool = LongInt;
       
   563 
       
   564     TSDL_eventaction = (SDL_ADDEVENT, SDL_PEEPEVENT, SDL_GETEVENT);
   332 
   565 
   333     PSDL_Rect = ^TSDL_Rect;
   566     PSDL_Rect = ^TSDL_Rect;
   334     TSDL_Rect = record
   567     TSDL_Rect = record
   335 {$IFDEF SDL13}
       
   336         x, y, w, h: LongInt;
   568         x, y, w, h: LongInt;
   337 {$ELSE}
       
   338         x, y: SmallInt;
       
   339         w, h: Word;
       
   340 {$ENDIF}
       
   341         end;
   569         end;
   342 
   570 
   343     TPoint = record
   571     TPoint = record
   344         X, Y: LongInt;
   572         x, y: LongInt;
   345         end;
   573         end;
   346 
   574 
   347     PSDL_PixelFormat = ^TSDL_PixelFormat;
   575     PSDL_PixelFormat = ^TSDL_PixelFormat;
   348     TSDL_PixelFormat = record
   576     TSDL_PixelFormat = record
   349 {$IFDEF SDL13}
       
   350         format: LongWord;
   577         format: LongWord;
   351         palette: Pointer;
   578         palette: Pointer;
   352         BitsPerPixel : Byte;
   579         BitsPerPixel : Byte;
   353         BytesPerPixel: Byte;
   580         BytesPerPixel: Byte;
   354         padding: array[0..1] of Byte;
   581         padding: array[0..1] of Byte;
   364         Gshift: Byte;
   591         Gshift: Byte;
   365         Bshift: Byte;
   592         Bshift: Byte;
   366         Ashift: Byte;
   593         Ashift: Byte;
   367         refcount: LongInt;
   594         refcount: LongInt;
   368         next: PSDL_PixelFormat;
   595         next: PSDL_PixelFormat;
   369 {$ELSE}
   596         end;
   370         palette: Pointer;
       
   371         BitsPerPixel : Byte;
       
   372         BytesPerPixel: Byte;
       
   373         Rloss : Byte;
       
   374         Gloss : Byte;
       
   375         Bloss : Byte;
       
   376         Aloss : Byte;
       
   377         Rshift: Byte;
       
   378         Gshift: Byte;
       
   379         Bshift: Byte;
       
   380         Ashift: Byte;
       
   381         RMask : LongWord;
       
   382         GMask : LongWord;
       
   383         BMask : LongWord;
       
   384         AMask : LongWord;
       
   385         colorkey: LongWord;
       
   386         alpha: Byte;
       
   387 {$ENDIF}
       
   388         end;
       
   389 
       
   390     TSDL_eventaction = (SDL_ADDEVENT, SDL_PEEPEVENT, SDL_GETEVENT);
       
   391 
   597 
   392     PSDL_Surface = ^TSDL_Surface;
   598     PSDL_Surface = ^TSDL_Surface;
   393     TSDL_Surface = record
   599     TSDL_Surface = record
   394         flags : LongWord;
   600         flags : LongWord;
   395         format: PSDL_PixelFormat;
   601         format: PSDL_PixelFormat;
   396         w, h  : LongInt;
   602         w, h  : LongInt;
   397         pitch : {$IFDEF SDL13}LongInt{$ELSE}Word{$ENDIF};
   603         pitch : LongInt;
   398         pixels: Pointer;
   604         pixels: Pointer;
   399         offset: LongInt;
   605 {$IFDEF PAS2C}
   400 {$IFDEF SDL13}
   606         hwdata   : Pointer;
   401         userdata: Pointer;
       
   402         locked: LongInt;
       
   403         lock_data: Pointer;
       
   404         clip_rect: TSDL_Rect;
   607         clip_rect: TSDL_Rect;
   405         map: Pointer;
   608         unsed1   : LongWord;
   406         refcount: LongInt;
   609         locked   : LongWord;
       
   610         map      : Pointer;
       
   611         format_version: Longword;
       
   612         refcount : LongInt;
       
   613         offset   : LongInt;
       
   614 {$ELSE}
       
   615         userdata  : Pointer;
       
   616         locked    : LongInt;
       
   617         lock_data : Pointer;
       
   618         clip_rect : TSDL_Rect;
       
   619         map       : Pointer;
       
   620         refcount  : LongInt;
   407 {$ENDIF}
   621 {$ENDIF}
   408         end;
   622         end;
   409 
   623 
   410 
   624 
   411     PSDL_Color = ^TSDL_Color;
   625     PSDL_Color = ^TSDL_Color;
   412     TSDL_Color = record
   626     TSDL_Color = record
   413             r: Byte;
   627             r: Byte;
   414             g: Byte;
   628             g: Byte;
   415             b: Byte;
   629             b: Byte;
   416             unused: Byte;
   630             a: Byte; //sdl12 name is 'unused' but as long as size matches...
   417         end;
   631         end;
   418 
   632 
   419 
   633 
       
   634     (* SDL_RWops and friends *)
   420     PSDL_RWops = ^TSDL_RWops;
   635     PSDL_RWops = ^TSDL_RWops;
   421     TSeek  = function( context: PSDL_RWops; offset: LongInt; whence: LongInt ): LongInt; cdecl;
   636     TSize  = function( context: PSDL_RWops): Int64; cdecl;
       
   637     TSeek  = function( context: PSDL_RWops; offset: Int64; whence: LongInt ): Int64; cdecl;
   422     TRead  = function( context: PSDL_RWops; Ptr: Pointer; size: LongInt; maxnum : LongInt ): LongInt;  cdecl;
   638     TRead  = function( context: PSDL_RWops; Ptr: Pointer; size: LongInt; maxnum : LongInt ): LongInt;  cdecl;
   423     TWrite = function( context: PSDL_RWops; Ptr: Pointer; size: LongInt; num: LongInt ): LongInt; cdecl;
   639     TWrite = function( context: PSDL_RWops; Ptr: Pointer; size: LongInt; num: LongInt ): LongInt; cdecl;
   424     TClose = function( context: PSDL_RWops ): LongInt; cdecl;
   640     TClose = function( context: PSDL_RWops ): LongInt; cdecl;
   425 
   641 
   426     TStdio = record
   642     TStdio = record
   427         autoclose: {$IFDEF SDL13}Boolean{$ELSE}LongInt{$ENDIF};
   643         autoclose: Boolean;
   428         fp: Pointer;
   644         fp: Pointer;
   429         end;
   645         end;
   430 
   646 
   431     TMem = record
   647     TMem = record
   432         base: PByte;
   648         base: PByte;
   434         stop: PByte;
   650         stop: PByte;
   435         end;
   651         end;
   436 
   652 
   437     TUnknown = record
   653     TUnknown = record
   438         data1: Pointer;
   654         data1: Pointer;
   439         end;
   655         data2: Pointer;
       
   656         end;
       
   657 
       
   658 {$IFDEF ANDROID}
       
   659     TAndroidio = record
       
   660         fileName, inputStream, readableByteChannel: Pointer;
       
   661         readMethod, assetFileDescriptor: Pointer;
       
   662         position, size, offset: Int64;
       
   663         fd: LongInt;
       
   664         end;
       
   665 {$ELSE}
       
   666 {$IFDEF WINDOWS}
       
   667     TWinbuffer = record
       
   668         data: Pointer;
       
   669         size, left: LongInt;
       
   670         end;
       
   671     TWindowsio = record
       
   672         append : Boolean;
       
   673         h : Pointer;
       
   674         buffer : TWinbuffer;
       
   675         end;
       
   676 {$ENDIF}
       
   677 {$ENDIF}
   440 
   678 
   441     TSDL_RWops = record
   679     TSDL_RWops = record
       
   680         size: TSize;
   442         seek: TSeek;
   681         seek: TSeek;
   443         read: TRead;
   682         read: TRead;
   444         write: TWrite;
   683         write: TWrite;
   445         close: TClose;
   684         close: TClose;
   446         type_: LongWord;
   685         type_: LongWord;
   447         case Byte of
   686         case Byte of
   448             0: (stdio: TStdio);
   687 {$IFDEF ANDROID}
   449             1: (mem: TMem);
   688             0: (androidio: TAndroidio);
   450             2: (unknown: TUnknown);
   689 {$ELSE}
       
   690 {$IFDEF WINDOWS}
       
   691             0: (windowsio: TWindowsio);
       
   692 {$ENDIF}
       
   693 {$ENDIF}
       
   694             1: (stdio: TStdio);     // assumes HAVE_STDIO_H
       
   695             2: (mem: TMem);
       
   696             3: (unknown: TUnknown);
   451             end;
   697             end;
   452 
   698 
   453 
   699 
   454 {* SDL_Event type definition *}
   700 {* SDL_Event type definition *}
   455 
   701 
   456 {$IFDEF SDL13}
   702     TSDL_Keysym = record
   457     TSDL_KeySym = record
   703         scancode: TSDL_Scancode;
   458         scancode: LongInt;
   704         sym: TSDL_Keycode;
   459         sym: LongWord;
       
   460         modifier: Word;
   705         modifier: Word;
   461         unicode: LongWord;
   706         unused: LongWord;
   462         end;
   707         end;
   463 
   708 
   464     TSDL_WindowEvent = record
   709     TSDL_WindowEvent = record
   465         type_: LongWord;
   710         type_: LongWord;
   466         timestamp: LongWord;
   711         timestamp: LongWord;
   468         event: Byte;
   713         event: Byte;
   469         padding1, padding2, padding3: Byte;
   714         padding1, padding2, padding3: Byte;
   470         data1, data2: LongInt;
   715         data1, data2: LongInt;
   471         end;
   716         end;
   472 
   717 
   473     // available in sdl12 but not exposed
       
   474     TSDL_TextEditingEvent = record
   718     TSDL_TextEditingEvent = record
   475         type_: LongWord;
   719         type_: Longword;
   476         timestamp: LongWord;
   720         timestamp: Longword;
   477         windowID: LongWord;
   721         windowID: Longword;
   478         text: array[0..31] of Byte;
   722         text: array [0..SDL_TEXTEDITINGEVENT_TEXT_SIZE - 1] of char;
   479         start, lenght: LongInt;
   723         start: LongInt;
   480         end;
   724         length: LongInt;
   481 
   725         end;
   482     // available in sdl12 but not exposed
   726 
   483     TSDL_TextInputEvent = record
   727     TSDL_TextInputEvent = record
   484         type_: LongWord;
   728         type_: Longword;
   485         timestamp: LongWord;
   729         timestamp: Longword;
   486         windowID: LongWord;
   730         windowID: Longword;
   487         text: array[0..31] of Byte;
   731         text: array [0..SDL_TEXTINPUTEVENT_TEXT_SIZE - 1] of char;
   488         end;
   732         end;
   489 
   733 
   490     TSDL_TouchFingerEvent = record
   734     TSDL_TouchFingerEvent = record
   491         type_: LongWord;
   735         type_: LongWord;
   492         timestamp: LongWord;
   736         timestamp: LongWord;
   493         windowId: LongWord;
       
   494         touchId: TSDL_TouchId;
   737         touchId: TSDL_TouchId;
   495         fingerId: TSDL_FingerId;
   738         fingerId: TSDL_FingerId;
   496         state, padding1, padding2, padding3: Byte;
   739         x, y, dx, dy: Single;
   497         x, y: Word;
   740         pressure: Single;
   498         dx, dy: SmallInt;
       
   499         pressure: Word;
       
   500         end;
       
   501 
       
   502     TSDL_TouchButtonEvent = record
       
   503         type_: LongWord;
       
   504         timestamp: LongWord;
       
   505         windowId: LongWord;
       
   506         touchId: TSDL_TouchId;
       
   507         state, button, padding1, padding2: Byte;
       
   508         end;
   741         end;
   509 
   742 
   510     TSDL_MultiGestureEvent = record
   743     TSDL_MultiGestureEvent = record
   511         type_: LongWord;
   744         type_: LongWord;
   512         timestamp: LongWord;
   745         timestamp: LongWord;
   513         windowId: LongWord;
       
   514         touchId: TSDL_TouchId;
   746         touchId: TSDL_TouchId;
   515         dTheta, dDist, x, y: Single;
   747         dTheta, dDist, x, y: Single;
   516         numFingers, padding: Word;
   748         numFingers, padding: Word;
   517         end;
   749         end;
   518 
   750 
   519     TSDL_DollarGestureEvent = record
   751     TSDL_DollarGestureEvent = record
   520         type_: LongWord;
   752         type_: LongWord;
   521         timestamp: LongWord;
   753         timestamp: LongWord;
   522         windowId: LongWord;
       
   523         touchId: Int64;
   754         touchId: Int64;
   524         gesturedId: Int64;
   755         gesturedId: Int64;
   525         numFingers: LongWord;
   756         numFingers: LongWord;
   526         error: Single;
   757         error, x, y: Single;
   527         end;
   758         end;
   528 
   759 
   529     TSDL_DropEvent = record
   760     TSDL_DropEvent = record
   530         type_: LongWord;
   761         type_: LongWord;
   531         timestamp: LongWord;
   762         timestamp: LongWord;
   535     TSDL_SysWMEvent = record
   766     TSDL_SysWMEvent = record
   536         type_: LongWord;
   767         type_: LongWord;
   537         timestamp: LongWord;
   768         timestamp: LongWord;
   538         msg: Pointer;
   769         msg: Pointer;
   539         end;
   770         end;
   540 {$ELSE}
   771 
   541     TSDL_KeySym = record
   772     TSDL_ControllerAxisEvent = record
   542         scancode: Byte;
   773         type_: LongWord;
   543         sym: LongWord;
   774         timestamp: LongWord;
   544         modifier: LongWord;
   775         which: TSDL_JoystickID;
   545         unicode: Word;
   776         axis, padding1, padding2, padding3: Byte;
   546         end;
   777         value: SmallInt;
   547 
   778         padding4: Word;
   548     TSDL_ActiveEvent = record
   779         end;
   549         type_: Byte;
   780 
   550         gain: Byte;
   781     TSDL_ControllerButtonEvent = record
   551         state: Byte;
   782         type_: LongWord;
   552         end;
   783         timestamp: LongWord;
   553 
   784         which: TSDL_JoystickID;
   554     TSDL_ResizeEvent = record
   785         button, states, padding1, padding2: Byte;
   555         type_: Byte;
   786         end;
   556         w, h: LongInt;
   787 
   557         end;
   788     TSDL_ControllerDeviceEvent = record
   558 {$ENDIF}
   789         type_: LongWord;
       
   790         timestamp: LongWord;
       
   791         which: LongInt;
       
   792         end;
       
   793 
       
   794     TSDL_JoyDeviceEvent = TSDL_ControllerDeviceEvent;
       
   795 
       
   796     TSDL_CommonEvent = record
       
   797         type_: LongWord;
       
   798         timestamp: LongWord;
       
   799         end;
       
   800 
       
   801     TSDL_OSEvent = TSDL_CommonEvent;
   559 
   802 
   560     TSDL_KeyboardEvent = record
   803     TSDL_KeyboardEvent = record
   561 {$IFDEF SDL13}
   804         type_: LongWord;
   562         type_: LongWord;
   805         timestamp: LongWord;
   563 //        timestamp: LongWord;
       
   564         windowID: LongWord;
   806         windowID: LongWord;
   565         state, repeat_ {*,padding2, padding3*}: Byte;
   807         state, repeat_, padding2, padding3: Byte;
   566 {$ELSE}
   808         keysym: TSDL_Keysym;
   567         type_, which, state: Byte;
       
   568 {$ENDIF}
       
   569         keysym: TSDL_KeySym;
       
   570         end;
   809         end;
   571 
   810 
   572     TSDL_MouseMotionEvent = record
   811     TSDL_MouseMotionEvent = record
   573 {$IFDEF SDL13}
       
   574         type_: LongWord;
   812         type_: LongWord;
   575         timestamp: LongWord;
   813         timestamp: LongWord;
   576         windowID: LongWord;
   814         windowID: LongWord;
   577         state, padding1, padding2, padding3: Byte;
   815         which, state: LongWord;
   578         x, y, z, xrel, yrel : LongInt;
   816         x, y, xrel, yrel: LongInt;
   579 {$ELSE}
       
   580         type_, which, state: Byte;
       
   581         x, y, xrel, yrel : Word;
       
   582 {$ENDIF}
       
   583         end;
   817         end;
   584 
   818 
   585     TSDL_MouseButtonEvent = record
   819     TSDL_MouseButtonEvent = record
   586 {$IFDEF SDL13}
       
   587         type_: LongWord;
   820         type_: LongWord;
   588         timestamp: LongWord;
   821         timestamp: LongWord;
   589         windowID: LongWord;
   822         windowID: LongWord;
       
   823         which: LongWord;
   590         button, state, padding1, padding2: Byte;
   824         button, state, padding1, padding2: Byte;
   591         x, y: LongInt;
   825         x, y: LongInt;
   592 {$ELSE}
       
   593         type_, which, button, state: Byte;
       
   594         x, y: Word;
       
   595 {$ENDIF}
       
   596         end;
   826         end;
   597 
   827 
   598     TSDL_MouseWheelEvent = record
   828     TSDL_MouseWheelEvent = record
   599         type_: LongWord;
   829         type_: LongWord;
   600 {$IFDEF SDL13}
       
   601         timestamp: LongWord;
   830         timestamp: LongWord;
   602         windowID: LongWord;
   831         windowID: LongWord;
   603 {$ELSE}
   832         which: LongWord;
   604         which: Byte;
       
   605 {$ENDIF}
       
   606         x, y: LongInt;
   833         x, y: LongInt;
   607         end;
   834         end;
   608 
   835 
   609     TSDL_JoyAxisEvent = record
   836     TSDL_JoyAxisEvent = record
   610 {$IFDEF SDL13}
   837         type_: LongWord;
   611         type_: LongWord;
   838         timestamp: LongWord;
   612         timestamp: LongWord;
   839         which: TSDL_JoystickID;
   613 {$ELSE}
       
   614         type_: Byte;
       
   615 {$ENDIF}
       
   616         which: Byte;
       
   617         axis: Byte;
   840         axis: Byte;
   618 {$IFDEF SDL13}
   841         padding1, padding2, padding3: Byte;
   619         padding1, padding2: Byte;
       
   620         value: LongInt;
       
   621 {$ELSE}
       
   622         value: SmallInt;
   842         value: SmallInt;
   623 {$ENDIF}
   843         padding4: Word;
   624         end;
   844         end;
   625 
   845 
   626     TSDL_JoyBallEvent = record
   846     TSDL_JoyBallEvent = record
   627 {$IFDEF SDL13}
   847         type_: LongWord;
   628         type_: LongWord;
   848         timestamp: LongWord;
   629         timestamp: LongWord;
   849         which: TSDL_JoystickID;
   630 {$ELSE}
       
   631         type_: Byte;
       
   632 {$ENDIF}
       
   633         which: Byte;
       
   634         ball: Byte;
   850         ball: Byte;
   635 {$IFDEF SDL13}
   851         padding1, padding2, padding3: Byte;
   636         padding1, padding2: Byte;
       
   637         xrel, yrel: LongInt;
       
   638 {$ELSE}
       
   639         xrel, yrel: SmallInt;
   852         xrel, yrel: SmallInt;
   640 {$ENDIF}
       
   641         end;
   853         end;
   642 
   854 
   643     TSDL_JoyHatEvent = record
   855     TSDL_JoyHatEvent = record
   644 {$IFDEF SDL13}
   856         type_: LongWord;
   645         type_: LongWord;
   857         timestamp: LongWord;
   646         timestamp: LongWord;
   858         which: TSDL_JoystickID;
   647 {$ELSE}
       
   648         type_: Byte;
       
   649 {$ENDIF}
       
   650         which: Byte;
       
   651         hat: Byte;
   859         hat: Byte;
   652         value: Byte;
   860         value: Byte;
   653 {$IFDEF SDL13}
   861         padding1, padding2: Byte;
   654         padding1: Byte;
       
   655 {$ENDIF}
       
   656         end;
   862         end;
   657 
   863 
   658     TSDL_JoyButtonEvent = record
   864     TSDL_JoyButtonEvent = record
   659 {$IFDEF SDL13}
   865         type_: LongWord;
   660         type_: LongWord;
   866         timestamp: LongWord;
   661         timestamp: LongWord;
   867         which: TSDL_JoystickID;
   662 {$ELSE}
       
   663         type_: Byte;
       
   664 {$ENDIF}
       
   665         which: Byte;
       
   666         button: Byte;
   868         button: Byte;
   667         state: Byte;
   869         state: Byte;
   668 {$IFDEF SDL13}
       
   669         padding1: Byte;
   870         padding1: Byte;
   670 {$ENDIF}
   871         padding2: Byte;
   671         end;
   872         end;
   672 
   873 
   673     TSDL_QuitEvent = record
   874     TSDL_QuitEvent = record
   674 {$IFDEF SDL13}
   875         type_: LongWord;
   675         type_: LongWord;
   876         timestamp: LongWord;
   676         timestamp: LongWord;
       
   677 {$ELSE}
       
   678         type_: Byte;
       
   679 {$ENDIF}
       
   680         end;
   877         end;
   681 
   878 
   682     TSDL_UserEvent = record
   879     TSDL_UserEvent = record
   683 {$IFDEF SDL13}
       
   684         type_: LongWord;
   880         type_: LongWord;
   685         timestamp: LongWord;
   881         timestamp: LongWord;
   686         windowID: LongWord;
   882         windowID: LongWord;
   687 {$ELSE}
       
   688         type_: Byte;
       
   689 {$ENDIF}
       
   690         code: LongInt;
   883         code: LongInt;
   691         data1, data2: Pointer;
   884         data1, data2: Pointer;
   692         end;
   885         end;
   693 
   886 
   694     PSDL_Event = ^TSDL_Event;
   887     PSDL_Event = ^TSDL_Event;
   695     TSDL_Event = record
   888     TSDL_Event = record
   696 {$IFDEF SDL13}
       
   697         case LongInt of
   889         case LongInt of
   698             SDL_FIRSTEVENT: (type_: LongInt);
   890             SDL_FIRSTEVENT: (type_: LongWord);
       
   891             SDL_COMMONDEVENT: (common: TSDL_CommonEvent);
   699             SDL_WINDOWEVENT: (window: TSDL_WindowEvent);
   892             SDL_WINDOWEVENT: (window: TSDL_WindowEvent);
   700             SDL_KEYDOWN,
   893             SDL_KEYDOWN,
   701             SDL_KEYUP: (key: TSDL_KeyboardEvent);
   894             SDL_KEYUP: (key: TSDL_KeyboardEvent);
   702             SDL_TEXTEDITING: (edit: TSDL_TextEditingEvent);
   895             SDL_TEXTEDITING: (edit: TSDL_TextEditingEvent);
   703             SDL_TEXTINPUT: (tedit: TSDL_TextInputEvent);
   896             SDL_TEXTINPUT: (text: TSDL_TextInputEvent);
   704             SDL_MOUSEMOTION: (motion: TSDL_MouseMotionEvent);
   897             SDL_MOUSEMOTION: (motion: TSDL_MouseMotionEvent);
   705             SDL_MOUSEBUTTONDOWN,
   898             SDL_MOUSEBUTTONDOWN,
   706             SDL_MOUSEBUTTONUP: (button: TSDL_MouseButtonEvent);
   899             SDL_MOUSEBUTTONUP: (button: TSDL_MouseButtonEvent);
   707             SDL_MOUSEWHEEL: (wheel: TSDL_MouseWheelEvent);
   900             SDL_MOUSEWHEEL: (wheel: TSDL_MouseWheelEvent);
   708             SDL_JOYAXISMOTION: (jaxis: TSDL_JoyAxisEvent);
   901             SDL_JOYAXISMOTION: (jaxis: TSDL_JoyAxisEvent);
   709             SDL_JOYBALLMOTION: (jball: TSDL_JoyBallEvent);
   902             SDL_JOYBALLMOTION: (jball: TSDL_JoyBallEvent);
   710             SDL_JOYHATMOTION: (jhat: TSDL_JoyHatEvent);
   903             SDL_JOYHATMOTION: (jhat: TSDL_JoyHatEvent);
   711             SDL_JOYBUTTONDOWN,
   904             SDL_JOYBUTTONDOWN,
   712             SDL_JOYBUTTONUP: (jbutton: TSDL_JoyButtonEvent);
   905             SDL_JOYBUTTONUP: (jbutton: TSDL_JoyButtonEvent);
       
   906             SDL_JOYDEVICEADDED,
       
   907             SDL_JOYDEVICEREMOVED: (jdevice: TSDL_JoyDeviceEvent);
       
   908             SDL_CONTROLLERAXISMOTION: (caxis: TSDL_ControllerAxisEvent);
       
   909             SDL_CONTROLLERBUTTONUP,
       
   910             SDL_CONTROLLERBUTTONDOWN: (cbutton: TSDL_ControllerButtonEvent);
       
   911             SDL_CONTROLLERDEVICEADDED,
       
   912             SDL_CONTROLLERDEVICEREMAPPED,
       
   913             SDL_CONTROLLERDEVICEREMOVED: (cdevice: TSDL_ControllerDeviceEvent);
   713             SDL_QUITEV: (quit: TSDL_QuitEvent);
   914             SDL_QUITEV: (quit: TSDL_QuitEvent);
   714             SDL_USEREVENT: (user: TSDL_UserEvent);
   915             SDL_USEREVENT: (user: TSDL_UserEvent);
   715             SDL_SYSWMEVENT: (syswm: TSDL_SysWMEvent);
   916             SDL_SYSWMEVENT: (syswm: TSDL_SysWMEvent);
   716             SDL_FINGERDOWN,
   917             SDL_FINGERDOWN,
   717             SDL_FINGERUP,
   918             SDL_FINGERUP,
   718             SDL_FINGERMOTION: (tfinger: TSDL_TouchFingerEvent);
   919             SDL_FINGERMOTION: (tfinger: TSDL_TouchFingerEvent);
   719             SDL_TOUCHBUTTONUP,
       
   720             SDL_TOUCHBUTTONDOWN: (tbutton: TSDL_TouchButtonEvent);
       
   721             SDL_MULTIGESTURE: (mgesture: TSDL_MultiGestureEvent);
   920             SDL_MULTIGESTURE: (mgesture: TSDL_MultiGestureEvent);
   722             SDL_DOLLARGESTURE: (dgesture: TSDL_DollarGestureEvent);
   921             SDL_DOLLARGESTURE: (dgesture: TSDL_DollarGestureEvent);
   723             SDL_DROPFILE: (drop: TSDL_DropEvent);
   922             SDL_DROPFILE: (drop: TSDL_DropEvent);
   724             SDL_ALLEVENTS: (foo: shortstring);
   923             SDL_ALLEVENTS: (foo: shortstring);
   725 {$ELSE}
       
   726         case Byte of
       
   727             SDL_NOEVENT: (type_: Byte);
       
   728             SDL_ACTIVEEVENT: (active: TSDL_ActiveEvent);
       
   729             SDL_KEYDOWN,
       
   730             SDL_KEYUP: (key: TSDL_KeyboardEvent);
       
   731             SDL_MOUSEMOTION: (motion: TSDL_MouseMotionEvent);
       
   732             SDL_MOUSEBUTTONDOWN,
       
   733             SDL_MOUSEBUTTONUP: (button: TSDL_MouseButtonEvent);
       
   734             SDL_JOYAXISMOTION: (jaxis: TSDL_JoyAxisEvent);
       
   735             SDL_JOYHATMOTION: (jhat: TSDL_JoyHatEvent);
       
   736             SDL_JOYBALLMOTION: (jball: TSDL_JoyBallEvent);
       
   737             SDL_JOYBUTTONDOWN,
       
   738             SDL_JOYBUTTONUP: (jbutton: TSDL_JoyButtonEvent);
       
   739             SDL_QUITEV: (quit: TSDL_QuitEvent);
       
   740             //SDL_SYSWMEVENT,SDL_EVENT_RESERVEDA,SDL_EVENT_RESERVEDB
       
   741             SDL_VIDEORESIZE: (resize: TSDL_ResizeEvent);
       
   742             SDL_ALLEVENTS: (foo: shortstring);
       
   743 {$ENDIF}
       
   744         end;
   924         end;
   745 
   925 
   746     TSDL_EventFilter = function( event : PSDL_Event ): Integer; cdecl;
   926     TSDL_EventFilter = function( event : PSDL_Event ): Integer; cdecl;
   747 
   927 
   748     TByteArray = array[0..65535] of Byte;
   928     TByteArray = array[0..65535] of Byte;
   749     PByteArray = ^TByteArray;
   929     PByteArray = ^TByteArray;
       
   930 
   750     TLongWordArray = array[0..16383] of LongWord;
   931     TLongWordArray = array[0..16383] of LongWord;
   751     PLongWordArray = ^TLongWordArray;
   932     PLongWordArray = ^TLongWordArray;
   752 
   933 
   753     PSDL_Thread = Pointer;
   934     PSDL_Thread = Pointer;
   754     PSDL_mutex = Pointer;
   935     PSDL_mutex = Pointer;
       
   936     PSDL_sem = Pointer;
   755 
   937 
   756     TSDL_GLattr = (
   938     TSDL_GLattr = (
   757         SDL_GL_RED_SIZE,
   939         SDL_GL_RED_SIZE,
   758         SDL_GL_GREEN_SIZE,
   940         SDL_GL_GREEN_SIZE,
   759         SDL_GL_BLUE_SIZE,
   941         SDL_GL_BLUE_SIZE,
   768         SDL_GL_ACCUM_ALPHA_SIZE,
   950         SDL_GL_ACCUM_ALPHA_SIZE,
   769         SDL_GL_STEREO,
   951         SDL_GL_STEREO,
   770         SDL_GL_MULTISAMPLEBUFFERS,
   952         SDL_GL_MULTISAMPLEBUFFERS,
   771         SDL_GL_MULTISAMPLESAMPLES,
   953         SDL_GL_MULTISAMPLESAMPLES,
   772         SDL_GL_ACCELERATED_VISUAL,
   954         SDL_GL_ACCELERATED_VISUAL,
   773 {$IFDEF SDL13}
       
   774         SDL_GL_RETAINED_BACKING,
   955         SDL_GL_RETAINED_BACKING,
   775         SDL_GL_CONTEXT_MAJOR_VERSION,
   956         SDL_GL_CONTEXT_MAJOR_VERSION,
   776         SDL_GL_CONTEXT_MINOR_VERSION
   957         SDL_GL_CONTEXT_MINOR_VERSION,
   777 {$ELSE}
   958         SDL_GL_CONTEXT_EGL,
   778         SDL_GL_SWAP_CONTROL
   959         SDL_GL_CONTEXT_FLAGS,
   779 {$ENDIF}
   960         SDL_GL_CONTEXT_PROFILE_MASK,
       
   961         SDL_GL_SHARE_WITH_CURRENT_CONTEXT
   780         );
   962         );
   781 
   963 
   782 {$IFDEF SDL13}
       
   783     TSDL_ArrayByteOrder = (  // array component order, low Byte -> high Byte
   964     TSDL_ArrayByteOrder = (  // array component order, low Byte -> high Byte
   784         SDL_ARRAYORDER_NONE,
   965         SDL_ARRAYORDER_NONE,
   785         SDL_ARRAYORDER_RGB,
   966         SDL_ARRAYORDER_RGB,
   786         SDL_ARRAYORDER_RGBA,
   967         SDL_ARRAYORDER_RGBA,
   787         SDL_ARRAYORDER_ARGB,
   968         SDL_ARRAYORDER_ARGB,
   788         SDL_ARRAYORDER_BGR,
   969         SDL_ARRAYORDER_BGR,
   789         SDL_ARRAYORDER_BGRA,
   970         SDL_ARRAYORDER_BGRA,
   790         SDL_ARRAYORDER_ABGR
   971         SDL_ARRAYORDER_ABGR
   791         );
   972         );
   792 {$ENDIF}
   973 
   793 
   974     // Joystick/Controller support
   794 // Joystick/Controller support
       
   795     PSDL_Joystick = ^TSDL_Joystick;
   975     PSDL_Joystick = ^TSDL_Joystick;
   796     TSDL_Joystick = record
   976     TSDL_Joystick = record
   797             end;
   977             end;
   798 
   978 
   799     {* SDL_TTF *}
   979     {* SDL_TTF *}
   825 
  1005 
   826     PMixMusic = ^TMixMusic;
  1006     PMixMusic = ^TMixMusic;
   827     TMixMusic = record
  1007     TMixMusic = record
   828                 end;
  1008                 end;
   829 
  1009 
   830     TPostMix = procedure(udata: pointer; stream: PByte; len: LongInt); cdecl;
  1010     TPostMix = procedure(udata: Pointer; stream: PByte; len: LongInt); cdecl;
   831 
  1011 
   832     {* SDL_net *}
  1012     {* SDL_net *}
   833     TIPAddress = record
  1013     TIPAddress = record
   834                 host: LongWord;
  1014                 host: LongWord;
   835                 port: Word;
  1015                 port: Word;
   848                         numsockets,
  1028                         numsockets,
   849                         maxsockets: LongInt;
  1029                         maxsockets: LongInt;
   850                         sockets: PTCPSocket;
  1030                         sockets: PTCPSocket;
   851                         end;
  1031                         end;
   852 
  1032 
       
  1033 {$IFDEF WINDOWS}
       
  1034      TThreadFunction = function (p: pointer): Longword; stdcall;
       
  1035      pfnSDL_CurrentBeginThread = function (
       
  1036         _Security: pointer; 
       
  1037         _StackSize: LongWord;
       
  1038         _StartAddress: TThreadFunction;
       
  1039         _ArgList: pointer;
       
  1040         _InitFlag: Longword;
       
  1041         _ThrdAddr: PLongword): PtrUInt; cdecl;
       
  1042     pfnSDL_CurrentEndThread = procedure (_Retval: LongInt); cdecl;
       
  1043 {$ENDIF} 
   853 
  1044 
   854 /////////////////////////////////////////////////////////////////
  1045 /////////////////////////////////////////////////////////////////
   855 /////////////////////  FUNCTION DEFINITIONS /////////////////////
  1046 /////////////////////  FUNCTION DEFINITIONS /////////////////////
   856 /////////////////////////////////////////////////////////////////
  1047 /////////////////////////////////////////////////////////////////
   857 
  1048 
   859 {* SDL *}
  1050 {* SDL *}
   860 function  SDL_Init(flags: LongWord): LongInt; cdecl; external SDLLibName;
  1051 function  SDL_Init(flags: LongWord): LongInt; cdecl; external SDLLibName;
   861 function  SDL_InitSubSystem(flags: LongWord): LongInt; cdecl; external SDLLibName;
  1052 function  SDL_InitSubSystem(flags: LongWord): LongInt; cdecl; external SDLLibName;
   862 procedure SDL_Quit; cdecl; external SDLLibName;
  1053 procedure SDL_Quit; cdecl; external SDLLibName;
   863 
  1054 
       
  1055 procedure SDL_free(mem: Pointer); cdecl; external SDLLibName;
       
  1056 
   864 procedure SDL_Delay(msec: LongWord); cdecl; external SDLLibName;
  1057 procedure SDL_Delay(msec: LongWord); cdecl; external SDLLibName;
   865 function  SDL_GetTicks: LongWord; cdecl; external SDLLibName;
  1058 function  SDL_GetTicks: LongWord; cdecl; external SDLLibName;
   866 
  1059 
   867 function  SDL_MustLock(Surface: PSDL_Surface): Boolean;
  1060 function  SDL_MustLock(Surface: PSDL_Surface): Boolean;
   868 function  SDL_LockSurface(Surface: PSDL_Surface): LongInt; cdecl; external SDLLibName;
  1061 function  SDL_LockSurface(Surface: PSDL_Surface): LongInt; cdecl; external SDLLibName;
   869 procedure SDL_UnlockSurface(Surface: PSDL_Surface); cdecl; external SDLLibName;
  1062 procedure SDL_UnlockSurface(Surface: PSDL_Surface); cdecl; external SDLLibName;
   870 
  1063 
   871 function  SDL_GetError: PChar; cdecl; external SDLLibName;
  1064 function  SDL_GetError: PChar; cdecl; external SDLLibName;
   872 
  1065 
   873 function  SDL_SetVideoMode(width, height, bpp: LongInt; flags: LongWord): PSDL_Surface; cdecl; external SDLLibName;
       
   874 function  SDL_CreateRGBSurface(flags: LongWord; Width, Height, Depth: LongInt; RMask, GMask, BMask, AMask: LongWord): PSDL_Surface; cdecl; external SDLLibName;
  1066 function  SDL_CreateRGBSurface(flags: LongWord; Width, Height, Depth: LongInt; RMask, GMask, BMask, AMask: LongWord): PSDL_Surface; cdecl; external SDLLibName;
   875 function  SDL_CreateRGBSurfaceFrom(pixels: Pointer; width, height, depth, pitch: LongInt; RMask, GMask, BMask, AMask: LongWord): PSDL_Surface; cdecl; external SDLLibName;
  1067 function  SDL_CreateRGBSurfaceFrom(pixels: Pointer; width, height, depth, pitch: LongInt; RMask, GMask, BMask, AMask: LongWord): PSDL_Surface; cdecl; external SDLLibName;
   876 procedure SDL_FreeSurface(Surface: PSDL_Surface); cdecl; external SDLLibName;
  1068 procedure SDL_FreeSurface(Surface: PSDL_Surface); cdecl; external SDLLibName;
   877 function  SDL_SetColorKey(surface: PSDL_Surface; flag, key: LongWord): LongInt; cdecl; external SDLLibName;
  1069 function  SDL_SetColorKey(surface: PSDL_Surface; flag, key: LongWord): LongInt; cdecl; external SDLLibName;
   878 function  SDL_SetAlpha(surface: PSDL_Surface; flag, key: LongWord): LongInt; cdecl; external SDLLibName;
  1070 function  SDL_SetAlpha(surface: PSDL_Surface; flag, key: LongWord): LongInt; cdecl; external SDLLibName;
   879 function  SDL_ConvertSurface(src: PSDL_Surface; fmt: PSDL_PixelFormat; flags: LongInt): PSDL_Surface; cdecl; external SDLLibName;
  1071 function  SDL_ConvertSurface(src: PSDL_Surface; fmt: PSDL_PixelFormat; flags: LongWord): PSDL_Surface; cdecl; external SDLLibName;
   880 
  1072 
   881 function  SDL_UpperBlit(src: PSDL_Surface; srcrect: PSDL_Rect; dst: PSDL_Surface; dstrect: PSDL_Rect): LongInt; cdecl; external SDLLibName;
  1073 function  SDL_UpperBlit(src: PSDL_Surface; srcrect: PSDL_Rect; dst: PSDL_Surface; dstrect: PSDL_Rect): LongInt; cdecl; external SDLLibName;
   882 function  SDL_FillRect(dst: PSDL_Surface; dstrect: PSDL_Rect; color: LongWord): LongInt; cdecl; external SDLLibName;
  1074 function  SDL_FillRect(dst: PSDL_Surface; dstrect: PSDL_Rect; color: LongWord): LongInt; cdecl; external SDLLibName;
   883 procedure SDL_UpdateRect(Screen: PSDL_Surface; x, y: LongInt; w, h: LongWord); cdecl; external SDLLibName;
  1075 procedure SDL_UpdateRect(Screen: PSDL_Surface; x, y: LongInt; w, h: LongWord); cdecl; external SDLLibName;
   884 function  SDL_Flip(Screen: PSDL_Surface): LongInt; cdecl; external SDLLibName;
  1076 function  SDL_Flip(Screen: PSDL_Surface): LongInt; cdecl; external SDLLibName;
   892 function  SDL_DisplayFormatAlpha(Surface: PSDL_Surface): PSDL_Surface; cdecl; external SDLLibName;
  1084 function  SDL_DisplayFormatAlpha(Surface: PSDL_Surface): PSDL_Surface; cdecl; external SDLLibName;
   893 
  1085 
   894 function  SDL_RWFromFile(filename, mode: PChar): PSDL_RWops; cdecl; external SDLLibName;
  1086 function  SDL_RWFromFile(filename, mode: PChar): PSDL_RWops; cdecl; external SDLLibName;
   895 function  SDL_SaveBMP_RW(surface: PSDL_Surface; dst: PSDL_RWops; freedst: LongInt): LongInt; cdecl; external SDLLibName;
  1087 function  SDL_SaveBMP_RW(surface: PSDL_Surface; dst: PSDL_RWops; freedst: LongInt): LongInt; cdecl; external SDLLibName;
   896 
  1088 
   897 {$IFDEF SDL13}
       
   898 function  SDL_CreateWindow(title: PChar; x,y,w,h: LongInt; flags: LongWord): PSDL_Window; cdecl; external SDLLibName;
  1089 function  SDL_CreateWindow(title: PChar; x,y,w,h: LongInt; flags: LongWord): PSDL_Window; cdecl; external SDLLibName;
       
  1090 procedure SDL_SetWindowIcon(window: PSDL_Window; icon: PSDL_Surface); cdecl; external SDLLibName;
       
  1091 
   899 function  SDL_CreateRenderer(window: PSDL_Window; index: LongInt; flags: LongWord): PSDL_Renderer; cdecl; external SDLLibName;
  1092 function  SDL_CreateRenderer(window: PSDL_Window; index: LongInt; flags: LongWord): PSDL_Renderer; cdecl; external SDLLibName;
   900 function  SDL_DestroyWindow(window: PSDL_Window): LongInt; cdecl; external SDLLibName;
  1093 function  SDL_DestroyWindow(window: PSDL_Window): LongInt; cdecl; external SDLLibName;
   901 function  SDL_DestroyRenderer(renderer: PSDL_Renderer): LongInt; cdecl; external SDLLibName;
  1094 function  SDL_DestroyRenderer(renderer: PSDL_Renderer): LongInt; cdecl; external SDLLibName;
       
  1095 procedure SDL_SetWindowPosition(window: PSDL_Window; w, h: LongInt); cdecl; external SDLLibName;
   902 procedure SDL_SetWindowSize(window: PSDL_Window; w, h: LongInt); cdecl; external SDLLibName;
  1096 procedure SDL_SetWindowSize(window: PSDL_Window; w, h: LongInt); cdecl; external SDLLibName;
       
  1097 procedure SDL_SetWindowFullscreen(window: PSDL_Window; flags: LongWord); cdecl; external SDLLibName;
   903 function  SDL_GetCurrentVideoDriver:Pchar; cdecl; external SDLLibName;
  1098 function  SDL_GetCurrentVideoDriver:Pchar; cdecl; external SDLLibName;
   904 
  1099 
   905 function  SDL_GL_CreateContext(window: PSDL_Window): PSDL_GLContext; cdecl; external SDLLibName;
  1100 function  SDL_GL_CreateContext(window: PSDL_Window): PSDL_GLContext; cdecl; external SDLLibName;
   906 procedure SDL_GL_DeleteContext(context: PSDL_GLContext); cdecl; external SDLLibName;
  1101 procedure SDL_GL_DeleteContext(context: PSDL_GLContext); cdecl; external SDLLibName;
   907 function  SDL_GL_SwapWindow(window: PSDL_Window): LongInt; cdecl; external SDLLibName;
  1102 procedure SDL_GL_SwapWindow(window: PSDL_Window); cdecl; external SDLLibName;
   908 function  SDL_GL_SetSwapInterval(interval: LongInt): LongInt; cdecl; external SDLLibName;
  1103 function  SDL_GL_SetSwapInterval(interval: LongInt): LongInt; cdecl; external SDLLibName;
   909 
  1104 
   910 procedure SDL_VideoQuit; cdecl; external SDLLibName;
  1105 procedure SDL_VideoQuit; cdecl; external SDLLibName;
   911 function  SDL_GetNumVideoDisplays: LongInt; cdecl; external SDLLibName;
  1106 function  SDL_GetNumVideoDisplays: LongInt; cdecl; external SDLLibName;
   912 procedure SDL_ShowWindow(window: PSDL_Window); cdecl; external SDLLibName;
  1107 procedure SDL_ShowWindow(window: PSDL_Window); cdecl; external SDLLibName;
   917 function  SDL_RenderClear(renderer: PSDL_Renderer): LongInt; cdecl; external SDLLibName;
  1112 function  SDL_RenderClear(renderer: PSDL_Renderer): LongInt; cdecl; external SDLLibName;
   918 procedure SDL_RenderPresent(renderer: PSDL_Renderer); cdecl; external SDLLibName;
  1113 procedure SDL_RenderPresent(renderer: PSDL_Renderer); cdecl; external SDLLibName;
   919 function  SDL_RenderReadPixels(renderer: PSDL_Renderer; rect: PSDL_Rect; format: LongInt; pixels: Pointer; pitch: LongInt): LongInt; cdecl; external SDLLibName;
  1114 function  SDL_RenderReadPixels(renderer: PSDL_Renderer; rect: PSDL_Rect; format: LongInt; pixels: Pointer; pitch: LongInt): LongInt; cdecl; external SDLLibName;
   920 function  SDL_RenderSetViewport(window: PSDL_Window; rect: PSDL_Rect): LongInt; cdecl; external SDLLibName;
  1115 function  SDL_RenderSetViewport(window: PSDL_Window; rect: PSDL_Rect): LongInt; cdecl; external SDLLibName;
   921 
  1116 
       
  1117 function  SDL_SetRelativeMouseMode(enabled: TSDL_bool): LongInt; cdecl; external SDLLibName;
   922 function  SDL_GetRelativeMouseState(x, y: PLongInt): Byte; cdecl; external SDLLibName;
  1118 function  SDL_GetRelativeMouseState(x, y: PLongInt): Byte; cdecl; external SDLLibName;
   923 function  SDL_PixelFormatEnumToMasks(format: TSDL_ArrayByteOrder; bpp: PLongInt; Rmask, Gmask, Bmask, Amask: PLongInt): Boolean; cdecl; external SDLLibName;
  1119 function  SDL_PixelFormatEnumToMasks(format: TSDL_ArrayByteOrder; bpp: PLongInt; Rmask, Gmask, Bmask, Amask: PLongInt): Boolean; cdecl; external SDLLibName;
   924 
  1120 
   925 procedure SDL_WarpMouseInWindow(window: PSDL_Window; x, y: LongInt); cdecl; external SDLLibName;
  1121 procedure SDL_WarpMouseInWindow(window: PSDL_Window; x, y: LongInt); cdecl; external SDLLibName;
   926 function  SDL_SetHint(name, value: PChar): Boolean; cdecl; external SDLLibName;
  1122 function  SDL_SetHint(name, value: PChar): Boolean; cdecl; external SDLLibName;
   927 procedure SDL_StartTextInput; cdecl; external SDLLibName;
  1123 procedure SDL_StartTextInput; cdecl; external SDLLibName;
       
  1124 procedure SDL_StopTextInput; cdecl; external SDLLibName;
       
  1125 procedure SDL_FlushEvent(eventType: LongWord); cdecl; external SDLLibName;
   928 
  1126 
   929 function  SDL_PeepEvents(event: PSDL_Event; numevents: LongInt; action: TSDL_eventaction; minType, maxType: LongWord): LongInt; cdecl; external SDLLibName;
  1127 function  SDL_PeepEvents(event: PSDL_Event; numevents: LongInt; action: TSDL_eventaction; minType, maxType: LongWord): LongInt; cdecl; external SDLLibName;
   930 function  SDL_CreateThread(fn: Pointer; name: PChar; data: Pointer): PSDL_Thread; cdecl; external SDLLibName;
  1128 
   931 {$ELSE}
  1129 function  SDL_AllocFormat(format: LongWord): PSDL_PixelFormat; cdecl; external SDLLibName;
   932 function  SDL_CreateThread(fn: Pointer; data: Pointer): PSDL_Thread; cdecl; external SDLLibName;
  1130 procedure SDL_FreeFormat(pixelformat: PSDL_PixelFormat); cdecl; external SDLLibName;
   933 function  SDL_PeepEvents(event: PSDL_Event; numevents: LongInt; action: TSDL_eventaction; mask: LongWord): LongInt; cdecl; external SDLLibName;
  1131 
   934 {$ENDIF}
       
   935 
  1132 
   936 function  SDL_GetMouseState(x, y: PLongInt): Byte; cdecl; external SDLLibName;
  1133 function  SDL_GetMouseState(x, y: PLongInt): Byte; cdecl; external SDLLibName;
   937 function  SDL_GetKeyName(key: LongWord): PChar; cdecl; external SDLLibName;
  1134 function  SDL_GetKeyName(key: TSDL_Keycode): PChar; cdecl; external SDLLibName;
   938 function  SDL_GetScancodeName(key: LongWord): PChar; cdecl; external SDLLibName;
  1135 function  SDL_GetScancodeName(key: TSDL_Scancode): PChar; cdecl; external SDLLibName;
   939 function  SDL_GetKeyFromScancode(key: LongWord): LongInt; cdecl; external SDLLibName;
  1136 function  SDL_GetKeyFromScancode(key: TSDL_Scancode): TSDL_Keycode; cdecl; external SDLLibName;
   940 
  1137 // SDL2 functions has some additional functions (not listed here) for keycode/scancode translation
   941 
  1138 
   942 procedure SDL_PumpEvents; cdecl; external SDLLibName;
  1139 procedure SDL_PumpEvents; cdecl; external SDLLibName;
   943 function  SDL_PollEvent(event: PSDL_Event): LongInt; cdecl; external SDLLibName;
  1140 function  SDL_PollEvent(event: PSDL_Event): LongInt; cdecl; external SDLLibName;
   944 function  SDL_WaitEvent(event: PSDL_Event): LongInt; cdecl; external SDLLibName;
  1141 function  SDL_WaitEvent(event: PSDL_Event): LongInt; cdecl; external SDLLibName;
   945 procedure SDL_SetEventFilter(filter: TSDL_EventFilter); cdecl; external SDLLibName;
  1142 procedure SDL_SetEventFilter(filter: TSDL_EventFilter); cdecl; external SDLLibName;
   946 
  1143 
   947 function  SDL_ShowCursor(toggle: LongInt): LongInt; cdecl; external SDLLibName;
  1144 function  SDL_ShowCursor(toggle: LongInt): LongInt; cdecl; external SDLLibName;
       
  1145 procedure SDL_WarpMouse(x, y: Word); inline;
       
  1146 
       
  1147 function  SDL_GetKeyboardState(numkeys: PLongInt): PByteArray; cdecl; external SDLLibName;
   948 
  1148 
   949 procedure SDL_WM_SetIcon(icon: PSDL_Surface; mask : Byte); cdecl; external SDLLibName;
  1149 procedure SDL_WM_SetIcon(icon: PSDL_Surface; mask : Byte); cdecl; external SDLLibName;
   950 procedure SDL_WM_SetCaption(title: PChar; icon: PChar); cdecl; external SDLLibName;
  1150 procedure SDL_WM_SetCaption(title: PChar; icon: PChar); cdecl; external SDLLibName;
   951 function  SDL_WM_ToggleFullScreen(surface: PSDL_Surface): LongInt; cdecl; external SDLLibName;
  1151 function  SDL_WM_ToggleFullScreen(surface: PSDL_Surface): LongInt; cdecl; external SDLLibName;
   952 
  1152 
       
  1153 
       
  1154 (* remember to mark the threaded functions as 'cdecl; export;'
       
  1155    (or have fun debugging nil arguments) *)
       
  1156 {$IFDEF WINDOWS}
       
  1157 // SDL uses wrapper in windows
       
  1158 function  SDL_CreateThread(fn: Pointer; name: PChar; data: Pointer; bt: pfnSDL_CurrentBeginThread; et: pfnSDL_CurrentEndThread): PSDL_Thread; cdecl; external SDLLibName;
       
  1159 function  SDL_CreateThread(fn: Pointer; name: PChar; data: Pointer): PSDL_Thread; cdecl; overload;
       
  1160 {$ELSE}
       
  1161 function  SDL_CreateThread(fn: Pointer; name: PChar; data: Pointer): PSDL_Thread; cdecl; external SDLLibName;
       
  1162 {$ENDIF}
   953 procedure SDL_WaitThread(thread: PSDL_Thread; status: PLongInt); cdecl; external SDLLibName;
  1163 procedure SDL_WaitThread(thread: PSDL_Thread; status: PLongInt); cdecl; external SDLLibName;
       
  1164 procedure SDL_DetachThread(thread: PSDL_Thread); cdecl; external SDLLibName;
       
  1165 procedure SDL_KillThread(thread: PSDL_Thread); cdecl; external SDLLibName;
       
  1166 
   954 function  SDL_CreateMutex: PSDL_mutex; cdecl; external SDLLibName;
  1167 function  SDL_CreateMutex: PSDL_mutex; cdecl; external SDLLibName;
   955 procedure SDL_DestroyMutex(mutex: PSDL_mutex); cdecl; external SDLLibName;
  1168 procedure SDL_DestroyMutex(mutex: PSDL_mutex); cdecl; external SDLLibName;
   956 function  SDL_LockMutex(mutex: PSDL_mutex): LongInt; cdecl; external SDLLibName name 'SDL_mutexP';
  1169 function  SDL_LockMutex(mutex: PSDL_mutex): LongInt; cdecl; external SDLLibName;
   957 function  SDL_UnlockMutex(mutex: PSDL_mutex): LongInt; cdecl; external SDLLibName name 'SDL_mutexV';
  1170 function  SDL_UnlockMutex(mutex: PSDL_mutex): LongInt; cdecl; external SDLLibName;
       
  1171 
       
  1172 function  SDL_CreateSemaphore(initial_value: Longword): PSDL_sem; cdecl; external SDLLibName;
       
  1173 procedure SDL_DestroySemaphore(sem: PSDL_sem); cdecl; external SDLLibName;
       
  1174 function  SDL_SemWait(sem: PSDL_sem): LongInt; cdecl; external SDLLibName;
       
  1175 function  SDL_SemPost(sem: PSDL_sem): LongInt; cdecl; external SDLLibName;
   958 
  1176 
   959 function  SDL_GL_SetAttribute(attr: TSDL_GLattr; value: LongInt): LongInt; cdecl; external SDLLibName;
  1177 function  SDL_GL_SetAttribute(attr: TSDL_GLattr; value: LongInt): LongInt; cdecl; external SDLLibName;
   960 procedure SDL_GL_SwapBuffers; cdecl; external SDLLibName;
  1178 procedure SDL_GL_SwapBuffers; cdecl; external SDLLibName;
   961 
  1179 
   962 procedure SDL_LockAudio; cdecl; external SDLLibName;
  1180 procedure SDL_LockAudio; cdecl; external SDLLibName;
   963 procedure SDL_UnlockAudio; cdecl; external SDLLibName;
  1181 procedure SDL_UnlockAudio; cdecl; external SDLLibName;
   964 
  1182 
   965 function  SDL_NumJoysticks: LongInt; cdecl; external SDLLibName;
  1183 function  SDL_NumJoysticks: LongInt; cdecl; external SDLLibName;
   966 function  SDL_JoystickName(idx: LongInt): PChar; cdecl; external SDLLibName;
  1184 function  SDL_JoystickNameForIndex(idx: LongInt): PChar; cdecl; external SDLLibName;
   967 function  SDL_JoystickOpen(idx: LongInt): PSDL_Joystick; cdecl; external SDLLibName;
  1185 function  SDL_JoystickOpen(idx: LongInt): PSDL_Joystick; cdecl; external SDLLibName;
   968 function  SDL_JoystickOpened(idx: LongInt): LongInt; cdecl; external SDLLibName;
  1186 function  SDL_JoystickOpened(idx: LongInt): LongInt; cdecl; external SDLLibName;
   969 function  SDL_JoystickIndex(joy: PSDL_Joystick): LongInt; cdecl; external SDLLibName;
  1187 function  SDL_JoystickIndex(joy: PSDL_Joystick): LongInt; cdecl; external SDLLibName;
   970 function  SDL_JoystickNumAxes(joy: PSDL_Joystick): LongInt; cdecl; external SDLLibName;
  1188 function  SDL_JoystickNumAxes(joy: PSDL_Joystick): LongInt; cdecl; external SDLLibName;
   971 function  SDL_JoystickNumBalls(joy: PSDL_Joystick): LongInt; cdecl; external SDLLibName;
  1189 function  SDL_JoystickNumBalls(joy: PSDL_Joystick): LongInt; cdecl; external SDLLibName;
   977 function  SDL_JoystickGetBall(joy: PSDL_Joystick; ball: LongInt; dx: PInteger; dy: PInteger): Word; cdecl; external SDLLibName;
  1195 function  SDL_JoystickGetBall(joy: PSDL_Joystick; ball: LongInt; dx: PInteger; dy: PInteger): Word; cdecl; external SDLLibName;
   978 function  SDL_JoystickGetHat(joy: PSDL_Joystick; hat: LongInt): Byte; cdecl; external SDLLibName;
  1196 function  SDL_JoystickGetHat(joy: PSDL_Joystick; hat: LongInt): Byte; cdecl; external SDLLibName;
   979 function  SDL_JoystickGetButton(joy: PSDL_Joystick; button: LongInt): Byte; cdecl; external SDLLibName;
  1197 function  SDL_JoystickGetButton(joy: PSDL_Joystick; button: LongInt): Byte; cdecl; external SDLLibName;
   980 procedure SDL_JoystickClose(joy: PSDL_Joystick); cdecl; external SDLLibName;
  1198 procedure SDL_JoystickClose(joy: PSDL_Joystick); cdecl; external SDLLibName;
   981 
  1199 
   982 {$IFDEF WIN32}
  1200 {$IFDEF WINDOWS}
   983 function SDL_putenv(const text: PChar): LongInt; cdecl; external SDLLibName;
  1201 function SDL_putenv(const text: PChar): LongInt; cdecl; external SDLLibName;
   984 function SDL_getenv(const text: PChar): PChar; cdecl; external SDLLibName;
  1202 function SDL_getenv(const text: PChar): PChar; cdecl; external SDLLibName;
   985 {$ENDIF}
  1203 {$ENDIF}
   986 
  1204 
   987 
       
   988 {* Compatibility between SDL-1.2 and SDL-1.3 *}
       
   989 procedure SDL_WarpMouse(x, y: Word); {$IFDEF SDL13}inline{$ELSE}cdecl; external SDLLibName{$ENDIF};
       
   990 function  SDL_GetKeyState(numkeys: PLongInt): PByteArray; cdecl; external SDLLibName {$IFDEF SDL13} name 'SDL_GetKeyboardState'{$ENDIF};
       
   991 function  SDL_AllocFormat(format: LongWord): PSDL_PixelFormat; {$IFDEF SDL13}cdecl; external SDLLibName;{$ENDIF}
       
   992 procedure SDL_FreeFormat(pixelformat: PSDL_PixelFormat); {$IFDEF SDL13}cdecl; external SDLLibName;{$ENDIF}
       
   993 function  SDL_VideoDriverName(namebuf: PChar; maxlen: LongInt): PChar; {$IFNDEF SDL13}cdecl; external SDLLibName;{$ENDIF}
       
   994 function  SDL_EnableUNICODE(enable: LongInt): LongInt; {$IFNDEF SDL13}cdecl; external SDLLibName;{$ENDIF}
       
   995 function  SDL_EnableKeyRepeat(timedelay, interval: LongInt): LongInt; {$IFNDEF SDL13}cdecl; external SDLLibName;{$ENDIF}
       
   996 
  1205 
   997 (*  SDL_ttf  *)
  1206 (*  SDL_ttf  *)
   998 function  TTF_Init: LongInt; cdecl; external SDL_TTFLibName;
  1207 function  TTF_Init: LongInt; cdecl; external SDL_TTFLibName;
   999 procedure TTF_Quit; cdecl; external SDL_TTFLibName;
  1208 procedure TTF_Quit; cdecl; external SDL_TTFLibName;
  1000 
  1209 
  1002 
  1211 
  1003 function  TTF_RenderUTF8_Solid(font: PTTF_Font; const text: PChar; fg: TSDL_Color): PSDL_Surface; cdecl; external SDL_TTFLibName;
  1212 function  TTF_RenderUTF8_Solid(font: PTTF_Font; const text: PChar; fg: TSDL_Color): PSDL_Surface; cdecl; external SDL_TTFLibName;
  1004 function  TTF_RenderUTF8_Blended(font: PTTF_Font; const text: PChar; fg: TSDL_Color): PSDL_Surface; cdecl; external SDL_TTFLibName;
  1213 function  TTF_RenderUTF8_Blended(font: PTTF_Font; const text: PChar; fg: TSDL_Color): PSDL_Surface; cdecl; external SDL_TTFLibName;
  1005 function  TTF_RenderUTF8_Shaded(font: PTTF_Font; const text: PChar; fg, bg: TSDL_Color): PSDL_Surface; cdecl; external SDL_TTFLibName;
  1214 function  TTF_RenderUTF8_Shaded(font: PTTF_Font; const text: PChar; fg, bg: TSDL_Color): PSDL_Surface; cdecl; external SDL_TTFLibName;
  1006 
  1215 
  1007 function  TTF_OpenFont(const filename: PChar; size: LongInt): PTTF_Font; cdecl; external SDL_TTFLibName;
  1216 function  TTF_OpenFontRW(src: PSDL_RWops; freesrc: LongBool; size: LongInt): PTTF_Font; cdecl; external SDL_TTFLibName;
  1008 procedure TTF_SetFontStyle(font: PTTF_Font; style: LongInt); cdecl; external SDL_TTFLibName;
  1217 procedure TTF_SetFontStyle(font: PTTF_Font; style: LongInt); cdecl; external SDL_TTFLibName;
       
  1218 procedure TTF_CloseFont(font: PTTF_Font); cdecl; external SDL_TTFLibName;
  1009 
  1219 
  1010 (*  SDL_mixer  *)
  1220 (*  SDL_mixer  *)
  1011 function  Mix_Init(flags: LongInt): LongInt; {$IFDEF SDL_MIXER_NEWER}cdecl; external SDL_MixerLibName;{$ENDIF}
  1221 function  Mix_Init(flags: LongInt): LongInt; cdecl; external SDL_MixerLibName;
  1012 procedure Mix_Quit; {$IFDEF SDL_MIXER_NEWER}cdecl; external SDL_MixerLibName;{$ENDIF}
  1222 procedure Mix_Quit; cdecl; external SDL_MixerLibName;
  1013 
  1223 
  1014 function  Mix_OpenAudio(frequency: LongInt; format: Word; channels: LongInt; chunksize: LongInt): LongInt; cdecl; external SDL_MixerLibName;
  1224 function  Mix_OpenAudio(frequency: LongInt; format: Word; channels: LongInt; chunksize: LongInt): LongInt; cdecl; external SDL_MixerLibName;
  1015 procedure Mix_CloseAudio; cdecl; external SDL_MixerLibName;
  1225 procedure Mix_CloseAudio; cdecl; external SDL_MixerLibName;
  1016 function  Mix_QuerySpec(frequency: PLongInt; format: PWord; channels: PLongInt): LongInt; cdecl; external SDL_MixerLibName;
  1226 function  Mix_QuerySpec(frequency: PLongInt; format: PWord; channels: PLongInt): LongInt; cdecl; external SDL_MixerLibName;
  1017 
  1227 
  1022 function  Mix_AllocateChannels(numchans: LongInt): LongInt; cdecl; external SDL_MixerLibName;
  1232 function  Mix_AllocateChannels(numchans: LongInt): LongInt; cdecl; external SDL_MixerLibName;
  1023 procedure Mix_FreeChunk(chunk: PMixChunk); cdecl; external SDL_MixerLibName;
  1233 procedure Mix_FreeChunk(chunk: PMixChunk); cdecl; external SDL_MixerLibName;
  1024 procedure Mix_FreeMusic(music: PMixMusic); cdecl; external SDL_MixerLibName;
  1234 procedure Mix_FreeMusic(music: PMixMusic); cdecl; external SDL_MixerLibName;
  1025 
  1235 
  1026 function  Mix_LoadWAV_RW(src: PSDL_RWops; freesrc: LongInt): PMixChunk; cdecl; external SDL_MixerLibName;
  1236 function  Mix_LoadWAV_RW(src: PSDL_RWops; freesrc: LongInt): PMixChunk; cdecl; external SDL_MixerLibName;
  1027 function  Mix_LoadMUS(const filename: PChar): PMixMusic; cdecl; external SDL_MixerLibName;
  1237 function  Mix_LoadMUS_RW(src: PSDL_RWops): PMixMusic; cdecl; external SDL_MixerLibName;
  1028 
  1238 
  1029 function  Mix_Playing(channel: LongInt): LongInt; cdecl; external SDL_MixerLibName;
  1239 function  Mix_Playing(channel: LongInt): LongInt; cdecl; external SDL_MixerLibName;
  1030 function  Mix_PlayingMusic: LongInt; cdecl; external SDL_MixerLibName;
  1240 function  Mix_PlayingMusic: LongInt; cdecl; external SDL_MixerLibName;
  1031 function  Mix_FadeInMusic(music: PMixMusic; loops: LongInt; ms: LongInt): LongInt; cdecl; external SDL_MixerLibName;
  1241 function  Mix_FadeInMusic(music: PMixMusic; loops: LongInt; ms: LongInt): LongInt; cdecl; external SDL_MixerLibName;
  1032 
  1242 
  1039 function  Mix_HaltMusic: LongInt; cdecl; external SDL_MixerLibName;
  1249 function  Mix_HaltMusic: LongInt; cdecl; external SDL_MixerLibName;
  1040 
  1250 
  1041 function  Mix_FadeInChannelTimed(channel: LongInt; chunk: PMixChunk; loops: LongInt; fadems: LongInt; ticks: LongInt): LongInt; cdecl; external SDL_MixerLibName;
  1251 function  Mix_FadeInChannelTimed(channel: LongInt; chunk: PMixChunk; loops: LongInt; fadems: LongInt; ticks: LongInt): LongInt; cdecl; external SDL_MixerLibName;
  1042 function  Mix_FadeOutChannel(channel: LongInt; fadems: LongInt): LongInt; cdecl; external SDL_MixerLibName;
  1252 function  Mix_FadeOutChannel(channel: LongInt; fadems: LongInt): LongInt; cdecl; external SDL_MixerLibName;
  1043 
  1253 
  1044 procedure Mix_SetPostMix( mix_func: TPostMix; arg: pointer); cdecl; external SDL_MixerLibName;
  1254 procedure Mix_SetPostMix( mix_func: TPostMix; arg: Pointer); cdecl; external SDL_MixerLibName;
  1045 
  1255 
  1046 (*  SDL_image  *)
  1256 (*  SDL_image  *)
  1047 function  IMG_Init(flags: LongInt): LongInt; {$IFDEF SDL_IMAGE_NEWER}cdecl; external SDL_ImageLibName;{$ENDIF}
  1257 function  IMG_Init(flags: LongInt): LongInt; cdecl; external SDL_ImageLibName;
  1048 procedure IMG_Quit; {$IFDEF SDL_IMAGE_NEWER}cdecl; external SDL_ImageLibName;{$ENDIF}
  1258 procedure IMG_Quit; cdecl; external SDL_ImageLibName;
  1049 
  1259 
  1050 function  IMG_Load(const _file: PChar): PSDL_Surface; cdecl; external SDL_ImageLibName;
  1260 function  IMG_Load(const _file: PChar): PSDL_Surface; cdecl; external SDL_ImageLibName;
  1051 function  IMG_Load_RW(rwop: PSDL_RWops; freesrc: LongInt): PSDL_Surface; cdecl; external SDL_ImageLibName;
  1261 function  IMG_Load_RW(rwop: PSDL_RWops; freesrc: LongBool): PSDL_Surface; cdecl; external SDL_ImageLibName;
  1052 function  IMG_LoadPNG_RW(rwop: PSDL_RWops): PSDL_Surface; cdecl; external SDL_ImageLibName;
  1262 function  IMG_LoadPNG_RW(rwop: PSDL_RWops): PSDL_Surface; cdecl; external SDL_ImageLibName;
  1053 function  IMG_LoadTyped_RW(rwop: PSDL_RWops; freesrc: LongInt; type_: PChar): PSDL_Surface; cdecl; external SDL_ImageLibName;
  1263 function  IMG_LoadTyped_RW(rwop: PSDL_RWops; freesrc: LongBool; type_: PChar): PSDL_Surface; cdecl; external SDL_ImageLibName;
       
  1264 function IMG_SavePNG(surface: PSDL_Surface; const _file: PChar): LongInt; cdecl; external SDL_ImageLibName;
  1054 
  1265 
  1055 (*  SDL_net  *)
  1266 (*  SDL_net  *)
  1056 function  SDLNet_Init: LongInt; cdecl; external SDL_NetLibName;
  1267 function  SDLNet_Init: LongInt; cdecl; external SDL_NetLibName;
  1057 procedure SDLNet_Quit; cdecl; external SDL_NetLibName;
  1268 procedure SDLNet_Quit; cdecl; external SDL_NetLibName;
  1058 
  1269 
  1065 procedure SDLNet_TCP_Close(sock: PTCPsocket); cdecl; external SDL_NetLibName;
  1276 procedure SDLNet_TCP_Close(sock: PTCPsocket); cdecl; external SDL_NetLibName;
  1066 procedure SDLNet_FreeSocketSet(_set: PSDLNet_SocketSet); cdecl; external SDL_NetLibName;
  1277 procedure SDLNet_FreeSocketSet(_set: PSDLNet_SocketSet); cdecl; external SDL_NetLibName;
  1067 function  SDLNet_AddSocket(_set: PSDLNet_SocketSet; sock: PTCPSocket): LongInt; cdecl; external SDL_NetLibName;
  1278 function  SDLNet_AddSocket(_set: PSDLNet_SocketSet; sock: PTCPSocket): LongInt; cdecl; external SDL_NetLibName;
  1068 function  SDLNet_CheckSockets(_set: PSDLNet_SocketSet; timeout: LongInt): LongInt; cdecl; external SDL_NetLibName;
  1279 function  SDLNet_CheckSockets(_set: PSDLNet_SocketSet; timeout: LongInt): LongInt; cdecl; external SDL_NetLibName;
  1069 
  1280 
       
  1281 // SDL 2 clipboard functions
       
  1282 function SDL_HasClipboardText(): Boolean; cdecl; external SDLLibName;
       
  1283 // returns nil if memory for clipboard contents copy couldn't be allocated
       
  1284 function SDL_GetClipboardText(): PChar; cdecl; external SDLLibName;
       
  1285 // returns 0 on success or negative error number on failure
       
  1286 function SDL_SetClipboardText(const text: PChar): LongInt; cdecl; external SDLLibName;
  1070 
  1287 
  1071 procedure SDLNet_Write16(value: Word; buf: Pointer);
  1288 procedure SDLNet_Write16(value: Word; buf: Pointer);
  1072 procedure SDLNet_Write32(value: LongWord; buf: Pointer);
  1289 procedure SDLNet_Write32(value: LongWord; buf: Pointer);
  1073 function  SDLNet_Read16(buf: Pointer): Word;
  1290 function  SDLNet_Read16(buf: Pointer): Word;
  1074 function  SDLNet_Read32(buf: Pointer): LongWord;
  1291 function  SDLNet_Read32(buf: Pointer): LongWord;
  1075 
  1292 
  1076 implementation
  1293 implementation
  1077 {$IFDEF SDL13}
  1294 uses uStore;
  1078 uses strings, uVariables, uStore;
  1295 
  1079 
  1296 // for sdl1.2 we directly call SDL_WarpMouse()
  1080 // compatible functions
  1297 // for sdl2 we provide a SDL_WarpMouse() which calls the right SDL_WarpMouseInWindow() function
       
  1298 // this has the advantage of reducing 'uses' and 'ifdef' statements
       
  1299 // (SDLwindow is a private member of uStore module)
  1081 procedure SDL_WarpMouse(x, y: Word); inline;
  1300 procedure SDL_WarpMouse(x, y: Word); inline;
  1082 begin
  1301 begin
  1083     WarpMouse(x, y);
  1302     WarpMouse(x, y);
  1084 end;
  1303 end;
  1085 
  1304 
  1086 function SDL_VideoDriverName(namebuf: PChar; maxlen: LongInt): PChar;
       
  1087 var name : PChar = nil;
       
  1088 begin
       
  1089     name:= SDL_GetCurrentVideoDriver();
       
  1090     if (name <> nil) and (namebuf <> nil) then
       
  1091         begin
       
  1092         strlcopy(namebuf, name, maxlen);
       
  1093         SDL_VideoDriverName:= namebuf
       
  1094         end;
       
  1095     SDL_VideoDriverName:= name;
       
  1096 end;
       
  1097 
       
  1098 function SDL_EnableUNICODE(enable: LongInt): LongInt;
       
  1099 begin
       
  1100     enable:= enable; // avoid hint
       
  1101     SDL_StartTextInput();
       
  1102     SDL_EnableUNICODE:= 0;
       
  1103 end;
       
  1104 
       
  1105 function SDL_EnableKeyRepeat(timedelay, interval: LongInt): LongInt;
       
  1106 begin
       
  1107     timedelay:= timedelay;  // avoid hint
       
  1108     interval:= interval;    // avoid hint
       
  1109     SDL_EnableKeyRepeat:= 0;
       
  1110 end;
       
  1111 {$ELSE}
       
  1112 const conversionFormat: TSDL_PixelFormat = (
       
  1113         palette: nil; BitsPerPixel: 32; BytesPerPixel: 4;
       
  1114         Rloss: 0; Gloss: 0; Bloss: 0; Aloss: 0;
       
  1115         Rshift: RShift; Gshift: GShift; Bshift: BShift; Ashift: AShift;
       
  1116         RMask: RMask; GMask: GMask; BMask: BMask; AMask: AMask;
       
  1117         colorkey: 0; alpha: 255);
       
  1118 
       
  1119 function SDL_AllocFormat(format: LongWord): PSDL_PixelFormat;
       
  1120 begin
       
  1121     format:= format;
       
  1122     SDL_AllocFormat:= @conversionFormat;
       
  1123 end;
       
  1124 
       
  1125 procedure SDL_FreeFormat(pixelformat: PSDL_PixelFormat);
       
  1126 begin
       
  1127     pixelformat:= pixelformat;  // avoid hint
       
  1128 end;
       
  1129 {$ENDIF}
       
  1130 
       
  1131 function SDL_MustLock(Surface: PSDL_Surface): Boolean;
  1305 function SDL_MustLock(Surface: PSDL_Surface): Boolean;
  1132 begin
  1306 begin
  1133     SDL_MustLock:=
  1307     SDL_MustLock:=
  1134 {$IFDEF SDL13}
       
  1135         ((surface^.flags and SDL_RLEACCEL) <> 0)
  1308         ((surface^.flags and SDL_RLEACCEL) <> 0)
  1136 {$ELSE}
       
  1137         ( surface^.offset <> 0 ) or (( surface^.flags and (SDL_HWSURFACE or SDL_ASYNCBLIT or SDL_RLEACCEL)) <> 0)
       
  1138 {$ENDIF}
       
  1139 end;
  1309 end;
  1140 
       
  1141 {$IFNDEF SDL_MIXER_NEWER}
       
  1142 function  Mix_Init(flags: LongInt): LongInt;
       
  1143 begin
       
  1144     Mix_Init:= flags;
       
  1145 end;
       
  1146 
       
  1147 procedure Mix_Quit;
       
  1148 begin
       
  1149 end;
       
  1150 {$ENDIF}
       
  1151 
       
  1152 {$IFNDEF SDL_IMAGE_NEWER}
       
  1153 function  IMG_Init(flags: LongInt): LongInt;
       
  1154 begin
       
  1155     IMG_Init:= flags;
       
  1156 end;
       
  1157 
       
  1158 procedure IMG_Quit;
       
  1159 begin
       
  1160 end;
       
  1161 {$ENDIF}
       
  1162 
  1310 
  1163 procedure SDLNet_Write16(value: Word; buf: Pointer);
  1311 procedure SDLNet_Write16(value: Word; buf: Pointer);
  1164 begin
  1312 begin
  1165     PByteArray(buf)^[1]:= value;
  1313     PByteArray(buf)^[1]:= value;
  1166     PByteArray(buf)^[0]:= value shr 8
  1314     PByteArray(buf)^[0]:= value shr 8
  1186                   (PByteArray(buf)^[2] shl  8) or
  1334                   (PByteArray(buf)^[2] shl  8) or
  1187                   (PByteArray(buf)^[1] shl 16) or
  1335                   (PByteArray(buf)^[1] shl 16) or
  1188                   (PByteArray(buf)^[0] shl 24)
  1336                   (PByteArray(buf)^[0] shl 24)
  1189 end;
  1337 end;
  1190 
  1338 
       
  1339 {$IFDEF WINDOWS}
       
  1340 function  SDL_CreateThread(fn: Pointer; name: PChar; data: Pointer): PSDL_Thread; cdecl;
       
  1341 begin
       
  1342     SDL_CreateThread:= SDL_CreateThread(fn, name, data, nil, nil)
       
  1343 end;  
       
  1344 {$ENDIF}
       
  1345 
  1191 end.
  1346 end.
  1192 
  1347