Wrap TTF_Font with a few calls
[sdlgit/SDL_perl.git] / src / SDL.xs
1 //
2 // SDL.xs
3 //
4 // Copyright (C) 2005 David J. Goehrig <dgoehrig@cpan.org>
5 //
6 // ------------------------------------------------------------------------------
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // 
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // Lesser General Public License for more details.
17 // 
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21 //
22 // ------------------------------------------------------------------------------
23 //
24 // Please feel free to send questions, suggestions or improvements to:
25 //
26 //      David J. Goehrig
27 //      dgoehrig@cpan.org
28 //
29
30 #include "EXTERN.h"
31 #include "perl.h"
32 #include "XSUB.h"
33
34 #ifndef aTHX_
35 #define aTHX_
36 #endif
37
38 #include <SDL.h>
39
40 #ifdef HAVE_GL
41 #include <gl.h>
42 #endif
43
44 #ifdef HAVE_GLU
45 #include <glu.h>
46 #endif
47
48 #ifdef HAVE_SDL_IMAGE
49 #include <SDL_image.h>
50 #endif 
51
52 #ifdef HAVE_SDL_MIXER
53 #include <SDL_mixer.h>
54 void (*mix_music_finished_cv)();
55 #endif
56
57 #ifdef HAVE_SDL_SOUND
58 #include <SDL_sound.h>
59 #endif
60
61 #ifdef HAVE_SDL_NET
62 #include <SDL_net.h>
63 #endif
64
65 #ifdef HAVE_SMPEG
66 #include <smpeg/smpeg.h>
67 #ifdef HAVE_SDL_MIXER
68 static int sdl_perl_use_smpeg_audio = 0;
69 #endif
70 #endif
71
72 #ifdef HAVE_SDL_GFX
73 #include <SDL_rotozoom.h>
74 #include <SDL_gfxPrimitives.h>
75 #include <SDL_framerate.h>
76 #include <SDL_imageFilter.h>
77 #endif
78
79 #ifdef HAVE_SDL_SVG
80 #include <SDL_svg.h>
81 #endif
82
83 #ifdef HAVE_SDL_TTF
84 #include <SDL_ttf.h>
85 #endif
86
87 #ifdef USE_THREADS
88 #define HAVE_TLS_CONTEXT
89 #endif
90
91 /* For windows  */
92 #ifndef SDL_PERL_DEFINES_H
93 #define SDL_PERL_DEFINES_H
94
95 #ifdef HAVE_TLS_CONTEXT
96 PerlInterpreter *parent_perl = NULL;
97 extern PerlInterpreter *parent_perl;
98 #define GET_TLS_CONTEXT parent_perl =  PERL_GET_CONTEXT;
99 #define ENTER_TLS_CONTEXT \
100         PerlInterpreter *current_perl = PERL_GET_CONTEXT; \
101                 PERL_SET_CONTEXT(parent_perl); { \
102                                         PerlInterpreter *my_perl = parent_perl;
103 #define LEAVE_TLS_CONTEXT \
104                                                 } PERL_SET_CONTEXT(current_perl);
105 #else
106 #define GET_TLS_CONTEXT         /* TLS context not enabled */
107 #define ENTER_TLS_CONTEXT       /* TLS context not enabled */
108 #define LEAVE_TLS_CONTEXT       /* TLS context not enabled */
109 #endif
110
111 #endif
112
113 Uint32 
114 sdl_perl_timer_callback ( Uint32 interval, void* param )
115 {
116         Uint32 retval;
117         int back;
118         SV* cmd;
119         ENTER_TLS_CONTEXT
120         dSP;
121
122         cmd = (SV*)param;
123
124         ENTER;
125         SAVETMPS;
126         PUSHMARK(SP);
127         XPUSHs(sv_2mortal(newSViv(interval)));
128         PUTBACK;
129
130         if (0 != (back = call_sv(cmd,G_SCALAR))) {
131                 SPAGAIN;
132                 if (back != 1 ) Perl_croak (aTHX_ "Timer Callback failed!");
133                 retval = POPi;  
134         } else {
135                 Perl_croak(aTHX_ "Timer Callback failed!");
136         }
137
138         FREETMPS;
139         LEAVE;
140
141         LEAVE_TLS_CONTEXT
142         
143         return retval;
144 }
145
146 void
147 sdl_perl_audio_callback ( void* data, Uint8 *stream, int len )
148 {
149         SV *cmd;
150         ENTER_TLS_CONTEXT
151         dSP;
152
153         cmd = (SV*)data;
154
155         ENTER;
156         SAVETMPS;
157         PUSHMARK(SP);
158         XPUSHs(sv_2mortal(newSViv(PTR2IV(stream))));
159         XPUSHs(sv_2mortal(newSViv(len)));
160         PUTBACK;
161
162         call_sv(cmd,G_VOID|G_DISCARD);
163         
164         PUTBACK;
165         FREETMPS;
166         LEAVE;
167
168         LEAVE_TLS_CONTEXT       
169 }
170
171 #ifdef HAVE_SDL_MIXER
172
173 void
174 sdl_perl_music_callback ( void ) 
175 {
176         SV *cmd;
177         ENTER_TLS_CONTEXT
178         dSP;
179
180         cmd = (SV*)Mix_GetMusicHookData();
181
182         ENTER;
183         SAVETMPS;
184         PUSHMARK(SP);
185         PUTBACK;
186         
187         call_sv(cmd,G_VOID|G_DISCARD);
188
189         PUTBACK;
190         FREETMPS;
191         LEAVE;
192
193         LEAVE_TLS_CONTEXT
194 }
195
196 void
197 sdl_perl_music_finished_callback ( void )
198 {
199         SV *cmd;
200         ENTER_TLS_CONTEXT
201         dSP;
202
203         cmd = (SV*)mix_music_finished_cv;
204         if ( cmd == NULL ) return;
205
206         ENTER;
207         SAVETMPS;
208         PUSHMARK(SP);
209         PUTBACK;
210         
211         call_sv(cmd,G_VOID|G_DISCARD);
212         
213         PUTBACK;
214         FREETMPS;
215         LEAVE;
216
217         LEAVE_TLS_CONTEXT
218 }
219
220 #endif
221
222 #define INIT_NS_APPLICATION
223 #define QUIT_NS_APPLICATION
224
225
226 void
227 sdl_perl_atexit (void)
228 {
229         QUIT_NS_APPLICATION     
230         SDL_Quit();
231 }
232
233 void boot_SDL();
234 void boot_SDL__OpenGL();
235
236 XS(boot_SDL_perl)
237 {
238         GET_TLS_CONTEXT
239         boot_SDL();
240 }
241
242 MODULE = SDL_perl       PACKAGE = SDL
243 PROTOTYPES : DISABLE
244
245 char *
246 GetError ()
247         CODE:
248                 RETVAL = SDL_GetError();
249         OUTPUT:
250                 RETVAL
251
252 int
253 Init ( flags )
254         Uint32 flags
255         CODE:
256                 INIT_NS_APPLICATION
257                 RETVAL = SDL_Init(flags);
258 #ifdef HAVE_TLS_CONTEXT
259                 Perl_call_atexit(PERL_GET_CONTEXT, (void*)sdl_perl_atexit,0);
260 #else
261                 atexit(sdl_perl_atexit);
262 #endif
263         OUTPUT:
264                 RETVAL
265
266 int
267 InitSubSystem ( flags )
268         Uint32 flags
269         CODE:
270                 RETVAL = SDL_InitSubSystem(flags);
271         OUTPUT:
272                 RETVAL
273
274 void
275 QuitSubSystem ( flags )
276         Uint32 flags
277         CODE:
278                 SDL_QuitSubSystem(flags);
279
280 void
281 Quit ()
282         CODE:
283                 QUIT_NS_APPLICATION
284                 SDL_Quit();
285
286 int
287 WasInit ( flags )
288         Uint32 flags
289         CODE:
290                 RETVAL = SDL_WasInit(flags);
291         OUTPUT:
292                 RETVAL
293
294 void
295 Delay ( ms )
296         int ms
297         CODE:
298                 SDL_Delay(ms);
299
300 Uint32
301 GetTicks ()
302         CODE:
303                 RETVAL = SDL_GetTicks();
304         OUTPUT:
305                 RETVAL
306
307 int
308 SetTimer ( interval, callback )
309         Uint32 interval
310         SDL_TimerCallback callback
311         CODE:
312                 RETVAL = SDL_SetTimer(interval,callback);
313         OUTPUT:
314                 RETVAL
315
316 SDL_TimerID
317 AddTimer ( interval, callback, param )
318         Uint32 interval
319         SDL_NewTimerCallback callback
320         void *param
321         CODE:
322                 RETVAL = SDL_AddTimer(interval,callback,param);
323         OUTPUT:
324                 RETVAL
325
326 SDL_NewTimerCallback
327 PerlTimerCallback ()
328         CODE:
329                 RETVAL = sdl_perl_timer_callback;
330         OUTPUT:
331                 RETVAL  
332
333 SDL_TimerID
334 NewTimer ( interval, cmd )
335         Uint32 interval
336         void *cmd
337         CODE:
338                 RETVAL = SDL_AddTimer(interval,sdl_perl_timer_callback,cmd);
339         OUTPUT:
340                 RETVAL
341
342 Uint32
343 RemoveTimer ( id )
344         SDL_TimerID id
345         CODE:
346                 RETVAL = SDL_RemoveTimer(id);
347         OUTPUT:
348                 RETVAL
349
350 SDL_RWops*
351 RWFromFile ( file, mode )
352         char* file
353         char * mode
354         CODE:
355                 RETVAL = SDL_RWFromFile(file,mode);
356         OUTPUT:
357                 RETVAL
358
359 SDL_RWops*
360 RWFromFP ( fp, autoclose )
361         FILE* fp
362         int autoclose
363         CODE:
364                 RETVAL = SDL_RWFromFP(fp,autoclose);
365         OUTPUT:
366                 RETVAL
367
368 SDL_RWops*
369 RWFromMem ( mem, size )
370         char* mem
371         int size
372         CODE:
373                 RETVAL = SDL_RWFromMem((void*)mem,size);
374         OUTPUT:
375                 RETVAL
376
377 SDL_RWops*
378 RWFromConstMem ( mem, size )
379         const char* mem
380         int size
381         CODE:
382                 RETVAL = SDL_RWFromConstMem((const void*)mem,size);
383         OUTPUT:
384                 RETVAL
385
386 SDL_RWops*
387 AllocRW ()
388         CODE:
389                 RETVAL = SDL_AllocRW();
390         OUTPUT:
391                 RETVAL
392
393 void
394 FreeRW ( rw )
395         SDL_RWops* rw
396         CODE:
397                 SDL_FreeRW(rw);
398
399 int
400 RWseek ( rw, off, whence )
401         SDL_RWops* rw
402         int off
403         int whence
404         CODE:
405                 RETVAL = SDL_RWseek(rw,off,whence);
406         OUTPUT:
407                 RETVAL
408
409 int
410 RWtell ( rw )
411         SDL_RWops* rw
412         CODE:
413                 RETVAL = SDL_RWtell(rw);
414         OUTPUT:
415                 RETVAL
416
417 int
418 RWread ( rw, mem, size, n )
419         SDL_RWops* rw
420         char* mem
421         int size
422         int n
423         CODE:
424                 RETVAL = SDL_RWread(rw,mem,size,n);
425         OUTPUT:
426                 RETVAL
427
428 int
429 RWwrite ( rw, mem, size, n )
430         SDL_RWops* rw
431         char* mem
432         int size
433         int n
434         CODE:
435                 RETVAL = SDL_RWwrite(rw,mem,size,n);
436         OUTPUT:
437                 RETVAL
438
439 int
440 RWclose ( rw )
441         SDL_RWops* rw
442         CODE:
443                 RETVAL = SDL_RWclose(rw);
444         OUTPUT:
445                 RETVAL
446
447 int
448 CDNumDrives ()
449         CODE:
450                 RETVAL = SDL_CDNumDrives();
451         OUTPUT:
452                 RETVAL
453
454 char *
455 CDName ( drive )
456         int drive
457         CODE:
458                 RETVAL = strdup(SDL_CDName(drive));
459         OUTPUT:
460                 RETVAL
461
462 SDL_CD *
463 CDOpen ( drive )
464         int drive
465         CODE:
466                 RETVAL = SDL_CDOpen(drive);
467         OUTPUT:
468                 RETVAL
469
470 Uint8
471 CDTrackId ( track )
472         SDL_CDtrack *track
473         CODE:
474                 RETVAL = track->id;
475         OUTPUT:
476                 RETVAL
477
478 Uint8
479 CDTrackType ( track )
480         SDL_CDtrack *track
481         CODE:
482                 RETVAL = track->type;
483         OUTPUT:
484                 RETVAL
485
486 Uint16
487 CDTrackLength ( track )
488         SDL_CDtrack *track
489         CODE:
490                 RETVAL = track->length;
491         OUTPUT:
492                 RETVAL
493
494 Uint32
495 CDTrackOffset ( track )
496         SDL_CDtrack *track
497         CODE:
498                 RETVAL = track->offset;
499         OUTPUT: 
500                 RETVAL
501
502 Uint32
503 CDStatus ( cd )
504         SDL_CD *cd 
505         CODE:
506                 RETVAL = SDL_CDStatus(cd);
507         OUTPUT:
508                 RETVAL
509
510 int
511 CDPlayTracks ( cd, start_track, ntracks, start_frame, nframes )
512         SDL_CD *cd
513         int start_track
514         int ntracks
515         int start_frame
516         int nframes
517         CODE:
518                 RETVAL = SDL_CDPlayTracks(cd,start_track,start_frame,ntracks,nframes);
519         OUTPUT:
520                 RETVAL
521
522 int
523 CDPlay ( cd, start, length )
524         SDL_CD *cd
525         int start
526         int length
527         CODE:
528                 RETVAL = SDL_CDPlay(cd,start,length);
529         OUTPUT:
530                 RETVAL
531
532 int
533 CDPause ( cd )
534         SDL_CD *cd
535         CODE:
536                 RETVAL = SDL_CDPause(cd);
537         OUTPUT:
538                 RETVAL
539
540 int
541 CDResume ( cd )
542         SDL_CD *cd
543         CODE:
544                 RETVAL = SDL_CDResume(cd);
545         OUTPUT:
546                 RETVAL
547
548 int
549 CDStop ( cd )
550         SDL_CD *cd
551         CODE:
552                 RETVAL = SDL_CDStop(cd);
553         OUTPUT:
554                 RETVAL
555
556 int
557 CDEject ( cd )
558         SDL_CD *cd
559         CODE:
560                 RETVAL = SDL_CDEject(cd);
561         OUTPUT:
562                 RETVAL
563
564 void
565 CDClose ( cd )
566         SDL_CD *cd
567         CODE:
568                 SDL_CDClose(cd);
569         
570 int
571 CDId ( cd )
572         SDL_CD *cd
573         CODE:
574                 RETVAL = cd->id;
575         OUTPUT: 
576                 RETVAL
577
578 int
579 CDNumTracks ( cd )
580         SDL_CD *cd
581         CODE:
582                 RETVAL = cd->numtracks;
583         OUTPUT:
584                 RETVAL
585
586 int
587 CDCurTrack ( cd )
588         SDL_CD *cd
589         CODE:
590                 RETVAL = cd->cur_track;
591         OUTPUT:
592                 RETVAL
593
594 int
595 CDCurFrame ( cd )
596         SDL_CD *cd
597         CODE:
598                 RETVAL = cd->cur_frame;
599         OUTPUT:
600                 RETVAL
601
602 SDL_CDtrack *
603 CDTrack ( cd, number )
604         SDL_CD *cd
605         int number
606         CODE:
607                 RETVAL = (SDL_CDtrack *)(cd->track + number);
608         OUTPUT:
609                 RETVAL
610
611 void
612 PumpEvents ()
613         CODE:
614                 SDL_PumpEvents();
615
616 int
617 PushEvent( e )
618         SDL_Event *e
619         CODE:
620                 RETVAL = SDL_PushEvent( e );
621         OUTPUT:
622                 RETVAL
623
624 SDL_Event *
625 NewEvent ()
626         CODE:   
627                 RETVAL = (SDL_Event *) safemalloc (sizeof(SDL_Event));
628         OUTPUT:
629                 RETVAL
630
631 void
632 FreeEvent ( e )
633         SDL_Event *e
634         CODE:
635                 safefree(e);
636
637 int
638 PollEvent ( e )
639         SDL_Event *e
640         CODE:
641                 RETVAL = SDL_PollEvent(e);
642         OUTPUT:
643                 RETVAL
644
645 int
646 WaitEvent ( e )
647         SDL_Event *e
648         CODE:
649                 RETVAL = SDL_WaitEvent(e);
650         OUTPUT:
651                 RETVAL
652
653 Uint8
654 EventState ( type, state )
655         Uint8 type
656         int state
657         CODE:
658                 RETVAL = SDL_EventState(type,state);
659         OUTPUT:
660                 RETVAL 
661
662 Uint8
663 EventType ( e )
664         SDL_Event *e
665         CODE:
666                 RETVAL = e->type;
667         OUTPUT:
668                 RETVAL
669
670 Uint8
671 SetEventType ( e, type )
672         SDL_Event *e
673         Uint8 type
674         CODE:
675                 RETVAL = e->type;
676                 e->type = type;
677         OUTPUT:
678                 RETVAL
679
680 Uint8
681 ActiveEventGain ( e )
682         SDL_Event *e
683         CODE:
684                 RETVAL = e->active.gain;
685         OUTPUT: 
686                 RETVAL
687
688 Uint8
689 ActiveEventState ( e )
690         SDL_Event *e
691         CODE:
692                 RETVAL = e->active.state;
693         OUTPUT:
694                 RETVAL
695
696 Uint8
697 KeyEventState( e )
698         SDL_Event *e
699         CODE:
700                 RETVAL = e->key.state;
701         OUTPUT:
702                 RETVAL
703
704 int
705 KeyEventSym ( e )
706         SDL_Event *e
707         CODE:
708                 RETVAL = e->key.keysym.sym;
709         OUTPUT:
710                 RETVAL
711
712 int 
713 KeyEventMod ( e )
714         SDL_Event *e
715         CODE:
716                 RETVAL = e->key.keysym.mod;
717         OUTPUT:
718                 RETVAL
719
720 Uint16
721 KeyEventUnicode ( e )
722         SDL_Event *e
723         CODE:
724                 RETVAL = e->key.keysym.unicode;
725         OUTPUT:
726                 RETVAL
727
728 Uint8
729 KeyEventScanCode ( e )
730         SDL_Event *e
731         CODE:
732                 RETVAL = e->key.keysym.scancode;
733         OUTPUT:
734                 RETVAL
735
736 Uint8
737 MouseMotionState ( e )
738         SDL_Event *e
739         CODE:
740                 RETVAL = e->motion.state;
741         OUTPUT: 
742                 RETVAL
743
744 Uint16
745 MouseMotionX ( e )
746         SDL_Event *e
747         CODE:
748                 RETVAL = e->motion.x;
749         OUTPUT:
750                 RETVAL
751
752 Uint16
753 MouseMotionY ( e )
754         SDL_Event *e
755         CODE:
756                 RETVAL = e->motion.y;
757         OUTPUT:
758                 RETVAL
759
760 Sint16
761 MouseMotionXrel( e )
762         SDL_Event *e
763         CODE:
764                 RETVAL = e->motion.xrel;
765         OUTPUT:
766                 RETVAL
767
768 Sint16
769 MouseMotionYrel ( e )
770         SDL_Event *e
771         CODE:
772                 RETVAL = e->motion.yrel;
773         OUTPUT:
774                 RETVAL
775
776 Uint8
777 MouseButtonState ( e )
778         SDL_Event *e
779         CODE:
780                 RETVAL = e->button.state;
781         OUTPUT:
782                 RETVAL
783
784 Uint8
785 MouseButton ( e )
786         SDL_Event *e
787         CODE:
788                 RETVAL = e->button.button;
789         OUTPUT:
790                 RETVAL
791
792 Uint16
793 MouseButtonX ( e )
794         SDL_Event *e
795         CODE:
796                 RETVAL = e->button.x;
797         OUTPUT:
798                 RETVAL
799
800 Uint16
801 MouseButtonY ( e )
802         SDL_Event *e
803         CODE:
804                 RETVAL = e->button.y;
805         OUTPUT:
806                 RETVAL
807
808 SDL_SysWMmsg *
809 SysWMEventMsg ( e )
810         SDL_Event *e
811         CODE:
812                 RETVAL = e->syswm.msg;
813         OUTPUT:
814                 RETVAL
815
816 int
817 EnableUnicode ( enable )
818         int enable
819         CODE:
820                 RETVAL = SDL_EnableUNICODE(enable);
821         OUTPUT:
822                 RETVAL
823
824 void
825 EnableKeyRepeat ( delay, interval )
826         int delay
827         int interval
828         CODE:
829                 SDL_EnableKeyRepeat(delay,interval);
830
831 Uint32
832 GetModState ()
833         CODE:
834                 RETVAL = SDL_GetModState();
835         OUTPUT:
836                 RETVAL
837
838 void
839 SetModState ( state )
840         Uint32 state
841         CODE:
842                 SDL_SetModState(state);
843
844 char *
845 GetKeyName ( sym )
846         int sym
847         CODE:
848                 RETVAL = SDL_GetKeyName(sym);
849         OUTPUT:
850                 RETVAL
851
852 #ifdef HAVE_SDL_IMAGE
853
854 SDL_Surface *
855 IMG_Load ( filename )
856         char *filename
857         CODE:
858                 char* CLASS = "SDL::Surface";
859                 RETVAL = IMG_Load(filename);
860         OUTPUT:
861                 RETVAL
862
863 #endif
864
865 =for comment
866
867 Comment out for now as it does not compile
868
869 SDL_Surface *
870 CreateRGBSurfaceFrom (pixels, width, height, depth, pitch, Rmask, Gmask, Bmask, Amask )
871         char *pixels
872         int width
873         int height
874         int depth
875         int pitch
876         Uint32 Rmask
877         Uint32 Gmask
878         Uint32 Bmask
879         Uint32 Amask
880         CODE:
881                 Uint8* pixeldata;
882                 Uint32 len = pitch * height;
883                 New(0,pixeldata,len,Uint8);
884                 Copy(pixels,pixeldata,len,Uint8);
885                 RETVAL = SDL_CreateRGBSurfaceFrom ( pixeldata, width, height,
886                                 depth, pitch, Rmask, Gmask, Bmask, Amask );
887         OUTPUT: 
888                 RETVAL
889
890 SDL_Surface*
891 SurfaceCopy ( surface )
892         SDL_Surface *surface
893         CODE:
894                 Uint8* pixels;
895                 Uint32 size = surface->pitch * surface->h;
896                 New(0,pixels,size,Uint8);
897                 Copy(surface->pixels,pixels,size,Uint8);
898                 RETVAL = SDL_CreateRGBSurfaceFrom(pixels,surface->w,surface->h,
899                         surface->format->BitsPerPixel, surface->pitch,
900                         surface->format->Rmask, surface->format->Gmask,
901                         surface->format->Bmask, surface->format->Amask);
902         OUTPUT:
903                 RETVAL
904
905 void
906 FreeSurface ( surface )
907         SDL_Surface *surface
908         CODE:
909                 if (surface) {
910                         Uint8* pixels = surface->pixels;
911                         Uint32 flags = surface->flags;
912                         SDL_FreeSurface(surface);
913                         if (flags & SDL_PREALLOC)
914                                 Safefree(pixels);
915                 }
916         
917 Uint32
918 SurfaceFlags ( surface )
919         SDL_Surface *surface
920         CODE:
921                 RETVAL = surface->flags;
922         OUTPUT:
923                 RETVAL
924
925 SDL_Palette *
926 SurfacePalette ( surface )
927         SDL_Surface *surface
928         CODE:
929                 RETVAL = surface->format->palette;
930         OUTPUT:
931                 RETVAL
932
933 Uint8
934 SurfaceBitsPerPixel ( surface )
935         SDL_Surface *surface
936         CODE:
937                 RETVAL = surface->format->BitsPerPixel;
938         OUTPUT:
939                 RETVAL
940
941 Uint8
942 SurfaceBytesPerPixel ( surface )
943         SDL_Surface *surface
944         CODE:   
945                 RETVAL = surface->format->BytesPerPixel;
946         OUTPUT:
947                 RETVAL
948
949 Uint8
950 SurfaceRshift ( surface )
951         SDL_Surface *surface
952         CODE:
953                 RETVAL = surface->format->Rshift;
954         OUTPUT:
955                 RETVAL
956
957 Uint8
958 SurfaceGshift ( surface )
959         SDL_Surface *surface
960         CODE:
961                 RETVAL = surface->format->Gshift;
962         OUTPUT:
963                 RETVAL
964
965 Uint8
966 SurfaceBshift ( surface )
967         SDL_Surface *surface
968         CODE:
969                 RETVAL = surface->format->Bshift;
970         OUTPUT:
971                 RETVAL
972
973 Uint8
974 SurfaceAshift ( surface )
975         SDL_Surface *surface
976         CODE:
977                 RETVAL = surface->format->Ashift;
978         OUTPUT:
979                 RETVAL
980
981 Uint32
982 SurfaceRmask( surface )
983         SDL_Surface *surface
984         CODE:
985                 RETVAL = surface->format->Rmask;
986         OUTPUT:
987                 RETVAL
988
989 Uint32
990 SurfaceGmask ( surface )
991         SDL_Surface *surface
992         CODE:
993                 RETVAL = surface->format->Gmask;
994         OUTPUT:
995                 RETVAL
996
997 Uint32
998 SurfaceBmask ( surface )
999         SDL_Surface *surface
1000         CODE:
1001                 RETVAL = surface->format->Bmask;
1002         OUTPUT:
1003                 RETVAL
1004
1005 Uint32
1006 SurfaceAmask ( surface )
1007         SDL_Surface *surface
1008         CODE:
1009                 RETVAL = surface->format->Amask;
1010         OUTPUT:
1011                 RETVAL
1012
1013 Uint32
1014 SurfaceColorKey ( surface )
1015         SDL_Surface *surface
1016         CODE:
1017                 RETVAL = surface->format->colorkey;
1018         OUTPUT:
1019                 RETVAL
1020
1021 Uint32
1022 SurfaceAlpha( surface )
1023         SDL_Surface *surface
1024         CODE:
1025                 RETVAL = surface->format->alpha;
1026         OUTPUT:
1027                 RETVAL
1028
1029 int
1030 SurfaceW ( surface )
1031         SDL_Surface *surface
1032         CODE:   
1033                 RETVAL = surface->w;
1034         OUTPUT:
1035                 RETVAL
1036
1037 int
1038 SurfaceH ( surface )
1039         SDL_Surface *surface
1040         CODE:   
1041                 RETVAL = surface->h;
1042         OUTPUT:
1043                 RETVAL
1044
1045 Uint16
1046 SurfacePitch ( surface )
1047         SDL_Surface *surface
1048         CODE:   
1049                 RETVAL = surface->pitch;
1050         OUTPUT:
1051                 RETVAL
1052
1053 SV*
1054 SurfacePixels ( surface )
1055         SDL_Surface *surface
1056         CODE:   
1057                 RETVAL = newSVpvn(surface->pixels,surface->pitch*surface->h);
1058         OUTPUT:
1059                 RETVAL
1060
1061 =cut
1062
1063 =for comment
1064
1065 Comment out for now as it does not compile
1066
1067 SDL_Color*
1068 SurfacePixel ( surface, x, y, ... )
1069         SDL_Surface *surface
1070         Sint32 x
1071         Sint32 y
1072         CODE:
1073                 SDL_Color* color;
1074                 int pix,index;
1075                 Uint8 r,g,b,a;
1076                 int bpp = surface->format->BytesPerPixel;
1077                 Uint8* p = (Uint8*)surface->pixels + bpp*x + surface->pitch*y;
1078                 if ( items < 3 || items > 4 ) 
1079                         Perl_croak(aTHX_ "usage: SDL::SurfacePixel(surface,x,y,[color])");
1080                 if ( items == 4) {
1081                         color = (SDL_Color*)SvIV(ST(3));
1082                         pix = SDL_MapRGB(surface->format,color->r,color->g,color->b);
1083                         switch(bpp) {
1084                                 case 1:
1085                                         *(Uint8*)p = pix;
1086                                         break;
1087                                 case 2:
1088                                         *(Uint16*)p = pix;
1089                                         break;
1090                                 case 3:
1091                                         if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
1092                                                 p[0] = (pix >> 16) & 0xff;
1093                                                 p[1] = (pix >> 8) & 0xff;
1094                                                 p[2] = pix & 0xff;
1095                                         } else {
1096                                                 p[0] = pix & 0xff;
1097                                                 p[1] = (pix >> 8) & 0xff;
1098                                                 p[2] = (pix >> 16) & 0xff;
1099                                         }
1100                                         break;
1101                                 case 4:
1102                                         *(Uint32*)p = pix;
1103                                         break;
1104                         }
1105                 }
1106                 RETVAL = (SDL_Color *) safemalloc(sizeof(SDL_Color));
1107                 switch(bpp) {
1108                         case 1:
1109                                 index = *(Uint8*)p;
1110                                 memcpy(RETVAL,&surface->format->palette[index],sizeof(SDL_Color));
1111                                 break;
1112                         case 2:
1113                                 pix = *(Uint16*)p;
1114                                 SDL_GetRGB(pix,surface->format,&r,&g,&b);
1115                                 RETVAL->r = r;
1116                                 RETVAL->g = g;
1117                                 RETVAL->b = b;
1118                                 break;
1119                         case 3:
1120                         case 4:
1121                                 pix = *(Uint32*)p;
1122                                 SDL_GetRGB(pix,surface->format,&r,&g,&b);
1123                                 RETVAL->r = r;
1124                                 RETVAL->g = g;
1125                                 RETVAL->b = b;
1126                                 break;
1127                 }
1128         OUTPUT:
1129                 RETVAL
1130
1131 int
1132 MUSTLOCK ( surface )
1133         SDL_Surface *surface
1134         CODE:
1135                 RETVAL = SDL_MUSTLOCK(surface);
1136         OUTPUT:
1137                 RETVAL          
1138
1139 int
1140 SurfaceLock ( surface )
1141         SDL_Surface *surface
1142         CODE:
1143                 RETVAL = SDL_LockSurface(surface);
1144         OUTPUT:
1145                 RETVAL
1146
1147 void
1148 SurfaceUnlock ( surface )
1149         SDL_Surface *surface
1150         CODE:
1151                 SDL_UnlockSurface(surface);
1152
1153 SDL_Surface *
1154 GetVideoSurface ()
1155         CODE:
1156                 RETVAL = SDL_GetVideoSurface();
1157         OUTPUT:
1158                 RETVAL
1159
1160 =cut
1161
1162 HV *
1163 VideoInfo ()
1164         CODE:
1165                 HV *hv;
1166                 SDL_VideoInfo *info;
1167                 info = (SDL_VideoInfo *) safemalloc ( sizeof(SDL_VideoInfo));
1168                 memcpy(info,SDL_GetVideoInfo(),sizeof(SDL_VideoInfo));
1169                 hv = newHV();
1170                 hv_store(hv,"hw_available",strlen("hw_available"),
1171                         newSViv(info->hw_available),0);
1172                 hv_store(hv,"wm_available",strlen("wm_available"),
1173                         newSViv(info->wm_available),0);
1174                 hv_store(hv,"blit_hw",strlen("blit_hw"),
1175                         newSViv(info->blit_hw),0);
1176                 hv_store(hv,"blit_hw_CC",strlen("blit_hw_CC"),
1177                         newSViv(info->blit_hw_CC),0);
1178                 hv_store(hv,"blit_hw_A",strlen("blit_hw_A"),
1179                         newSViv(info->blit_hw_A),0);
1180                 hv_store(hv,"blit_sw",strlen("blit_sw"),
1181                         newSViv(info->blit_sw),0);
1182                 hv_store(hv,"blit_sw_CC",strlen("blit_sw_CC"),
1183                         newSViv(info->blit_sw_CC),0);
1184                 hv_store(hv,"blit_sw_A",strlen("blit_sw_A"),
1185                         newSViv(info->blit_sw_A),0);
1186                 hv_store(hv,"blit_fill",strlen("blit_fill"),
1187                         newSViv(info->blit_fill),0);
1188                 hv_store(hv,"video_mem",strlen("video_mem"),
1189                         newSViv(info->video_mem),0);
1190                 RETVAL = hv;
1191         OUTPUT:
1192                 RETVAL
1193
1194 AV*
1195 ListModes ( format, flags )
1196         Uint32 flags
1197         SDL_PixelFormat *format
1198         CODE:
1199                 SDL_Rect **mode;
1200                 RETVAL = newAV();
1201                 mode = SDL_ListModes(format,flags);
1202                 if (mode == (SDL_Rect**)-1 ) {
1203                         av_push(RETVAL,newSVpv("all",0));
1204                 } else if (! mode ) {
1205                         av_push(RETVAL,newSVpv("none",0));
1206                 } else {
1207                         for (;*mode;mode++) {
1208                                 av_push(RETVAL,newSViv(PTR2IV(*mode)));
1209                         }
1210                 }
1211         OUTPUT:
1212                 RETVAL
1213
1214 SDL_Palette *
1215 NewPalette ( number )
1216         int number
1217         CODE:
1218                 RETVAL = (SDL_Palette *)safemalloc(sizeof(SDL_Palette));
1219                 RETVAL->colors = (SDL_Color *)safemalloc(number * 
1220                                                 sizeof(SDL_Color));
1221                 RETVAL->ncolors = number;
1222         OUTPUT:
1223                 RETVAL
1224
1225 int
1226 PaletteNColors ( palette, ... )
1227         SDL_Palette *palette
1228         CODE:
1229                 if ( items > 1 ) palette->ncolors = SvIV(ST(1));
1230                 RETVAL = palette->ncolors;
1231         OUTPUT:
1232                 RETVAL
1233
1234 SDL_Surface *
1235 SetVideoMode ( width, height, bpp, flags )
1236
1237         int width
1238         int height
1239         int bpp
1240         Uint32 flags
1241
1242         CODE:
1243                 char *CLASS = "SDL::Surface";
1244                 RETVAL = SDL_SetVideoMode(width,height,bpp,flags);
1245         OUTPUT:
1246                 RETVAL
1247
1248 int
1249 Flip ( surface )
1250         SDL_Surface *surface
1251         CODE:
1252                 RETVAL = SDL_Flip(surface);
1253         OUTPUT:
1254                 RETVAL
1255
1256 int
1257 BlitSurface ( src, src_rect, dest, dest_rect )
1258         SDL_Surface *src
1259         SDL_Surface *dest
1260         SDL_Rect *src_rect
1261         SDL_Rect *dest_rect
1262         CODE:
1263                 RETVAL = SDL_BlitSurface(src,src_rect,dest,dest_rect);
1264         OUTPUT:
1265                 RETVAL
1266
1267 Uint32
1268 MapRGB ( pixel_format, r, g, b )
1269         SDL_PixelFormat *pixel_format
1270         Uint8 r
1271         Uint8 g
1272         Uint8 b
1273         CODE:
1274                 RETVAL = SDL_MapRGB(pixel_format,r,g,b);
1275         OUTPUT:
1276                 RETVAL
1277
1278 void
1279 UpdateRect ( surface, x, y, w ,h )
1280         SDL_Surface *surface
1281         int x
1282         int y
1283         int w
1284         int h
1285         CODE:
1286                 SDL_UpdateRect(surface,x,y,w,h);
1287
1288 SDL_Surface *
1289 DisplayFormat ( surface )
1290         SDL_Surface *surface
1291         CODE:
1292                 char* CLASS = "SDL::Surface";
1293                 RETVAL = SDL_DisplayFormat(surface);
1294         OUTPUT:
1295                 RETVAL
1296
1297 SDL_Surface *
1298 DisplayFormatAlpha ( surface )
1299         SDL_Surface *surface
1300         CODE:
1301                 char* CLASS = "SDL::Surface";
1302                 RETVAL = SDL_DisplayFormatAlpha(surface);
1303         OUTPUT:
1304                 RETVAL
1305
1306 void
1307 UpdateRects ( surface, ... )
1308         SDL_Surface *surface
1309         CODE:
1310                 SDL_Rect *rects;
1311                 int num_rects,i;
1312                 if ( items < 2 ) return;
1313                 num_rects = items - 1;
1314                 rects = (SDL_Rect *)safemalloc(sizeof(SDL_Rect)*items);
1315                 for(i=0;i<num_rects;i++) {
1316                         rects[i] = *(SDL_Rect *)SvIV((SV*)SvRV( ST(i + 1) ));
1317                 }
1318                 SDL_UpdateRects(surface,num_rects,rects);
1319                 safefree(rects);
1320
1321 =for comment
1322
1323 Comment out for now as it does not compile
1324
1325 SDL_Color *
1326 PaletteColors ( palette, index, ... )
1327         SDL_Palette *palette
1328         int index
1329         CODE:
1330                 if ( items > 2 ) {
1331                         palette->colors[index].r = SvUV(ST(2)); 
1332                         palette->colors[index].g = SvUV(ST(3)); 
1333                         palette->colors[index].b = SvUV(ST(4)); 
1334                 }
1335                 RETVAL = (SDL_Color *)(palette->colors + index);
1336         OUTPUT:
1337                 RETVAL
1338
1339
1340
1341 int
1342 VideoModeOK ( width, height, bpp, flags )
1343         int width
1344         int height
1345         int bpp
1346         Uint32 flags
1347         CODE:
1348                 RETVAL = SDL_VideoModeOK(width,height,bpp,flags);
1349         OUTPUT:
1350                 RETVAL
1351
1352 SDL_Surface *
1353 SetVideoMode ( width, height, bpp, flags )
1354         int width
1355         int height
1356         int bpp
1357         Uint32 flags
1358         CODE:
1359                 RETVAL = SDL_SetVideoMode(width,height,bpp,flags);
1360         OUTPUT:
1361                 RETVAL
1362
1363 int
1364 Flip ( surface )
1365         SDL_Surface *surface
1366         CODE:
1367                 RETVAL = SDL_Flip(surface);
1368         OUTPUT:
1369                 RETVAL
1370
1371 int
1372 SetColors ( surface, start, ... )
1373         SDL_Surface *surface
1374         int start
1375         CODE:
1376                 SDL_Color *colors,*temp;
1377                 int i, length;
1378                 if ( items < 3 ) { RETVAL = 0;  goto all_done; }
1379                 length = items - 2;
1380                 colors = (SDL_Color *)safemalloc(sizeof(SDL_Color)*(length+1));
1381                 for ( i = 0; i < length ; i++ ) {
1382                         temp = (SDL_Color *)SvIV(ST(i+2));
1383                         colors[i].r = temp->r;
1384                         colors[i].g = temp->g;
1385                         colors[i].b = temp->b;
1386                 }
1387                 RETVAL = SDL_SetColors(surface, colors, start, length );
1388                 safefree(colors);
1389 all_done:
1390         OUTPUT: 
1391                 RETVAL
1392
1393 Uint32
1394 MapRGBA ( surface, r, g, b, a )
1395         SDL_Surface *surface
1396         Uint8 r
1397         Uint8 g
1398         Uint8 b
1399         Uint8 a
1400         CODE:
1401                 RETVAL = SDL_MapRGBA(surface->format,r,g,b,a);
1402         OUTPUT:
1403                 RETVAL
1404
1405 AV *
1406 GetRGB ( surface, pixel )
1407         SDL_Surface *surface
1408         Uint32 pixel
1409         CODE:
1410                 Uint8 r,g,b;
1411                 SDL_GetRGB(pixel,surface->format,&r,&g,&b);
1412                 RETVAL = newAV();
1413                 av_push(RETVAL,newSViv(r));
1414                 av_push(RETVAL,newSViv(g));
1415                 av_push(RETVAL,newSViv(b));
1416         OUTPUT:
1417                 RETVAL
1418
1419 AV *
1420 GetRGBA ( surface, pixel )
1421         SDL_Surface *surface
1422         Uint32 pixel
1423         CODE:
1424                 Uint8 r,g,b,a;
1425                 SDL_GetRGBA(pixel,surface->format,&r,&g,&b,&a);
1426                 RETVAL = newAV();
1427                 av_push(RETVAL,newSViv(r));
1428                 av_push(RETVAL,newSViv(g));
1429                 av_push(RETVAL,newSViv(b));
1430                 av_push(RETVAL,newSViv(a));
1431         OUTPUT:
1432                 RETVAL
1433
1434 int
1435 SaveBMP ( surface, filename )
1436         SDL_Surface *surface
1437         char *filename
1438         CODE:
1439                 RETVAL = SDL_SaveBMP(surface,filename);
1440         OUTPUT:
1441                 RETVAL  
1442
1443 int
1444 SetColorKey ( surface, flag, key )
1445         SDL_Surface *surface
1446         Uint32 flag
1447         SDL_Color *key
1448         CODE:
1449                 Uint32 pixel = SDL_MapRGB(surface->format,key->r,key->g,key->b);
1450                 RETVAL = SDL_SetColorKey(surface,flag,pixel);
1451         OUTPUT:
1452                 RETVAL
1453
1454 int
1455 SetAlpha ( surface, flag, alpha )
1456         SDL_Surface *surface
1457         Uint32 flag
1458         Uint8 alpha
1459         CODE:
1460                 RETVAL = SDL_SetAlpha(surface,flag,alpha);
1461         OUTPUT:
1462                 RETVAL
1463
1464 SDL_Surface*
1465 ConvertRGB ( surface )
1466         SDL_Surface * surface
1467         CODE:
1468                 SDL_PixelFormat fmt;
1469                 fmt.palette = NULL;
1470                 fmt.BitsPerPixel = 24;
1471                 fmt.BytesPerPixel = 3;
1472                 fmt.Rmask = 0x000000ff;
1473                 fmt.Gmask = 0x0000ff00;
1474                 fmt.Bmask = 0x00ff0000;
1475                 fmt.Amask = 0x00000000;
1476                 fmt.Rloss = 0;
1477                 fmt.Gloss = 0;
1478                 fmt.Bloss = 0;
1479                 fmt.Aloss = 0;
1480                 fmt.Rshift = 0;
1481                 fmt.Gshift = 8;
1482                 fmt.Bshift = 16;
1483                 fmt.Ashift = 24;
1484                 fmt.colorkey = 0;
1485                 fmt.alpha = 0;
1486                 RETVAL = SDL_ConvertSurface(surface,&fmt,surface->flags);
1487         OUTPUT:
1488                 RETVAL
1489
1490 SDL_Surface* 
1491 ConvertRGBA ( surface )
1492         SDL_Surface * surface
1493         CODE:
1494                 SDL_PixelFormat fmt;
1495                 fmt.palette = NULL;
1496                 fmt.BitsPerPixel = 32;
1497                 fmt.BytesPerPixel = 4;
1498                 fmt.Rmask = 0x000000ff;
1499                 fmt.Gmask = 0x0000ff00;
1500                 fmt.Bmask = 0x00ff0000;
1501                 fmt.Amask = 0xff000000;
1502                 fmt.Rloss = 0;
1503                 fmt.Gloss = 0;
1504                 fmt.Bloss = 0;
1505                 fmt.Aloss = 0;
1506                 fmt.Rshift = 0;
1507                 fmt.Gshift = 8;
1508                 fmt.Bshift = 16;
1509                 fmt.Ashift = 24;
1510                 fmt.colorkey = 0;
1511                 fmt.alpha = 0;
1512                 RETVAL = SDL_ConvertSurface(surface,&fmt,surface->flags);
1513         OUTPUT:
1514                 RETVAL
1515
1516 =cut
1517
1518 int
1519 FillRect ( dest, dest_rect, pixel )
1520         SDL_Surface *dest
1521         SDL_Rect *dest_rect
1522         Uint32 pixel
1523         CODE:
1524                 RETVAL = SDL_FillRect(dest,dest_rect,pixel);
1525         OUTPUT:
1526                 RETVAL
1527
1528 Uint8
1529 GetAppState ()
1530         CODE:
1531                 RETVAL = SDL_GetAppState();
1532         OUTPUT:
1533                 RETVAL
1534
1535
1536 void
1537 WMSetCaption ( title, icon )
1538         char *title
1539         char *icon
1540         CODE:
1541                 SDL_WM_SetCaption(title,icon);
1542
1543 AV *
1544 WMGetCaption ()
1545         CODE:
1546                 char *title,*icon;
1547                 SDL_WM_GetCaption(&title,&icon);
1548                 RETVAL = newAV();
1549                 av_push(RETVAL,newSVpv(title,0));
1550                 av_push(RETVAL,newSVpv(icon,0));
1551         OUTPUT:
1552                 RETVAL
1553
1554 void
1555 WMSetIcon ( icon )
1556         SDL_Surface *icon
1557         CODE:
1558                 SDL_WM_SetIcon(icon,NULL);
1559
1560 void
1561 WarpMouse ( x, y )
1562         Uint16 x
1563         Uint16 y
1564         CODE:
1565                 SDL_WarpMouse(x,y);
1566
1567 AV*
1568 GetMouseState ()
1569         CODE:
1570                 Uint8 mask;
1571                 int x;
1572                 int y;
1573                 mask = SDL_GetMouseState(&x,&y);
1574                 RETVAL = newAV();
1575                 av_push(RETVAL,newSViv(mask));
1576                 av_push(RETVAL,newSViv(x));
1577                 av_push(RETVAL,newSViv(y));
1578         OUTPUT:
1579                 RETVAL  
1580
1581 AV*
1582 GetRelativeMouseState ()
1583         CODE:
1584                 Uint8 mask;
1585                 int x;
1586                 int y;
1587                 mask = SDL_GetRelativeMouseState(&x,&y);
1588                 RETVAL = newAV();
1589                 av_push(RETVAL,newSViv(mask));
1590                 av_push(RETVAL,newSViv(x));
1591                 av_push(RETVAL,newSViv(y));
1592         OUTPUT:
1593                 RETVAL  
1594
1595 SDL_Cursor *
1596 NewCursor ( data, mask, x ,y )
1597         SDL_Surface *data
1598         SDL_Surface *mask
1599         int x
1600         int y
1601         CODE:
1602                 RETVAL = SDL_CreateCursor((Uint8*)data->pixels,
1603                                 (Uint8*)mask->pixels,data->w,data->h,x,y);
1604         OUTPUT:
1605                 RETVAL
1606
1607 void
1608 FreeCursor ( cursor )
1609         SDL_Cursor *cursor
1610         CODE:
1611                 SDL_FreeCursor(cursor);
1612
1613 void
1614 SetCursor ( cursor )
1615         SDL_Cursor *cursor
1616         CODE:
1617                 SDL_SetCursor(cursor);
1618
1619 SDL_Cursor *
1620 GetCursor ()
1621         CODE:
1622                 RETVAL = SDL_GetCursor();
1623         OUTPUT:
1624                 RETVAL
1625
1626 int
1627 ShowCursor ( toggle )
1628         int toggle
1629         CODE:
1630                 RETVAL = SDL_ShowCursor(toggle);
1631         OUTPUT: 
1632                 RETVAL
1633
1634 SDL_AudioSpec *
1635 NewAudioSpec ( freq, format, channels, samples )
1636         int freq
1637         Uint16 format
1638         Uint8 channels
1639         Uint16 samples
1640         CODE:
1641                 RETVAL = (SDL_AudioSpec *)safemalloc(sizeof(SDL_AudioSpec));
1642                 RETVAL->freq = freq;
1643                 RETVAL->format = format;
1644                 RETVAL->channels = channels;
1645                 RETVAL->samples = samples;
1646         OUTPUT:
1647                 RETVAL
1648
1649 void
1650 FreeAudioSpec ( spec )
1651         SDL_AudioSpec *spec
1652         CODE:
1653                 safefree(spec);
1654
1655 SDL_AudioCVT *
1656 NewAudioCVT ( src_format, src_channels, src_rate, dst_format, dst_channels, dst_rate)
1657         Uint16 src_format
1658         Uint8 src_channels
1659         int src_rate
1660         Uint16 dst_format
1661         Uint8 dst_channels
1662         int dst_rate
1663         CODE:
1664                 RETVAL = (SDL_AudioCVT *)safemalloc(sizeof(SDL_AudioCVT));
1665                 if (SDL_BuildAudioCVT(RETVAL,src_format, src_channels, src_rate,
1666                         dst_format, dst_channels, dst_rate)) { 
1667                         safefree(RETVAL); RETVAL = NULL; }
1668         OUTPUT:
1669                 RETVAL
1670
1671 void
1672 FreeAudioCVT ( cvt )
1673         SDL_AudioCVT *cvt
1674         CODE:
1675                 safefree(cvt);
1676
1677 int
1678 ConvertAudioData ( cvt, data, len )
1679         SDL_AudioCVT *cvt
1680         Uint8 *data
1681         int len
1682         CODE:
1683                 cvt->len = len;
1684                 cvt->buf = (Uint8*) safemalloc(cvt->len*cvt->len_mult);
1685                 memcpy(cvt->buf,data,cvt->len);
1686                 RETVAL = SDL_ConvertAudio(cvt);
1687         OUTPUT:
1688                 RETVAL                  
1689
1690 int
1691 OpenAudio ( spec, callback )
1692         SDL_AudioSpec *spec
1693         SV* callback
1694         CODE:
1695                 spec->userdata = (void*)callback;
1696                 spec->callback = sdl_perl_audio_callback;
1697                 RETVAL = SDL_OpenAudio(spec,NULL);
1698         OUTPUT:
1699                 RETVAL
1700
1701 Uint32
1702 GetAudioStatus ()
1703         CODE:
1704                 RETVAL = SDL_GetAudioStatus ();
1705         OUTPUT:
1706                 RETVAL
1707
1708 void
1709 PauseAudio ( p_on )
1710         int p_on
1711         CODE:
1712                 SDL_PauseAudio(p_on);
1713         
1714 void
1715 LockAudio ()
1716         CODE:
1717                 SDL_LockAudio();
1718
1719 void
1720 UnlockAudio ()
1721         CODE:
1722                 SDL_UnlockAudio();
1723
1724 void
1725 CloseAudio ()
1726         CODE:
1727                 SDL_CloseAudio();
1728
1729 void
1730 FreeWAV ( buf )
1731         Uint8 *buf
1732         CODE:
1733                 SDL_FreeWAV(buf);
1734
1735 AV *
1736 LoadWAV ( filename, spec )
1737         char *filename
1738         SDL_AudioSpec *spec
1739         CODE:
1740                 SDL_AudioSpec *temp;
1741                 Uint8 *buf;
1742                 Uint32 len;
1743
1744                 RETVAL = newAV();
1745                 temp = SDL_LoadWAV(filename,spec,&buf,&len);
1746                 if ( ! temp ) goto error;
1747                 av_push(RETVAL,newSViv(PTR2IV(temp)));
1748                 av_push(RETVAL,newSViv(PTR2IV(buf)));
1749                 av_push(RETVAL,newSViv(len));
1750 error:
1751         OUTPUT:
1752                 RETVAL
1753         
1754 #ifdef HAVE_SDL_MIXER
1755
1756 void
1757 MixAudio ( dst, src, len, volume )
1758         Uint8 *dst
1759         Uint8 *src
1760         Uint32 len
1761         int volume
1762         CODE:
1763                 SDL_MixAudio(dst,src,len,volume);
1764
1765 int
1766 MixOpenAudio ( frequency, format, channels, chunksize )
1767         int frequency
1768         Uint16 format
1769         int channels
1770         int chunksize   
1771         CODE:
1772                 RETVAL = Mix_OpenAudio(frequency, format, channels, chunksize);
1773         OUTPUT:
1774                 RETVAL
1775
1776 int
1777 MixAllocateChannels ( number )
1778         int number
1779         CODE:
1780                 RETVAL = Mix_AllocateChannels(number);
1781         OUTPUT:
1782                 RETVAL
1783
1784 AV *
1785 MixQuerySpec ()
1786         CODE:
1787                 int freq, channels, status;
1788                 Uint16 format;
1789                 status = Mix_QuerySpec(&freq,&format,&channels);
1790                 RETVAL = newAV();
1791                 av_push(RETVAL,newSViv(status));
1792                 av_push(RETVAL,newSViv(freq));
1793                 av_push(RETVAL,newSViv(format));
1794                 av_push(RETVAL,newSViv(channels));
1795         OUTPUT:
1796                 RETVAL
1797
1798 Mix_Chunk *
1799 MixLoadWAV ( filename )
1800         char *filename
1801         CODE:
1802                 RETVAL = Mix_LoadWAV(filename);
1803         OUTPUT:
1804                 RETVAL
1805
1806 Mix_Music *
1807 MixLoadMusic ( filename )
1808         char *filename
1809         CODE:
1810                 RETVAL = Mix_LoadMUS(filename);
1811         OUTPUT:
1812                 RETVAL
1813
1814 Mix_Chunk *
1815 MixQuickLoadWAV ( buf )
1816         Uint8 *buf
1817         CODE:
1818                 RETVAL = Mix_QuickLoad_WAV(buf);
1819         OUTPUT:
1820                 RETVAL
1821
1822 void
1823 MixFreeChunk( chunk )
1824         Mix_Chunk *chunk
1825         CODE:
1826                 Mix_FreeChunk(chunk);
1827
1828 void
1829 MixFreeMusic ( music )
1830         Mix_Music *music
1831         CODE:
1832                 Mix_FreeMusic(music);
1833
1834 void
1835 MixSetPostMixCallback ( func, arg )
1836         void *func
1837         void *arg
1838         CODE:
1839                 Mix_SetPostMix(func,arg);
1840
1841 void*
1842 PerlMixMusicHook ()
1843         CODE:
1844                 RETVAL = sdl_perl_music_callback;
1845         OUTPUT:
1846                 RETVAL
1847
1848 void
1849 MixSetMusicHook ( func, arg )
1850         void *func
1851         void *arg
1852         CODE:
1853                 Mix_HookMusic(func,arg);
1854
1855 void
1856 MixSetMusicFinishedHook ( func )
1857         void *func
1858         CODE:
1859                 mix_music_finished_cv = func;
1860                 Mix_HookMusicFinished(sdl_perl_music_finished_callback);
1861
1862 void *
1863 MixGetMusicHookData ()
1864         CODE:
1865                 RETVAL = Mix_GetMusicHookData();
1866         OUTPUT:
1867                 RETVAL
1868
1869 int
1870 MixReverseChannels ( number )
1871         int number
1872         CODE:
1873                 RETVAL = Mix_ReserveChannels ( number );
1874         OUTPUT:
1875                 RETVAL
1876
1877 int
1878 MixGroupChannel ( which, tag )
1879         int which
1880         int tag
1881         CODE:
1882                 RETVAL = Mix_GroupChannel(which,tag);
1883         OUTPUT:
1884                 RETVAL
1885
1886 int
1887 MixGroupChannels ( from, to, tag )
1888         int from
1889         int to
1890         int tag
1891         CODE:
1892                 RETVAL = Mix_GroupChannels(from,to,tag);
1893         OUTPUT:
1894                 RETVAL
1895
1896 int
1897 MixGroupAvailable ( tag )
1898         int tag
1899         CODE:
1900                 RETVAL = Mix_GroupAvailable(tag);
1901         OUTPUT:
1902                 RETVAL
1903
1904 int
1905 MixGroupCount ( tag )
1906         int tag
1907         CODE:
1908                 RETVAL = Mix_GroupCount(tag);
1909         OUTPUT:
1910                 RETVAL
1911
1912 int
1913 MixGroupOldest ( tag )
1914         int tag
1915         CODE:
1916                 RETVAL = Mix_GroupOldest(tag);
1917         OUTPUT:
1918                 RETVAL
1919
1920 int
1921 MixGroupNewer ( tag )
1922         int tag
1923         CODE:
1924                 RETVAL = Mix_GroupNewer(tag);
1925         OUTPUT:
1926                 RETVAL
1927
1928 int
1929 MixPlayChannel ( channel, chunk, loops )
1930         int channel
1931         Mix_Chunk *chunk
1932         int loops
1933         CODE:
1934                 RETVAL = Mix_PlayChannel(channel,chunk,loops);
1935         OUTPUT:
1936                 RETVAL
1937
1938 int
1939 MixPlayChannelTimed ( channel, chunk, loops, ticks )
1940         int channel
1941         Mix_Chunk *chunk
1942         int loops
1943         int ticks
1944         CODE:
1945                 RETVAL = Mix_PlayChannelTimed(channel,chunk,loops,ticks);
1946         OUTPUT:
1947                 RETVAL
1948
1949 int
1950 MixPlayMusic ( music, loops )
1951         Mix_Music *music
1952         int loops
1953         CODE:
1954                 RETVAL = Mix_PlayMusic(music,loops);
1955         OUTPUT:
1956                 RETVAL
1957
1958 int
1959 MixFadeInChannel ( channel, chunk, loops, ms )
1960         int channel
1961         Mix_Chunk *chunk
1962         int loops
1963         int ms
1964         CODE:
1965                 RETVAL = Mix_FadeInChannel(channel,chunk,loops,ms);
1966         OUTPUT:
1967                 RETVAL
1968
1969 int
1970 MixFadeInChannelTimed ( channel, chunk, loops, ms, ticks )
1971         int channel
1972         Mix_Chunk *chunk
1973         int loops
1974         int ticks
1975         int ms
1976         CODE:
1977                 RETVAL = Mix_FadeInChannelTimed(channel,chunk,loops,ms,ticks);
1978         OUTPUT:
1979                 RETVAL
1980
1981 int
1982 MixFadeInMusic ( music, loops, ms )
1983         Mix_Music *music
1984         int loops
1985         int ms
1986         CODE:
1987                 RETVAL = Mix_FadeInMusic(music,loops,ms);
1988         OUTPUT:
1989                 RETVAL
1990
1991 int
1992 MixVolume ( channel, volume )
1993         int channel
1994         int volume
1995         CODE:   
1996                 RETVAL = Mix_Volume(channel,volume);
1997         OUTPUT:
1998                 RETVAL
1999
2000 int
2001 MixVolumeChunk ( chunk, volume )
2002         Mix_Chunk *chunk
2003         int volume
2004         CODE:
2005                 RETVAL = Mix_VolumeChunk(chunk,volume);
2006         OUTPUT:
2007                 RETVAL
2008
2009 int
2010 MixVolumeMusic ( volume )
2011         int volume
2012         CODE:
2013                 RETVAL = Mix_VolumeMusic(volume);
2014         OUTPUT:
2015                 RETVAL
2016
2017 int
2018 MixHaltChannel ( channel )
2019         int channel
2020         CODE:
2021                 RETVAL = Mix_HaltChannel(channel);
2022         OUTPUT:
2023                 RETVAL
2024
2025 int
2026 MixHaltGroup ( tag )
2027         int tag
2028         CODE:
2029                 RETVAL = Mix_HaltGroup(tag);
2030         OUTPUT:
2031                 RETVAL
2032
2033 int
2034 MixHaltMusic ()
2035         CODE:
2036                 RETVAL = Mix_HaltMusic();
2037         OUTPUT:
2038                 RETVAL
2039
2040 int
2041 MixExpireChannel ( channel, ticks )
2042         int channel
2043         int ticks
2044         CODE:
2045                 RETVAL = Mix_ExpireChannel ( channel,ticks);
2046         OUTPUT:
2047                 RETVAL
2048
2049 int
2050 MixFadeOutChannel ( which, ms )
2051         int which
2052         int ms
2053         CODE:
2054                 RETVAL = Mix_FadeOutChannel(which,ms);
2055         OUTPUT:
2056                 RETVAL
2057
2058 int
2059 MixFadeOutGroup ( which, ms )
2060         int which
2061         int ms
2062         CODE:
2063                 RETVAL = Mix_FadeOutGroup(which,ms);
2064         OUTPUT:
2065                 RETVAL
2066
2067 int
2068 MixFadeOutMusic ( ms )
2069         int ms
2070         CODE:
2071                 RETVAL = Mix_FadeOutMusic(ms);
2072         OUTPUT:
2073                 RETVAL
2074
2075 Mix_Fading
2076 MixFadingMusic()
2077         CODE:
2078                 RETVAL = Mix_FadingMusic();
2079         OUTPUT:
2080                 RETVAL
2081
2082 Mix_Fading
2083 MixFadingChannel( which )
2084         int which
2085         CODE:
2086                 RETVAL = Mix_FadingChannel(which);
2087         OUTPUT:
2088                 RETVAL
2089
2090 void
2091 MixPause ( channel )
2092         int channel
2093         CODE:
2094                 Mix_Pause(channel);
2095
2096 void
2097 MixResume ( channel )
2098         int channel
2099         CODE:
2100                 Mix_Resume(channel);
2101
2102 int
2103 MixPaused ( channel )
2104         int channel
2105         CODE:
2106                 RETVAL = Mix_Paused(channel);
2107         OUTPUT:
2108                 RETVAL
2109
2110 void
2111 MixPauseMusic ()
2112         CODE:
2113                 Mix_PauseMusic();
2114
2115 void
2116 MixResumeMusic ()
2117         CODE:
2118                 Mix_ResumeMusic();
2119
2120 void
2121 MixRewindMusic ()
2122         CODE:
2123                 Mix_RewindMusic();
2124
2125 int
2126 MixPausedMusic ()
2127         CODE:
2128                 RETVAL = Mix_PausedMusic();
2129         OUTPUT:
2130                 RETVAL
2131
2132 int
2133 MixPlaying( channel )
2134         int channel     
2135         CODE:
2136                 RETVAL = Mix_Playing(channel);
2137         OUTPUT:
2138                 RETVAL
2139
2140 int
2141 MixPlayingMusic()
2142         CODE:
2143                 RETVAL = Mix_PlayingMusic();
2144         OUTPUT:
2145                 RETVAL
2146
2147 int
2148 MixSetPanning ( channel, left, right )
2149         int channel
2150         int left
2151         int right
2152         CODE:
2153                 RETVAL = Mix_SetPanning(channel, left, right);
2154         OUTPUT:
2155                 RETVAL
2156
2157 void
2158 MixCloseAudio ()
2159         CODE:
2160                 Mix_CloseAudio();
2161
2162 #endif
2163
2164 int
2165 GLLoadLibrary ( path )
2166         char *path
2167         CODE:
2168                 RETVAL = SDL_GL_LoadLibrary(path);
2169         OUTPUT:
2170                 RETVAL
2171
2172 void*
2173 GLGetProcAddress ( proc )
2174         char *proc
2175         CODE:
2176                 RETVAL = SDL_GL_GetProcAddress(proc);
2177         OUTPUT:
2178                 RETVAL
2179
2180 int
2181 GLSetAttribute ( attr,  value )
2182         int        attr
2183         int        value
2184         CODE:
2185                 RETVAL = SDL_GL_SetAttribute(attr, value);
2186         OUTPUT:
2187                 RETVAL
2188
2189 AV *
2190 GLGetAttribute ( attr )
2191         int        attr
2192         CODE:
2193                 int value;
2194                 RETVAL = newAV();
2195                 av_push(RETVAL,newSViv(SDL_GL_GetAttribute(attr, &value)));
2196                 av_push(RETVAL,newSViv(value));
2197         OUTPUT:
2198                 RETVAL
2199
2200 void
2201 GLSwapBuffers ()
2202         CODE:
2203                 SDL_GL_SwapBuffers ();
2204
2205
2206 int
2207 BigEndian ()
2208         CODE:
2209                 RETVAL = (SDL_BYTEORDER == SDL_BIG_ENDIAN);
2210         OUTPUT:
2211                 RETVAL
2212
2213 int
2214 NumJoysticks ()
2215         CODE:
2216                 RETVAL = SDL_NumJoysticks();
2217         OUTPUT:
2218                 RETVAL
2219
2220 char *
2221 JoystickName ( index )
2222         int index
2223         CODE:
2224                 RETVAL = (char*)SDL_JoystickName(index);
2225         OUTPUT:
2226                 RETVAL
2227
2228 SDL_Joystick *
2229 JoystickOpen ( index ) 
2230         int index
2231         CODE:
2232                 RETVAL = SDL_JoystickOpen(index);
2233         OUTPUT:
2234                 RETVAL
2235
2236 int
2237 JoystickOpened ( index )
2238         int index
2239         CODE:
2240                 RETVAL = SDL_JoystickOpened(index);
2241         OUTPUT:
2242                 RETVAL
2243
2244 int
2245 JoystickIndex ( joystick )
2246         SDL_Joystick *joystick
2247         CODE:
2248                 RETVAL = SDL_JoystickIndex(joystick);
2249         OUTPUT:
2250                 RETVAL
2251
2252 int
2253 JoystickNumAxes ( joystick )
2254         SDL_Joystick *joystick
2255         CODE:
2256                 RETVAL = SDL_JoystickNumAxes(joystick);
2257         OUTPUT:
2258                 RETVAL
2259
2260 int
2261 JoystickNumBalls ( joystick )
2262         SDL_Joystick *joystick
2263         CODE:
2264                 RETVAL = SDL_JoystickNumBalls(joystick);
2265         OUTPUT:
2266                 RETVAL
2267
2268 int
2269 JoystickNumHats ( joystick )
2270         SDL_Joystick *joystick
2271         CODE:
2272                 RETVAL = SDL_JoystickNumHats(joystick);
2273         OUTPUT:
2274                 RETVAL
2275
2276 int
2277 JoystickNumButtons ( joystick )
2278         SDL_Joystick *joystick
2279         CODE:
2280                 RETVAL = SDL_JoystickNumButtons(joystick);
2281         OUTPUT:
2282                 RETVAL
2283
2284 void
2285 JoystickUpdate ()
2286         CODE:
2287                 SDL_JoystickUpdate();
2288
2289 Sint16
2290 JoystickGetAxis ( joystick, axis )
2291         SDL_Joystick *joystick
2292         int axis
2293         CODE:
2294                 RETVAL = SDL_JoystickGetAxis(joystick,axis);
2295         OUTPUT:
2296                 RETVAL
2297
2298 Uint8
2299 JoystickGetHat ( joystick, hat )
2300         SDL_Joystick *joystick
2301         int hat 
2302         CODE:
2303                 RETVAL = SDL_JoystickGetHat(joystick,hat);
2304         OUTPUT:
2305                 RETVAL
2306
2307 Uint8
2308 JoystickGetButton ( joystick, button)
2309         SDL_Joystick *joystick
2310         int button 
2311         CODE:
2312                 RETVAL = SDL_JoystickGetButton(joystick,button);
2313         OUTPUT:
2314                 RETVAL
2315
2316 AV *
2317 JoystickGetBall ( joystick, ball )
2318         SDL_Joystick *joystick
2319         int ball 
2320         CODE:
2321                 int success,dx,dy;
2322                 success = SDL_JoystickGetBall(joystick,ball,&dx,&dy);
2323                 RETVAL = newAV();
2324                 av_push(RETVAL,newSViv(success));
2325                 av_push(RETVAL,newSViv(dx));
2326                 av_push(RETVAL,newSViv(dy));
2327         OUTPUT:
2328                 RETVAL  
2329
2330 void
2331 JoystickClose ( joystick )
2332         SDL_Joystick *joystick
2333         CODE:
2334                 SDL_JoystickClose(joystick);
2335
2336 Sint16
2337 JoyAxisEventWhich ( e )
2338         SDL_Event *e
2339         CODE:
2340                 RETVAL = e->jaxis.which;
2341         OUTPUT:
2342                 RETVAL
2343
2344 Uint8
2345 JoyAxisEventAxis ( e )
2346         SDL_Event *e
2347         CODE:
2348                 RETVAL = e->jaxis.axis;
2349         OUTPUT:
2350                 RETVAL
2351
2352 Sint16
2353 JoyAxisEventValue ( e )
2354         SDL_Event *e
2355         CODE:
2356                 RETVAL = e->jaxis.value;
2357         OUTPUT:
2358                 RETVAL
2359
2360 Uint8
2361 JoyButtonEventWhich ( e )
2362         SDL_Event *e
2363         CODE:
2364                 RETVAL = e->jbutton.which;
2365         OUTPUT:
2366                 RETVAL
2367
2368 Uint8
2369 JoyButtonEventButton ( e )
2370         SDL_Event *e
2371         CODE:
2372                 RETVAL = e->jbutton.button;
2373         OUTPUT:
2374                 RETVAL
2375
2376 Uint8
2377 JoyButtonEventState ( e )
2378         SDL_Event *e
2379         CODE:
2380                 RETVAL = e->jbutton.state;
2381         OUTPUT:
2382                 RETVAL
2383         
2384 Uint8
2385 JoyHatEventWhich ( e )
2386         SDL_Event *e
2387         CODE:
2388                 RETVAL = e->jhat.which;
2389         OUTPUT:
2390                 RETVAL
2391
2392 Uint8
2393 JoyHatEventHat ( e )
2394         SDL_Event *e
2395         CODE:
2396                 RETVAL = e->jhat.hat;
2397         OUTPUT:
2398                 RETVAL
2399
2400 Uint8
2401 JoyHatEventValue ( e )
2402         SDL_Event *e
2403         CODE:
2404                 RETVAL = e->jhat.value;
2405         OUTPUT:
2406                 RETVAL
2407
2408 Uint8
2409 JoyBallEventWhich ( e )
2410         SDL_Event *e
2411         CODE: 
2412                 RETVAL = e->jball.which;
2413         OUTPUT:
2414                 RETVAL
2415
2416 Uint8
2417 JoyBallEventBall ( e )
2418         SDL_Event *e
2419         CODE:
2420                 RETVAL = e->jball.ball;
2421         OUTPUT:
2422                 RETVAL
2423
2424 Sint16
2425 JoyBallEventXrel ( e )
2426         SDL_Event *e
2427         CODE:
2428                 RETVAL = e->jball.xrel;
2429         OUTPUT:
2430                 RETVAL
2431
2432 Sint16
2433 JoyBallEventYrel ( e )
2434         SDL_Event *e
2435         CODE:
2436                 RETVAL = e->jball.yrel;
2437         OUTPUT:
2438                 RETVAL
2439
2440 void
2441 SetClipRect ( surface, rect )
2442         SDL_Surface *surface
2443         SDL_Rect *rect
2444         CODE:
2445                 SDL_SetClipRect(surface,rect);
2446         
2447 void
2448 GetClipRect ( surface, rect )
2449         SDL_Surface *surface
2450         SDL_Rect *rect;
2451         CODE:
2452                 SDL_GetClipRect(surface, rect);
2453
2454
2455 #ifdef HAVE_SDL_NET
2456
2457 int
2458 NetInit ()
2459         CODE:
2460                 RETVAL = SDLNet_Init();
2461         OUTPUT:
2462                 RETVAL
2463
2464 void
2465 NetQuit ()
2466         CODE:
2467                 SDLNet_Quit();
2468
2469 IPaddress*
2470 NetNewIPaddress ( host, port )
2471         Uint32 host
2472         Uint16 port
2473         CODE:
2474                 RETVAL = (IPaddress*) safemalloc(sizeof(IPaddress));
2475                 RETVAL->host = host;
2476                 RETVAL->port = port;
2477         OUTPUT:
2478                 RETVAL
2479
2480 Uint32
2481 NetIPaddressHost ( ip )
2482         IPaddress *ip
2483         CODE:
2484                 RETVAL = ip->host;
2485         OUTPUT:
2486                 RETVAL
2487
2488 Uint16
2489 NetIPaddressPort ( ip )
2490         IPaddress *ip
2491         CODE:
2492                 RETVAL = ip->port;
2493         OUTPUT:
2494                 RETVAL
2495
2496 void
2497 NetFreeIPaddress ( ip )
2498         IPaddress *ip
2499         CODE:
2500                 safefree(ip);
2501
2502 const char*
2503 NetResolveIP ( address )
2504         IPaddress *address
2505         CODE:
2506                 RETVAL = SDLNet_ResolveIP(address);
2507         OUTPUT:
2508                 RETVAL
2509
2510 int
2511 NetResolveHost ( address, host, port )
2512         IPaddress *address
2513         const char *host
2514         Uint16 port
2515         CODE:
2516                 RETVAL = SDLNet_ResolveHost(address,host,port);
2517         OUTPUT:
2518                 RETVAL
2519         
2520 TCPsocket
2521 NetTCPOpen ( ip )
2522         IPaddress *ip
2523         CODE:
2524                 RETVAL = SDLNet_TCP_Open(ip);
2525         OUTPUT:
2526                 RETVAL
2527
2528 TCPsocket
2529 NetTCPAccept ( server )
2530         TCPsocket server
2531         CODE:
2532                 RETVAL = SDLNet_TCP_Accept(server);
2533         OUTPUT:
2534                 RETVAL
2535
2536 IPaddress*
2537 NetTCPGetPeerAddress ( sock )
2538         TCPsocket sock
2539         CODE:
2540                 RETVAL = SDLNet_TCP_GetPeerAddress(sock);
2541         OUTPUT:
2542                 RETVAL
2543
2544 int
2545 NetTCPSend ( sock, data, len  )
2546         TCPsocket sock
2547         void *data
2548         int len
2549         CODE:
2550                 RETVAL = SDLNet_TCP_Send(sock,data,len);
2551         OUTPUT:
2552                 RETVAL
2553
2554 AV*
2555 NetTCPRecv ( sock, maxlen )
2556         TCPsocket sock
2557         int maxlen
2558         CODE:
2559                 int status;
2560                 void *buffer;
2561                 buffer = safemalloc(maxlen);
2562                 RETVAL = newAV();
2563                 status = SDLNet_TCP_Recv(sock,buffer,maxlen);
2564                 av_push(RETVAL,newSViv(status));
2565                 av_push(RETVAL,newSVpvn((char*)buffer,maxlen));
2566         OUTPUT:
2567                 RETVAL  
2568         
2569 void
2570 NetTCPClose ( sock )
2571         TCPsocket sock
2572         CODE:
2573                 SDLNet_TCP_Close(sock);
2574
2575 UDPpacket*
2576 NetAllocPacket ( size )
2577         int size
2578         CODE:
2579                 RETVAL = SDLNet_AllocPacket(size);
2580         OUTPUT:
2581                 RETVAL
2582
2583 UDPpacket**
2584 NetAllocPacketV ( howmany, size )
2585         int howmany
2586         int size
2587         CODE:
2588                 RETVAL = SDLNet_AllocPacketV(howmany,size);
2589         OUTPUT:
2590                 RETVAL
2591
2592 int
2593 NetResizePacket ( packet, newsize )
2594         UDPpacket *packet
2595         int newsize
2596         CODE:
2597                 RETVAL = SDLNet_ResizePacket(packet,newsize);
2598         OUTPUT:
2599                 RETVAL
2600
2601 void
2602 NetFreePacket ( packet )
2603         UDPpacket *packet
2604         CODE:
2605                 SDLNet_FreePacket(packet);
2606
2607 void
2608 NetFreePacketV ( packet )
2609         UDPpacket **packet
2610         CODE:
2611                 SDLNet_FreePacketV(packet);
2612
2613 UDPsocket
2614 NetUDPOpen ( port )
2615         Uint16 port
2616         CODE:
2617                 RETVAL = SDLNet_UDP_Open(port);
2618         OUTPUT:
2619                 RETVAL
2620
2621 int
2622 NetUDPBind ( sock, channel, address )
2623         UDPsocket sock
2624         int channel
2625         IPaddress *address
2626         CODE:
2627                 RETVAL = SDLNet_UDP_Bind(sock,channel,address);
2628         OUTPUT:
2629                 RETVAL
2630
2631 void
2632 NetUDPUnbind ( sock, channel )
2633         UDPsocket sock
2634         int channel
2635         CODE:
2636                 SDLNet_UDP_Unbind(sock,channel);
2637
2638 IPaddress*
2639 NetUDPGetPeerAddress ( sock, channel )
2640         UDPsocket sock
2641         int channel
2642         CODE:
2643                 RETVAL = SDLNet_UDP_GetPeerAddress(sock,channel);
2644         OUTPUT:
2645                 RETVAL
2646
2647 int
2648 NetUDPSendV ( sock, packets, npackets )
2649         UDPsocket sock
2650         UDPpacket **packets
2651         int npackets
2652         CODE:
2653                 RETVAL = SDLNet_UDP_SendV(sock,packets,npackets);
2654         OUTPUT:
2655                 RETVAL
2656
2657 int
2658 NetUDPSend ( sock, channel, packet )
2659         UDPsocket sock
2660         int channel
2661         UDPpacket *packet 
2662         CODE:
2663                 RETVAL = SDLNet_UDP_Send(sock,channel,packet);
2664         OUTPUT:
2665                 RETVAL
2666
2667 int
2668 NetUDPRecvV ( sock, packets )
2669         UDPsocket sock
2670         UDPpacket **packets
2671         CODE:
2672                 RETVAL = SDLNet_UDP_RecvV(sock,packets);
2673         OUTPUT:
2674                 RETVAL
2675
2676 int
2677 NetUDPRecv ( sock, packet )
2678         UDPsocket sock
2679         UDPpacket *packet
2680         CODE:
2681                 RETVAL = SDLNet_UDP_Recv(sock,packet);
2682         OUTPUT:
2683                 RETVAL
2684
2685 void
2686 NetUDPClose ( sock )
2687         UDPsocket sock
2688         CODE:
2689                 SDLNet_UDP_Close(sock);
2690
2691 SDLNet_SocketSet
2692 NetAllocSocketSet ( maxsockets )
2693         int maxsockets
2694         CODE:
2695                 RETVAL = SDLNet_AllocSocketSet(maxsockets);
2696         OUTPUT:
2697                 RETVAL
2698
2699 int
2700 NetTCP_AddSocket ( set, sock )
2701         SDLNet_SocketSet set
2702         TCPsocket sock
2703         CODE:
2704                 RETVAL = SDLNet_TCP_AddSocket(set,sock);
2705         OUTPUT:
2706                 RETVAL
2707
2708 int
2709 NetUDP_AddSocket ( set, sock )
2710         SDLNet_SocketSet set
2711         UDPsocket sock
2712         CODE:
2713                 RETVAL = SDLNet_UDP_AddSocket(set,sock);
2714         OUTPUT:
2715                 RETVAL
2716
2717 int
2718 NetTCP_DelSocket ( set, sock )
2719         SDLNet_SocketSet set
2720         TCPsocket sock
2721         CODE:
2722                 RETVAL = SDLNet_TCP_DelSocket(set,sock);
2723         OUTPUT:
2724                 RETVAL
2725
2726 int
2727 NetUDP_DelSocket ( set, sock )
2728         SDLNet_SocketSet set
2729         UDPsocket sock
2730         CODE:
2731                 RETVAL = SDLNet_UDP_DelSocket(set,sock);
2732         OUTPUT:
2733                 RETVAL
2734
2735 int
2736 NetCheckSockets ( set, timeout )
2737         SDLNet_SocketSet set
2738         Uint32 timeout
2739         CODE:
2740                 RETVAL = SDLNet_CheckSockets(set,timeout);
2741         OUTPUT:
2742                 RETVAL
2743
2744 int
2745 NetSocketReady ( sock )
2746         SDLNet_GenericSocket sock
2747         CODE:
2748                 RETVAL = SDLNet_SocketReady(sock);
2749         OUTPUT:
2750                 RETVAL
2751
2752 void
2753 NetFreeSocketSet ( set )
2754         SDLNet_SocketSet set
2755         CODE:
2756                 SDLNet_FreeSocketSet(set);
2757
2758 void
2759 NetWrite16 ( value, area )
2760         Uint16 value
2761         void *area
2762         CODE:
2763                 SDLNet_Write16(value,area);
2764
2765 void
2766 NetWrite32 ( value, area )
2767         Uint32 value
2768         void *area
2769         CODE:
2770                 SDLNet_Write32(value,area);
2771         
2772 Uint16
2773 NetRead16 ( area )
2774         void *area
2775         CODE:
2776                 RETVAL = SDLNet_Read16(area);
2777         OUTPUT:
2778                 RETVAL
2779
2780 Uint32
2781 NetRead32 ( area )
2782         void *area
2783         CODE:
2784                 RETVAL = SDLNet_Read32(area);
2785         OUTPUT:
2786                 RETVAL
2787
2788 #endif 
2789
2790 SDL_Overlay*
2791 CreateYUVOverlay ( width, height, format, display )
2792         int width
2793         int height
2794         Uint32 format
2795         SDL_Surface *display
2796         CODE:
2797                 RETVAL = SDL_CreateYUVOverlay ( width, height, format, display );
2798         OUTPUT:
2799                 RETVAL
2800
2801 int
2802 LockYUVOverlay ( overlay )
2803         SDL_Overlay *overlay
2804         CODE:
2805                 RETVAL = SDL_LockYUVOverlay(overlay);
2806         OUTPUT:
2807                 RETVAL
2808
2809 void
2810 UnlockYUVOverlay ( overlay )
2811         SDL_Overlay *overlay
2812         CODE:
2813                 SDL_UnlockYUVOverlay(overlay);
2814
2815 int
2816 DisplayYUVOverlay ( overlay, dstrect )
2817         SDL_Overlay *overlay
2818         SDL_Rect *dstrect
2819         CODE:
2820                 RETVAL = SDL_DisplayYUVOverlay ( overlay, dstrect );
2821         OUTPUT:
2822                 RETVAL
2823
2824 void
2825 FreeYUVOverlay ( overlay )
2826         SDL_Overlay *overlay
2827         CODE:
2828                 SDL_FreeYUVOverlay ( overlay );
2829
2830 Uint32
2831 OverlayFormat ( overlay, ... )
2832         SDL_Overlay *overlay
2833         CODE:
2834                 if ( items > 1 ) 
2835                         overlay->format = SvIV(ST(1));
2836                 RETVAL = overlay->format;
2837         OUTPUT:
2838                 RETVAL
2839
2840 int 
2841 OverlayW ( overlay, ... )
2842         SDL_Overlay *overlay
2843         CODE:
2844                 if ( items > 1 ) 
2845                         overlay->w = SvIV(ST(1));
2846                 RETVAL = overlay->w;
2847         OUTPUT:
2848                 RETVAL
2849
2850 int
2851 OverlayH ( overlay, ... )
2852         SDL_Overlay *overlay
2853         CODE:
2854                 if ( items > 1 )
2855                         overlay->h = SvIV(ST(1));
2856                 RETVAL = overlay->h;
2857         OUTPUT:
2858                 RETVAL 
2859
2860 int
2861 OverlayPlanes ( overlay, ... )
2862         SDL_Overlay *overlay
2863         CODE:
2864                 if ( items > 1 )
2865                         overlay->planes = SvIV(ST(1));
2866                 RETVAL = overlay->planes;
2867         OUTPUT:
2868                 RETVAL
2869
2870 Uint32
2871 OverlayHW ( overlay )
2872         SDL_Overlay *overlay
2873         CODE:
2874                 RETVAL = overlay->hw_overlay;
2875         OUTPUT:
2876                 RETVAL
2877
2878 Uint16*
2879 OverlayPitches ( overlay )
2880         SDL_Overlay *overlay
2881         CODE:
2882                 RETVAL = overlay->pitches;
2883         OUTPUT:
2884                 RETVAL
2885
2886 Uint8**
2887 OverlayPixels ( overlay )
2888         SDL_Overlay *overlay
2889         CODE:
2890                 RETVAL = overlay->pixels;
2891         OUTPUT:
2892                 RETVAL
2893
2894 int
2895 WMToggleFullScreen ( surface )
2896         SDL_Surface *surface
2897         CODE:
2898                 RETVAL = SDL_WM_ToggleFullScreen(surface);
2899         OUTPUT:
2900                 RETVAL
2901
2902 Uint32
2903 WMGrabInput ( mode )
2904         Uint32 mode
2905         CODE:
2906                 RETVAL = SDL_WM_GrabInput(mode);
2907         OUTPUT:
2908                 RETVAL
2909
2910 int
2911 WMIconifyWindow ()
2912         CODE:
2913                 RETVAL = SDL_WM_IconifyWindow();
2914         OUTPUT:
2915                 RETVAL
2916
2917 int
2918 ResizeEventW ( e )
2919         SDL_Event *e
2920         CODE:
2921                 RETVAL = e->resize.w;
2922         OUTPUT:
2923                 RETVAL
2924
2925 int
2926 ResizeEventH ( e )
2927         SDL_Event *e
2928         CODE:
2929                 RETVAL = e->resize.h;
2930         OUTPUT:
2931                 RETVAL
2932
2933 char*
2934 AudioDriverName ()
2935         CODE:
2936                 char name[32];
2937                 RETVAL = SDL_AudioDriverName(name,32);
2938         OUTPUT:
2939                 RETVAL
2940
2941 Uint32
2942 GetKeyState ( k )
2943         SDLKey k
2944         CODE:
2945                 if (k >= SDLK_LAST) Perl_croak (aTHX_ "Key out of range");      
2946                 RETVAL = SDL_GetKeyState(NULL)[k];
2947         OUTPUT:
2948                 RETVAL
2949
2950 #ifdef HAVE_SMPEG
2951
2952 SMPEG_Info *
2953 NewSMPEGInfo()
2954         CODE:   
2955                 RETVAL = (SMPEG_Info *) safemalloc (sizeof(SMPEG_Info));
2956         OUTPUT:
2957                 RETVAL
2958
2959 void
2960 FreeSMPEGInfo ( info )
2961         SMPEG_Info *info
2962         CODE:   
2963                 safefree(info);
2964
2965 int
2966 SMPEGInfoHasAudio ( info )
2967         SMPEG_Info* info
2968         CODE:
2969                 RETVAL = info->has_audio;
2970         OUTPUT:
2971                 RETVAL
2972
2973 int
2974 SMPEGInfoHasVideo ( info )
2975         SMPEG_Info* info
2976         CODE:
2977                 RETVAL = info->has_video;
2978         OUTPUT:
2979                 RETVAL
2980
2981 int
2982 SMPEGInfoWidth ( info )
2983         SMPEG_Info* info
2984         CODE:
2985                 RETVAL = info->width;
2986         OUTPUT:
2987                 RETVAL
2988
2989 int
2990 SMPEGInfoHeight ( info )
2991         SMPEG_Info* info
2992         CODE:
2993                 RETVAL = info->height;
2994         OUTPUT:
2995                 RETVAL
2996
2997 int
2998 SMPEGInfoCurrentFrame ( info )
2999         SMPEG_Info* info
3000         CODE:
3001                 RETVAL = info->current_frame;
3002         OUTPUT:
3003                 RETVAL
3004
3005 double
3006 SMPEGInfoCurrentFPS ( info )
3007         SMPEG_Info* info
3008         CODE:
3009                 RETVAL = info->current_fps;
3010         OUTPUT:
3011                 RETVAL
3012
3013 int
3014 SMPEGInfoCurrentAudioFrame ( info )
3015         SMPEG_Info* info
3016         CODE:
3017                 RETVAL = info->audio_current_frame;
3018         OUTPUT:
3019                 RETVAL
3020
3021 int
3022 SMPEGInfoCurrentOffset ( info )
3023         SMPEG_Info* info
3024         CODE:
3025                 RETVAL = info->current_offset;
3026         OUTPUT:
3027                 RETVAL
3028
3029 int
3030 SMPEGInfoTotalSize ( info )
3031         SMPEG_Info* info
3032         CODE:
3033                 RETVAL = info->total_size;
3034         OUTPUT:
3035                 RETVAL
3036
3037 double
3038 SMPEGInfoCurrentTime ( info )
3039         SMPEG_Info* info
3040         CODE:
3041                 RETVAL = info->current_time;
3042         OUTPUT:
3043                 RETVAL
3044
3045 double
3046 SMPEGInfoTotalTime ( info )
3047         SMPEG_Info* info
3048         CODE:
3049                 RETVAL = info->total_time;
3050         OUTPUT:
3051                 RETVAL
3052
3053 char *
3054 SMPEGError ( mpeg )
3055         SMPEG* mpeg
3056         CODE:   
3057                 RETVAL = SMPEG_error(mpeg);
3058         OUTPUT:
3059                 RETVAL
3060
3061 SMPEG*
3062 NewSMPEG ( filename, info, use_audio )
3063         char* filename
3064         SMPEG_Info* info
3065         int use_audio
3066         CODE:   
3067 #ifdef HAVE_SDL_MIXER
3068                 RETVAL = SMPEG_new(filename,info,0);
3069 #else
3070                 RETVAL = SMPEG_new(filename,info,use_audio);
3071 #endif
3072         OUTPUT:
3073                 RETVAL
3074
3075 void
3076 FreeSMPEG ( mpeg )
3077         SMPEG* mpeg
3078         CODE:
3079                 SMPEG_delete(mpeg);
3080
3081 void
3082 SMPEGEnableAudio ( mpeg , flag )
3083         SMPEG* mpeg
3084         int flag
3085         CODE:   
3086                 SMPEG_enableaudio(mpeg,flag);
3087 #ifdef HAVE_SDL_MIXER
3088                 sdl_perl_use_smpeg_audio = flag;
3089 #endif
3090
3091 void
3092 SMPEGEnableVideo ( mpeg , flag )
3093         SMPEG* mpeg
3094         int flag
3095         CODE:   
3096                 SMPEG_enablevideo(mpeg,flag);
3097
3098 void
3099 SMPEGSetVolume ( mpeg , volume )
3100         SMPEG* mpeg
3101         int volume
3102         CODE:   
3103                 SMPEG_setvolume(mpeg,volume);
3104
3105 void
3106 SMPEGSetDisplay ( mpeg, dest, surfLock )
3107         SMPEG* mpeg
3108         SDL_Surface* dest
3109         SDL_mutex*  surfLock
3110         CODE:
3111                 SMPEG_setdisplay(mpeg,dest,surfLock,NULL);
3112
3113 void
3114 SMPEGScaleXY ( mpeg, w, h)
3115         SMPEG* mpeg
3116         int w
3117         int h
3118         CODE:
3119                 SMPEG_scaleXY(mpeg,w,h);
3120
3121 void
3122 SMPEGScale ( mpeg, scale )
3123         SMPEG* mpeg
3124         int scale
3125         CODE:
3126                 SMPEG_scale(mpeg,scale);
3127
3128 void
3129 SMPEGPlay ( mpeg )
3130         SMPEG* mpeg
3131         CODE:
3132                 SDL_AudioSpec audiofmt;
3133                 Uint16 format;
3134                 int freq, channels;
3135 #ifdef HAVE_SDL_MIXER
3136                 if  (sdl_perl_use_smpeg_audio ) {
3137                         SMPEG_enableaudio(mpeg, 0);
3138                         Mix_QuerySpec(&freq, &format, &channels);
3139                         audiofmt.format = format;
3140                         audiofmt.freq = freq;
3141                         audiofmt.channels = channels;
3142                         SMPEG_actualSpec(mpeg, &audiofmt);
3143                         Mix_HookMusic(SMPEG_playAudioSDL, mpeg);
3144                         SMPEG_enableaudio(mpeg, 1);
3145                 }
3146 #endif
3147                 SMPEG_play(mpeg);
3148
3149 SMPEGstatus
3150 SMPEGStatus ( mpeg )
3151         SMPEG* mpeg
3152         CODE:
3153                 RETVAL = SMPEG_status(mpeg);
3154         OUTPUT:
3155                 RETVAL
3156
3157 void
3158 SMPEGPause ( mpeg )
3159         SMPEG* mpeg
3160         CODE:
3161                 SMPEG_pause(mpeg);
3162
3163 void
3164 SMPEGLoop ( mpeg, repeat )
3165         SMPEG* mpeg
3166         int repeat
3167         CODE:
3168                 SMPEG_loop(mpeg,repeat);
3169
3170 void
3171 SMPEGStop ( mpeg )
3172         SMPEG* mpeg
3173         CODE:
3174                 SMPEG_stop(mpeg);
3175 #ifdef HAVE_SDL_MIXER
3176                 Mix_HookMusic(NULL, NULL);
3177 #endif
3178
3179 void
3180 SMPEGRewind ( mpeg )
3181         SMPEG* mpeg
3182         CODE:
3183                 SMPEG_rewind(mpeg);
3184
3185 void
3186 SMPEGSeek ( mpeg, bytes )
3187         SMPEG* mpeg
3188         int bytes
3189         CODE:
3190                 SMPEG_seek(mpeg,bytes);
3191
3192 void
3193 SMPEGSkip ( mpeg, seconds )
3194         SMPEG* mpeg
3195         float seconds
3196         CODE:
3197                 SMPEG_skip(mpeg,seconds);
3198
3199 void
3200 SMPEGSetDisplayRegion ( mpeg, rect )
3201         SMPEG* mpeg
3202         SDL_Rect* rect
3203         CODE:
3204                 SMPEG_setdisplayregion(mpeg,rect->x,rect->y,rect->w,rect->h);
3205
3206 void
3207 SMPEGRenderFrame ( mpeg, frame )
3208         SMPEG* mpeg
3209         int frame
3210         CODE:
3211                 SMPEG_renderFrame(mpeg,frame);
3212
3213 SMPEG_Info *
3214 SMPEGGetInfo ( mpeg )
3215         SMPEG* mpeg
3216         CODE:
3217                 RETVAL = (SMPEG_Info *) safemalloc (sizeof(SMPEG_Info));
3218                 SMPEG_getinfo(mpeg,RETVAL);
3219         OUTPUT:
3220                 RETVAL
3221         
3222
3223 #endif
3224
3225 #ifdef HAVE_SDL_GFX
3226
3227 =cut
3228
3229 SDL_Surface *
3230 GFXRotoZoom ( src, angle, zoom, smooth)
3231         SDL_Surface * src
3232         double angle
3233         double zoom
3234         int smooth
3235         CODE:
3236                 RETVAL = rotozoomSurface( src, angle, zoom, smooth);
3237         OUTPUT:
3238                 RETVAL
3239
3240 SDL_Surface *
3241 GFXZoom ( src, zoomx, zoomy, smooth)
3242         SDL_Surface *src
3243         double zoomx
3244         double zoomy
3245         int smooth
3246         CODE:
3247                 RETVAL = zoomSurface( src, zoomx, zoomy, smooth);
3248         OUTPUT:
3249                 RETVAL
3250
3251 =cut
3252
3253 int
3254 GFXPixelColor ( dst, x, y, color )
3255         SDL_Surface* dst
3256         Sint16 x
3257         Sint16 y
3258         Uint32 color
3259         CODE:
3260                 RETVAL = pixelColor( dst, x, y, color);
3261         OUTPUT:
3262                 RETVAL
3263
3264 int
3265 GFXPixelRGBA ( dst, x, y, r, g, b, a )
3266         SDL_Surface* dst
3267         Sint16 x
3268         Sint16 y
3269         Uint8 r
3270         Uint8 g
3271         Uint8 b
3272         Uint8 a
3273         CODE:
3274                 RETVAL = pixelRGBA( dst, x, y, r, g, b, a );
3275         OUTPUT:
3276                 RETVAL
3277
3278 int
3279 GFXHlineColor ( dst, x1, x2, y, color )
3280         SDL_Surface* dst
3281         Sint16 x1
3282         Sint16 x2
3283         Sint16 y
3284         Uint32 color
3285         CODE:
3286                 RETVAL = hlineColor( dst, x1, x2, y, color );
3287         OUTPUT:
3288                 RETVAL
3289
3290 int
3291 GFXHlineRGBA ( dst, x1, x2, y, r, g, b, a )
3292         SDL_Surface* dst
3293         Sint16 x1
3294         Sint16 x2
3295         Sint16 y
3296         Uint8 r
3297         Uint8 g
3298         Uint8 b
3299         Uint8 a
3300         CODE:
3301                 RETVAL = hlineRGBA( dst, x1, x2, y, r, g, b, a );
3302         OUTPUT:
3303                 RETVAL
3304
3305 int
3306 GFXVlineColor ( dst, x, y1, y2, color )
3307         SDL_Surface* dst
3308         Sint16 x
3309         Sint16 y1
3310         Sint16 y2
3311         Uint32 color
3312         CODE:
3313                 RETVAL = vlineColor( dst, x, y1, y2, color );
3314         OUTPUT:
3315                 RETVAL
3316
3317 int
3318 GFXVlineRGBA ( dst, x, y1, y2, r, g, b, a )
3319         SDL_Surface* dst
3320         Sint16 x
3321         Sint16 y1
3322         Sint16 y2
3323         Uint8 r
3324         Uint8 g
3325         Uint8 b
3326         Uint8 a
3327         CODE:
3328                 RETVAL = vlineRGBA( dst, x, y1, y2, r, g, b, a );
3329         OUTPUT:
3330                 RETVAL
3331
3332 int
3333 GFXRectangleColor ( dst, x1, y1, x2, y2, color )
3334         SDL_Surface* dst
3335         Sint16 x1
3336         Sint16 y1
3337         Sint16 x2
3338         Sint16 y2
3339         Uint32 color
3340         CODE:
3341                 RETVAL = rectangleColor( dst, x1, y1, x2, y2, color );
3342         OUTPUT:
3343                 RETVAL
3344
3345 int
3346 GFXRectangleRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3347         SDL_Surface* dst
3348         Sint16 x1
3349         Sint16 y1
3350         Sint16 x2
3351         Sint16 y2
3352         Uint8 r
3353         Uint8 g
3354         Uint8 b
3355         Uint8 a
3356         CODE:
3357                 RETVAL = rectangleRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3358         OUTPUT:
3359                 RETVAL
3360
3361 int
3362 GFXBoxColor ( dst, x1, y1, x2, y2, color )
3363         SDL_Surface* dst
3364         Sint16 x1
3365         Sint16 y1
3366         Sint16 x2
3367         Sint16 y2
3368         Uint32 color
3369         CODE:
3370                 RETVAL = boxColor( dst, x1, y1, x2, y2, color );
3371         OUTPUT:
3372                 RETVAL
3373
3374 int
3375 GFXBoxRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3376         SDL_Surface* dst;
3377         Sint16 x1
3378         Sint16 y1
3379         Sint16 x2
3380         Sint16 y2
3381         Uint8 r
3382         Uint8 g
3383         Uint8 b
3384         Uint8 a
3385         CODE:
3386                 RETVAL = boxRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3387         OUTPUT:
3388                 RETVAL
3389
3390 int
3391 GFXLineColor ( dst, x1, y1, x2, y2, color )
3392         SDL_Surface* dst
3393         Sint16 x1
3394         Sint16 y1
3395         Sint16 x2
3396         Sint16 y2
3397         Uint32 color
3398         CODE:
3399                 RETVAL = lineColor( dst, x1, y1, x2, y2, color );
3400         OUTPUT:
3401                 RETVAL
3402
3403 int
3404 GFXLineRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3405         SDL_Surface* dst
3406         Sint16 x1
3407         Sint16 y1
3408         Sint16 x2
3409         Sint16 y2
3410         Uint8 r
3411         Uint8 g
3412         Uint8 b
3413         Uint8 a
3414         CODE:
3415                 RETVAL = lineRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3416         OUTPUT:
3417                 RETVAL
3418
3419 int
3420 GFXAalineColor ( dst, x1, y1, x2, y2, color )
3421         SDL_Surface* dst
3422         Sint16 x1
3423         Sint16 y1
3424         Sint16 x2
3425         Sint16 y2
3426         Uint32 color
3427         CODE:
3428                 RETVAL = aalineColor( dst, x1, y1, x2, y2, color );
3429         OUTPUT:
3430                 RETVAL
3431
3432 int
3433 GFXAalineRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3434         SDL_Surface* dst
3435         Sint16 x1
3436         Sint16 y1
3437         Sint16 x2
3438         Sint16 y2
3439         Uint8 r
3440         Uint8 g
3441         Uint8 b
3442         Uint8 a
3443         CODE:
3444                 RETVAL = aalineRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3445         OUTPUT:
3446                 RETVAL
3447
3448 int
3449 GFXCircleColor ( dst, x, y, r, color )
3450         SDL_Surface* dst
3451         Sint16 x
3452         Sint16 y
3453         Sint16 r
3454         Uint32 color
3455         CODE:
3456                 RETVAL = circleColor( dst, x, y, r, color );
3457         OUTPUT:
3458                 RETVAL
3459
3460 int
3461 GFXCircleRGBA ( dst, x, y, rad, r, g, b, a )
3462         SDL_Surface* dst
3463         Sint16 x
3464         Sint16 y
3465         Sint16 rad
3466         Uint8 r
3467         Uint8 g
3468         Uint8 b
3469         Uint8 a
3470         CODE:
3471                 RETVAL = circleRGBA( dst, x, y, rad, r, g, b, a );
3472         OUTPUT:
3473                 RETVAL
3474
3475 int
3476 GFXAacircleColor ( dst, x, y, r, color )
3477         SDL_Surface* dst
3478         Sint16 x
3479         Sint16 y
3480         Sint16 r
3481         Uint32 color
3482         CODE:
3483                 RETVAL = aacircleColor( dst, x, y, r, color );
3484         OUTPUT:
3485                 RETVAL
3486
3487 int
3488 GFXAacircleRGBA ( dst, x, y, rad, r, g, b, a )
3489         SDL_Surface* dst
3490         Sint16 x
3491         Sint16 y
3492         Sint16 rad
3493         Uint8 r
3494         Uint8 g
3495         Uint8 b
3496         Uint8 a
3497         CODE:
3498                 RETVAL = aacircleRGBA( dst, x, y, rad, r, g, b, a );
3499         OUTPUT:
3500                 RETVAL
3501
3502 int
3503 GFXFilledCircleColor ( dst, x, y, r, color )
3504         SDL_Surface* dst
3505         Sint16 x
3506         Sint16 y
3507         Sint16 r
3508         Uint32 color
3509         CODE:
3510                 RETVAL = filledCircleColor( dst, x, y, r, color );
3511         OUTPUT:
3512                 RETVAL
3513
3514 int
3515 GFXFilledCircleRGBA ( dst, x, y, rad, r, g, b, a )
3516         SDL_Surface* dst
3517         Sint16 x
3518         Sint16 y
3519         Sint16 rad
3520         Uint8 r
3521         Uint8 g
3522         Uint8 b
3523         Uint8 a
3524         CODE:
3525                 RETVAL = filledCircleRGBA( dst, x, y, rad, r, g, b, a );
3526         OUTPUT:
3527                 RETVAL
3528
3529 int
3530 GFXEllipseColor ( dst, x, y, rx, ry, color )
3531         SDL_Surface* dst
3532         Sint16 x
3533         Sint16 y
3534         Sint16 rx
3535         Sint16 ry
3536         Uint32 color
3537         CODE:
3538                 RETVAL = ellipseColor( dst, x, y, rx, ry, color );
3539         OUTPUT:
3540                 RETVAL
3541
3542 int
3543 GFXEllipseRGBA ( dst, x, y, rx, ry, r, g, b, a )
3544         SDL_Surface* dst
3545         Sint16 x
3546         Sint16 y
3547         Sint16  rx
3548         Sint16 ry
3549         Uint8 r
3550         Uint8 g
3551         Uint8 b
3552         Uint8 a
3553         CODE:
3554                 RETVAL = ellipseRGBA( dst, x, y, rx, ry, r, g, b, a );
3555         OUTPUT:
3556                 RETVAL
3557
3558 int
3559 GFXAaellipseColor ( dst, xc, yc, rx, ry, color )
3560         SDL_Surface* dst
3561         Sint16 xc
3562         Sint16 yc
3563         Sint16 rx
3564         Sint16 ry
3565         Uint32 color
3566         CODE:
3567                 RETVAL = aaellipseColor( dst, xc, yc, rx, ry, color );
3568         OUTPUT:
3569                 RETVAL
3570
3571 int
3572 GFXAaellipseRGBA ( dst, x, y, rx, ry, r, g, b, a )
3573         SDL_Surface* dst
3574         Sint16 x
3575         Sint16 y
3576         Sint16 rx
3577         Sint16 ry
3578         Uint8 r
3579         Uint8 g
3580         Uint8 b
3581         Uint8 a
3582         CODE:
3583                 RETVAL = aaellipseRGBA( dst, x, y, rx, ry, r, g, b, a );
3584         OUTPUT:
3585                 RETVAL
3586
3587 int
3588 GFXFilledEllipseColor ( dst, x, y, rx, ry, color )
3589         SDL_Surface* dst
3590         Sint16 x
3591         Sint16 y
3592         Sint16 rx
3593         Sint16 ry
3594         Uint32 color
3595         CODE:
3596                 RETVAL = filledEllipseColor( dst, x, y, rx, ry, color );
3597         OUTPUT:
3598                 RETVAL
3599
3600 int
3601 GFXFilledEllipseRGBA ( dst, x, y, rx, ry, r, g, b, a )
3602         SDL_Surface* dst
3603         Sint16 x
3604         Sint16 y
3605         Sint16 rx
3606         Sint16 ry
3607         Uint8 r
3608         Uint8 g
3609         Uint8 b
3610         Uint8 a
3611         CODE:
3612                 RETVAL = filledEllipseRGBA( dst, x, y, rx, ry, r, g, b, a );
3613         OUTPUT:
3614                 RETVAL
3615
3616 int
3617 GFXFilledPieColor ( dst, x, y, rad, start, end, color )
3618         SDL_Surface* dst
3619         Sint16 x
3620         Sint16 y
3621         Sint16 rad
3622         Sint16 start
3623         Sint16 end
3624         Uint32 color
3625         CODE:
3626                 RETVAL = filledPieColor( dst, x, y, rad, start, end, color );
3627         OUTPUT:
3628                 RETVAL
3629
3630 int
3631 GFXFilledPieRGBA ( dst, x, y, rad, start, end, r, g, b, a )
3632         SDL_Surface* dst
3633         Sint16 x
3634         Sint16 y
3635         Sint16 rad
3636         Sint16 start
3637         Sint16 end
3638         Uint8 r
3639         Uint8 g
3640         Uint8 b
3641         Uint8 a
3642         CODE:
3643                 RETVAL = filledPieRGBA( dst, x, y, rad, start, end, r, g, b, a );
3644         OUTPUT:
3645                 RETVAL
3646
3647 int
3648 GFXPolygonColor ( dst, vx, vy, n, color )
3649         SDL_Surface* dst
3650         Sint16* vx
3651         Sint16* vy
3652         int n
3653         Uint32 color;
3654         CODE:
3655                 RETVAL = polygonColor( dst, vx, vy, n, color );
3656         OUTPUT:
3657                 RETVAL
3658
3659 int
3660 GFXPolygonRGBA ( dst, vx, vy, n, r, g, b, a )
3661         SDL_Surface* dst
3662         Sint16* vx
3663         Sint16* vy
3664         int n
3665         Uint8 r
3666         Uint8 g
3667         Uint8 b
3668         Uint8 a
3669         CODE:
3670                 RETVAL = polygonRGBA( dst, vx, vy, n, r, g, b, a );
3671         OUTPUT:
3672                 RETVAL
3673
3674 int
3675 GFXAapolygonColor ( dst, vx, vy, n, color )
3676         SDL_Surface* dst
3677         Sint16* vx
3678         Sint16* vy
3679         int n
3680         Uint32 color
3681         CODE:
3682                 RETVAL = aapolygonColor( dst, vx, vy, n, color );
3683         OUTPUT:
3684                 RETVAL
3685
3686 int
3687 GFXAapolygonRGBA ( dst, vx, vy, n, r, g, b, a )
3688         SDL_Surface* dst
3689         Sint16* vx
3690         Sint16* vy
3691         int n
3692         Uint8 r
3693         Uint8 g
3694         Uint8 b
3695         Uint8 a
3696         CODE:
3697                 RETVAL = aapolygonRGBA( dst, vx, vy, n, r, g, b, a );
3698         OUTPUT:
3699                 RETVAL
3700
3701 int
3702 GFXFilledPolygonColor ( dst, vx, vy, n, color )
3703         SDL_Surface* dst
3704         Sint16* vx
3705         Sint16* vy
3706         int n
3707         int color
3708         CODE:
3709                 RETVAL = filledPolygonColor( dst, vx, vy, n, color );
3710         OUTPUT:
3711                 RETVAL
3712
3713 int
3714 GFXFilledPolygonRGBA ( dst, vx, vy, n, r, g, b, a )
3715         SDL_Surface* dst
3716         Sint16* vx
3717         Sint16* vy
3718         int n
3719         Uint8 r
3720         Uint8 g
3721         Uint8 b
3722         Uint8 a
3723         CODE:
3724                 RETVAL = filledPolygonRGBA( dst, vx, vy, n, r, g, b, a );
3725         OUTPUT:
3726                 RETVAL
3727
3728 int
3729 GFXCharacterColor ( dst, x, y, c, color )
3730         SDL_Surface* dst
3731         Sint16 x
3732         Sint16 y
3733         char c
3734         Uint32 color
3735         CODE:
3736                 RETVAL = characterColor( dst, x, y, c, color );
3737         OUTPUT:
3738                 RETVAL
3739
3740 int
3741 GFXCharacterRGBA ( dst, x, y, c, r, g, b, a )
3742         SDL_Surface* dst
3743         Sint16 x
3744         Sint16 y
3745         char c
3746         Uint8 r
3747         Uint8 g
3748         Uint8 b
3749         Uint8 a
3750         CODE:
3751                 RETVAL = characterRGBA( dst, x, y, c, r, g, b, a );
3752         OUTPUT:
3753                 RETVAL
3754
3755 int
3756 GFXStringColor ( dst, x, y, c, color )
3757         SDL_Surface* dst
3758         Sint16 x
3759         Sint16 y
3760         char* c
3761         Uint32 color
3762         CODE:
3763                 RETVAL = stringColor( dst, x, y, c, color );
3764         OUTPUT:
3765                 RETVAL
3766
3767 int
3768 GFXStringRGBA ( dst, x, y, c, r, g, b, a )
3769         SDL_Surface* dst
3770         Sint16 x
3771         Sint16 y
3772         char* c
3773         Uint8 r
3774         Uint8 g
3775         Uint8 b
3776         Uint8 a
3777         CODE:
3778                 RETVAL = stringRGBA( dst, x, y, c, r, g, b, a );
3779         OUTPUT:
3780                 RETVAL
3781
3782 #endif
3783
3784
3785 #ifdef HAVE_SDL_SVG
3786
3787 SDL_svg_context *
3788 SVG_Load ( filename )
3789         char* filename
3790         CODE:
3791                 RETVAL = SVG_Load(filename);
3792         OUTPUT:
3793                 RETVAL
3794
3795 SDL_svg_context *
3796 SVG_LoadBuffer ( data, len )
3797         char* data
3798         int len
3799         CODE:
3800                 RETVAL = SVG_LoadBuffer(data,len);
3801         OUTPUT:
3802                 RETVAL
3803
3804 int
3805 SVG_SetOffset ( source, xoff, yoff )
3806         SDL_svg_context* source
3807         double xoff
3808         double yoff
3809         CODE:
3810                 RETVAL = SVG_SetOffset(source,xoff,yoff);
3811         OUTPUT:
3812                 RETVAL
3813
3814 int
3815 SVG_SetScale ( source, xscale, yscale )
3816         SDL_svg_context* source
3817         double xscale
3818         double yscale
3819         CODE:
3820                 RETVAL = SVG_SetScale(source,xscale,yscale);
3821         OUTPUT:
3822                 RETVAL
3823
3824 int
3825 SVG_RenderToSurface ( source, x, y, dest )
3826         SDL_svg_context* source
3827         int x
3828         int y
3829         SDL_Surface* dest;
3830         CODE:
3831                 RETVAL = SVG_RenderToSurface(source,x,y,dest);
3832         OUTPUT:
3833                 RETVAL
3834
3835 void
3836 SVG_Free ( source )
3837         SDL_svg_context* source
3838         CODE:
3839                 SVG_Free(source);       
3840
3841 void
3842 SVG_Set_Flags ( source, flags )
3843         SDL_svg_context* source
3844         Uint32 flags
3845         CODE:
3846                 SVG_Set_Flags(source,flags);
3847
3848 float
3849 SVG_Width ( source )
3850         SDL_svg_context* source
3851         CODE:
3852                 RETVAL = SVG_Width(source);
3853         OUTPUT:
3854                 RETVAL
3855
3856 float
3857 SVG_HEIGHT ( source )
3858         SDL_svg_context* source
3859         CODE:
3860                 RETVAL = SVG_Height(source);
3861         OUTPUT:
3862                 RETVAL
3863
3864 void
3865 SVG_SetClipping ( source, minx, miny, maxx, maxy )
3866         SDL_svg_context* source
3867         int minx
3868         int miny
3869         int maxx
3870         int maxy
3871         CODE:
3872                 SVG_SetClipping(source,minx,miny,maxx,maxy);
3873
3874 int
3875 SVG_Version ( )
3876         CODE:
3877                 RETVAL = SVG_Version();
3878         OUTPUT:
3879                 RETVAL
3880
3881
3882 #endif
3883
3884 #ifdef HAVE_SDL_SOUND
3885
3886 Uint16
3887 SoundAudioInfoFormat ( audioinfo )
3888         Sound_AudioInfo* audioinfo
3889         CODE:
3890                 RETVAL = audioinfo->format;
3891         OUTPUT:
3892                 RETVAL
3893
3894 Uint8
3895 SoundAudioInfoChannels ( audioinfo )
3896         Sound_AudioInfo* audioinfo
3897         CODE:
3898                 RETVAL = audioinfo->channels;
3899         OUTPUT:
3900                 RETVAL
3901
3902 Uint32
3903 SoundAudioInforate ( audioinfo )
3904         Sound_AudioInfo* audioinfo
3905         CODE:
3906                 RETVAL = audioinfo->rate;
3907         OUTPUT:
3908                 RETVAL
3909
3910 AV*
3911 SoundDecoderInfoExtensions ( decoderinfo )
3912         Sound_DecoderInfo* decoderinfo
3913         CODE:
3914                 const char **ext;
3915                 for ( ext = decoderinfo->extensions; *ext != NULL; ext++ ){
3916                         av_push(RETVAL,newSVpv(*ext,0));
3917                 }
3918         OUTPUT:
3919                 RETVAL
3920
3921 const char*
3922 SoundDecoderInfoDescription ( decoderinfo )
3923         Sound_DecoderInfo* decoderinfo
3924         CODE:
3925                 RETVAL = decoderinfo->description;
3926         OUTPUT:
3927                 RETVAL
3928
3929 const char*
3930 SoundDecoderInfoAuthor ( decoderinfo )
3931         Sound_DecoderInfo* decoderinfo
3932         CODE:
3933                 RETVAL = decoderinfo->author;
3934         OUTPUT:
3935                 RETVAL
3936
3937 const char*
3938 SoundDecoderInfoUrl ( decoderinfo )
3939         Sound_DecoderInfo* decoderinfo
3940         CODE:
3941                 RETVAL = decoderinfo->url;
3942         OUTPUT:
3943                 RETVAL
3944
3945 const Sound_DecoderInfo*
3946 SoundSampleDecoder ( sample ) 
3947         Sound_Sample* sample
3948         CODE:
3949                 RETVAL = sample->decoder;
3950         OUTPUT:
3951                 RETVAL
3952
3953 Sound_AudioInfo* 
3954 SoundSampleDesired ( sample )
3955         Sound_Sample* sample
3956         CODE:
3957                 RETVAL = &sample->desired;
3958         OUTPUT:
3959                 RETVAL
3960
3961 Sound_AudioInfo*
3962 SoundSampleAcutal ( sample )
3963         Sound_Sample* sample
3964         CODE:
3965                 RETVAL = &sample->actual;
3966         OUTPUT:
3967                 RETVAL
3968
3969 char*
3970 SoundSampleBuffer ( sample )
3971         Sound_Sample* sample
3972         CODE:
3973                 RETVAL = sample->buffer;
3974         OUTPUT:
3975                 RETVAL
3976
3977 Uint32
3978 SoundSampleBufferSize ( sample )
3979         Sound_Sample* sample
3980         CODE:
3981                 RETVAL = sample->buffer_size;
3982         OUTPUT:
3983                 RETVAL
3984
3985 Uint32
3986 SoundSampleFlags ( sample )
3987         Sound_Sample* sample
3988         CODE:
3989                 RETVAL = (Uint32)sample->flags;
3990         OUTPUT:
3991                 RETVAL
3992
3993 int
3994 Sound_Init ( )
3995         CODE:
3996                 RETVAL = Sound_Init();
3997         OUTPUT:
3998                 RETVAL
3999
4000 int
4001 Sound_Quit ( )
4002         CODE:
4003                 RETVAL = Sound_Quit();
4004         OUTPUT:
4005                 RETVAL
4006
4007 AV*
4008 Sound_AvailableDecoders ( )
4009         CODE:
4010                 RETVAL = newAV();
4011                 const Sound_DecoderInfo** sdi;
4012                 sdi = Sound_AvailableDecoders();
4013                 if (sdi != NULL)  {
4014                         for (;*sdi != NULL; ++sdi) {
4015                                 av_push(RETVAL,sv_2mortal(newSViv(PTR2IV(*sdi))));
4016                         }
4017                 }
4018         OUTPUT:
4019                 RETVAL
4020
4021 const char*
4022 Sound_GetError ( )
4023         CODE:
4024                 RETVAL = Sound_GetError();
4025         OUTPUT:
4026                 RETVAL
4027
4028 void
4029 Sound_ClearError ( )
4030         CODE:
4031                 Sound_ClearError();
4032
4033 Sound_Sample*
4034 Sound_NewSample ( rw, ext, desired, buffsize )
4035         SDL_RWops* rw
4036         const char* ext
4037         Sound_AudioInfo* desired
4038         Uint32 buffsize
4039         CODE:
4040                 RETVAL = Sound_NewSample(rw,ext,desired,buffsize);
4041         OUTPUT:
4042                 RETVAL
4043
4044 Sound_Sample*
4045 Sound_NewSampleFromMem ( data, size, ext, desired, buffsize )
4046         const Uint8 *data
4047         Uint32 size
4048         const char* ext
4049         Sound_AudioInfo* desired
4050         Uint32 buffsize
4051         CODE:
4052                 RETVAL = Sound_NewSampleFromMem(data,size,ext,desired,buffsize);
4053         OUTPUT:
4054                 RETVAL
4055
4056 Sound_Sample*
4057 Sound_NewSampleFromFile ( fname, desired, buffsize )
4058         const char* fname
4059         Sound_AudioInfo* desired
4060         Uint32 buffsize
4061         CODE:
4062                 RETVAL = Sound_NewSampleFromFile(fname,desired,buffsize);
4063         OUTPUT:
4064                 RETVAL
4065
4066 void
4067 Sound_FreeSample ( sample )
4068         Sound_Sample* sample
4069         CODE:
4070                 Sound_FreeSample(sample);
4071
4072 Sint32
4073 Sound_GetDuration ( sample )
4074         Sound_Sample* sample
4075         CODE:
4076                 RETVAL = Sound_GetDuration(sample);
4077         OUTPUT:
4078                 RETVAL
4079
4080 int
4081 Sound_SetBufferSize ( sample, size )
4082         Sound_Sample* sample
4083         Uint32 size
4084         CODE:
4085                 RETVAL = Sound_SetBufferSize(sample,size);
4086         OUTPUT:
4087                 RETVAL
4088
4089 Uint32
4090 Sound_Decode ( sample )
4091         Sound_Sample* sample
4092         CODE:
4093                 RETVAL = Sound_Decode(sample);
4094         OUTPUT:
4095                 RETVAL
4096
4097 Uint32
4098 Sound_DecodeAll ( sample ) 
4099         Sound_Sample* sample
4100         CODE:
4101                 RETVAL = Sound_DecodeAll(sample);
4102         OUTPUT:
4103                 RETVAL
4104
4105 int
4106 Sound_Rewind ( sample )
4107         Sound_Sample* sample
4108         CODE:
4109                 RETVAL = Sound_Rewind(sample);
4110         OUTPUT:
4111                 RETVAL
4112
4113 int
4114 Sound_Seek ( sample, ms )
4115         Sound_Sample* sample
4116         Uint32 ms
4117         CODE:
4118                 RETVAL = Sound_Seek(sample,ms);
4119         OUTPUT:
4120                 RETVAL
4121
4122 #endif
4123
4124 #ifdef HAVE_SDL_TTF
4125
4126 int
4127 TTF_Init ()
4128         CODE:
4129                 RETVAL = TTF_Init();
4130         OUTPUT:
4131                 RETVAL
4132
4133 void
4134 TTF_Quit ()
4135         CODE:
4136                 TTF_Quit();
4137
4138 TTF_Font*
4139 TTF_OpenFont ( file, ptsize )
4140         char *file
4141         int ptsize
4142         CODE:
4143                 char* CLASS = "SDL::TTF_Font";
4144                 RETVAL = TTF_OpenFont(file,ptsize);
4145         OUTPUT:
4146                 RETVAL
4147
4148 AV*
4149 TTF_SizeText ( font, text )
4150         TTF_Font *font
4151         char *text
4152         CODE:
4153                 int w,h;
4154                 RETVAL = newAV();
4155                 if(TTF_SizeText(font,text,&w,&h))
4156                 {
4157                         printf("TTF error at TTFSizeText: %s \n", TTF_GetError());
4158                         Perl_croak (aTHX_ "TTF error \n");
4159                 }
4160                 else
4161                 {
4162                         av_push(RETVAL,newSViv(w));
4163                         av_push(RETVAL,newSViv(h));
4164                         sv_2mortal((SV*)RETVAL);
4165                 }
4166         OUTPUT:
4167                 RETVAL
4168
4169 SDL_Surface*
4170 TTF_RenderText_Blended ( font, text, fg )
4171         TTF_Font *font
4172         char *text
4173         SDL_Color *fg
4174         CODE:
4175                 char* CLASS = "SDL::Surface";
4176                 RETVAL = TTF_RenderText_Blended(font,text,*fg);
4177         OUTPUT:
4178                 RETVAL
4179
4180 #endif
4181
4182 MODULE = SDL            PACKAGE = SDL
4183 PROTOTYPES : DISABLE
4184
4185