Skiping test for SDL_TTF because they are not aware of new API changes. It is illadvi...
[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 int
2791 LockYUVOverlay ( overlay )
2792         SDL_Overlay *overlay
2793         CODE:
2794                 RETVAL = SDL_LockYUVOverlay(overlay);
2795         OUTPUT:
2796                 RETVAL
2797
2798 void
2799 UnlockYUVOverlay ( overlay )
2800         SDL_Overlay *overlay
2801         CODE:
2802                 SDL_UnlockYUVOverlay(overlay);
2803
2804 int
2805 DisplayYUVOverlay ( overlay, dstrect )
2806         SDL_Overlay *overlay
2807         SDL_Rect *dstrect
2808         CODE:
2809                 RETVAL = SDL_DisplayYUVOverlay ( overlay, dstrect );
2810         OUTPUT:
2811                 RETVAL
2812
2813 Uint32
2814 OverlayFormat ( overlay, ... )
2815         SDL_Overlay *overlay
2816         CODE:
2817                 if ( items > 1 ) 
2818                         overlay->format = SvIV(ST(1));
2819                 RETVAL = overlay->format;
2820         OUTPUT:
2821                 RETVAL
2822
2823 int 
2824 OverlayW ( overlay, ... )
2825         SDL_Overlay *overlay
2826         CODE:
2827                 if ( items > 1 ) 
2828                         overlay->w = SvIV(ST(1));
2829                 RETVAL = overlay->w;
2830         OUTPUT:
2831                 RETVAL
2832
2833 int
2834 OverlayH ( overlay, ... )
2835         SDL_Overlay *overlay
2836         CODE:
2837                 if ( items > 1 )
2838                         overlay->h = SvIV(ST(1));
2839                 RETVAL = overlay->h;
2840         OUTPUT:
2841                 RETVAL 
2842
2843 int
2844 OverlayPlanes ( overlay, ... )
2845         SDL_Overlay *overlay
2846         CODE:
2847                 if ( items > 1 )
2848                         overlay->planes = SvIV(ST(1));
2849                 RETVAL = overlay->planes;
2850         OUTPUT:
2851                 RETVAL
2852
2853 Uint32
2854 OverlayHW ( overlay )
2855         SDL_Overlay *overlay
2856         CODE:
2857                 RETVAL = overlay->hw_overlay;
2858         OUTPUT:
2859                 RETVAL
2860
2861 Uint16*
2862 OverlayPitches ( overlay )
2863         SDL_Overlay *overlay
2864         CODE:
2865                 RETVAL = overlay->pitches;
2866         OUTPUT:
2867                 RETVAL
2868
2869 Uint8**
2870 OverlayPixels ( overlay )
2871         SDL_Overlay *overlay
2872         CODE:
2873                 RETVAL = overlay->pixels;
2874         OUTPUT:
2875                 RETVAL
2876
2877 int
2878 WMToggleFullScreen ( surface )
2879         SDL_Surface *surface
2880         CODE:
2881                 RETVAL = SDL_WM_ToggleFullScreen(surface);
2882         OUTPUT:
2883                 RETVAL
2884
2885 Uint32
2886 WMGrabInput ( mode )
2887         Uint32 mode
2888         CODE:
2889                 RETVAL = SDL_WM_GrabInput(mode);
2890         OUTPUT:
2891                 RETVAL
2892
2893 int
2894 WMIconifyWindow ()
2895         CODE:
2896                 RETVAL = SDL_WM_IconifyWindow();
2897         OUTPUT:
2898                 RETVAL
2899
2900 int
2901 ResizeEventW ( e )
2902         SDL_Event *e
2903         CODE:
2904                 RETVAL = e->resize.w;
2905         OUTPUT:
2906                 RETVAL
2907
2908 int
2909 ResizeEventH ( e )
2910         SDL_Event *e
2911         CODE:
2912                 RETVAL = e->resize.h;
2913         OUTPUT:
2914                 RETVAL
2915
2916 char*
2917 AudioDriverName ()
2918         CODE:
2919                 char name[32];
2920                 RETVAL = SDL_AudioDriverName(name,32);
2921         OUTPUT:
2922                 RETVAL
2923
2924 Uint32
2925 GetKeyState ( k )
2926         SDLKey k
2927         CODE:
2928                 if (k >= SDLK_LAST) Perl_croak (aTHX_ "Key out of range");      
2929                 RETVAL = SDL_GetKeyState(NULL)[k];
2930         OUTPUT:
2931                 RETVAL
2932
2933 #ifdef HAVE_SMPEG
2934
2935 SMPEG_Info *
2936 NewSMPEGInfo()
2937         CODE:   
2938                 RETVAL = (SMPEG_Info *) safemalloc (sizeof(SMPEG_Info));
2939         OUTPUT:
2940                 RETVAL
2941
2942 void
2943 FreeSMPEGInfo ( info )
2944         SMPEG_Info *info
2945         CODE:   
2946                 safefree(info);
2947
2948 int
2949 SMPEGInfoHasAudio ( info )
2950         SMPEG_Info* info
2951         CODE:
2952                 RETVAL = info->has_audio;
2953         OUTPUT:
2954                 RETVAL
2955
2956 int
2957 SMPEGInfoHasVideo ( info )
2958         SMPEG_Info* info
2959         CODE:
2960                 RETVAL = info->has_video;
2961         OUTPUT:
2962                 RETVAL
2963
2964 int
2965 SMPEGInfoWidth ( info )
2966         SMPEG_Info* info
2967         CODE:
2968                 RETVAL = info->width;
2969         OUTPUT:
2970                 RETVAL
2971
2972 int
2973 SMPEGInfoHeight ( info )
2974         SMPEG_Info* info
2975         CODE:
2976                 RETVAL = info->height;
2977         OUTPUT:
2978                 RETVAL
2979
2980 int
2981 SMPEGInfoCurrentFrame ( info )
2982         SMPEG_Info* info
2983         CODE:
2984                 RETVAL = info->current_frame;
2985         OUTPUT:
2986                 RETVAL
2987
2988 double
2989 SMPEGInfoCurrentFPS ( info )
2990         SMPEG_Info* info
2991         CODE:
2992                 RETVAL = info->current_fps;
2993         OUTPUT:
2994                 RETVAL
2995
2996 int
2997 SMPEGInfoCurrentAudioFrame ( info )
2998         SMPEG_Info* info
2999         CODE:
3000                 RETVAL = info->audio_current_frame;
3001         OUTPUT:
3002                 RETVAL
3003
3004 int
3005 SMPEGInfoCurrentOffset ( info )
3006         SMPEG_Info* info
3007         CODE:
3008                 RETVAL = info->current_offset;
3009         OUTPUT:
3010                 RETVAL
3011
3012 int
3013 SMPEGInfoTotalSize ( info )
3014         SMPEG_Info* info
3015         CODE:
3016                 RETVAL = info->total_size;
3017         OUTPUT:
3018                 RETVAL
3019
3020 double
3021 SMPEGInfoCurrentTime ( info )
3022         SMPEG_Info* info
3023         CODE:
3024                 RETVAL = info->current_time;
3025         OUTPUT:
3026                 RETVAL
3027
3028 double
3029 SMPEGInfoTotalTime ( info )
3030         SMPEG_Info* info
3031         CODE:
3032                 RETVAL = info->total_time;
3033         OUTPUT:
3034                 RETVAL
3035
3036 char *
3037 SMPEGError ( mpeg )
3038         SMPEG* mpeg
3039         CODE:   
3040                 RETVAL = SMPEG_error(mpeg);
3041         OUTPUT:
3042                 RETVAL
3043
3044 SMPEG*
3045 NewSMPEG ( filename, info, use_audio )
3046         char* filename
3047         SMPEG_Info* info
3048         int use_audio
3049         CODE:   
3050 #ifdef HAVE_SDL_MIXER
3051                 RETVAL = SMPEG_new(filename,info,0);
3052 #else
3053                 RETVAL = SMPEG_new(filename,info,use_audio);
3054 #endif
3055         OUTPUT:
3056                 RETVAL
3057
3058 void
3059 FreeSMPEG ( mpeg )
3060         SMPEG* mpeg
3061         CODE:
3062                 SMPEG_delete(mpeg);
3063
3064 void
3065 SMPEGEnableAudio ( mpeg , flag )
3066         SMPEG* mpeg
3067         int flag
3068         CODE:   
3069                 SMPEG_enableaudio(mpeg,flag);
3070 #ifdef HAVE_SDL_MIXER
3071                 sdl_perl_use_smpeg_audio = flag;
3072 #endif
3073
3074 void
3075 SMPEGEnableVideo ( mpeg , flag )
3076         SMPEG* mpeg
3077         int flag
3078         CODE:   
3079                 SMPEG_enablevideo(mpeg,flag);
3080
3081 void
3082 SMPEGSetVolume ( mpeg , volume )
3083         SMPEG* mpeg
3084         int volume
3085         CODE:   
3086                 SMPEG_setvolume(mpeg,volume);
3087
3088 void
3089 SMPEGSetDisplay ( mpeg, dest, surfLock )
3090         SMPEG* mpeg
3091         SDL_Surface* dest
3092         SDL_mutex*  surfLock
3093         CODE:
3094                 SMPEG_setdisplay(mpeg,dest,surfLock,NULL);
3095
3096 void
3097 SMPEGScaleXY ( mpeg, w, h)
3098         SMPEG* mpeg
3099         int w
3100         int h
3101         CODE:
3102                 SMPEG_scaleXY(mpeg,w,h);
3103
3104 void
3105 SMPEGScale ( mpeg, scale )
3106         SMPEG* mpeg
3107         int scale
3108         CODE:
3109                 SMPEG_scale(mpeg,scale);
3110
3111 void
3112 SMPEGPlay ( mpeg )
3113         SMPEG* mpeg
3114         CODE:
3115                 SDL_AudioSpec audiofmt;
3116                 Uint16 format;
3117                 int freq, channels;
3118 #ifdef HAVE_SDL_MIXER
3119                 if  (sdl_perl_use_smpeg_audio ) {
3120                         SMPEG_enableaudio(mpeg, 0);
3121                         Mix_QuerySpec(&freq, &format, &channels);
3122                         audiofmt.format = format;
3123                         audiofmt.freq = freq;
3124                         audiofmt.channels = channels;
3125                         SMPEG_actualSpec(mpeg, &audiofmt);
3126                         Mix_HookMusic(SMPEG_playAudioSDL, mpeg);
3127                         SMPEG_enableaudio(mpeg, 1);
3128                 }
3129 #endif
3130                 SMPEG_play(mpeg);
3131
3132 SMPEGstatus
3133 SMPEGStatus ( mpeg )
3134         SMPEG* mpeg
3135         CODE:
3136                 RETVAL = SMPEG_status(mpeg);
3137         OUTPUT:
3138                 RETVAL
3139
3140 void
3141 SMPEGPause ( mpeg )
3142         SMPEG* mpeg
3143         CODE:
3144                 SMPEG_pause(mpeg);
3145
3146 void
3147 SMPEGLoop ( mpeg, repeat )
3148         SMPEG* mpeg
3149         int repeat
3150         CODE:
3151                 SMPEG_loop(mpeg,repeat);
3152
3153 void
3154 SMPEGStop ( mpeg )
3155         SMPEG* mpeg
3156         CODE:
3157                 SMPEG_stop(mpeg);
3158 #ifdef HAVE_SDL_MIXER
3159                 Mix_HookMusic(NULL, NULL);
3160 #endif
3161
3162 void
3163 SMPEGRewind ( mpeg )
3164         SMPEG* mpeg
3165         CODE:
3166                 SMPEG_rewind(mpeg);
3167
3168 void
3169 SMPEGSeek ( mpeg, bytes )
3170         SMPEG* mpeg
3171         int bytes
3172         CODE:
3173                 SMPEG_seek(mpeg,bytes);
3174
3175 void
3176 SMPEGSkip ( mpeg, seconds )
3177         SMPEG* mpeg
3178         float seconds
3179         CODE:
3180                 SMPEG_skip(mpeg,seconds);
3181
3182 void
3183 SMPEGSetDisplayRegion ( mpeg, rect )
3184         SMPEG* mpeg
3185         SDL_Rect* rect
3186         CODE:
3187                 SMPEG_setdisplayregion(mpeg,rect->x,rect->y,rect->w,rect->h);
3188
3189 void
3190 SMPEGRenderFrame ( mpeg, frame )
3191         SMPEG* mpeg
3192         int frame
3193         CODE:
3194                 SMPEG_renderFrame(mpeg,frame);
3195
3196 SMPEG_Info *
3197 SMPEGGetInfo ( mpeg )
3198         SMPEG* mpeg
3199         CODE:
3200                 RETVAL = (SMPEG_Info *) safemalloc (sizeof(SMPEG_Info));
3201                 SMPEG_getinfo(mpeg,RETVAL);
3202         OUTPUT:
3203                 RETVAL
3204         
3205
3206 #endif
3207
3208 #ifdef HAVE_SDL_GFX
3209
3210 =cut
3211
3212 SDL_Surface *
3213 GFXRotoZoom ( src, angle, zoom, smooth)
3214         SDL_Surface * src
3215         double angle
3216         double zoom
3217         int smooth
3218         CODE:
3219                 RETVAL = rotozoomSurface( src, angle, zoom, smooth);
3220         OUTPUT:
3221                 RETVAL
3222
3223 SDL_Surface *
3224 GFXZoom ( src, zoomx, zoomy, smooth)
3225         SDL_Surface *src
3226         double zoomx
3227         double zoomy
3228         int smooth
3229         CODE:
3230                 RETVAL = zoomSurface( src, zoomx, zoomy, smooth);
3231         OUTPUT:
3232                 RETVAL
3233
3234 =cut
3235
3236 int
3237 GFXPixelColor ( dst, x, y, color )
3238         SDL_Surface* dst
3239         Sint16 x
3240         Sint16 y
3241         Uint32 color
3242         CODE:
3243                 RETVAL = pixelColor( dst, x, y, color);
3244         OUTPUT:
3245                 RETVAL
3246
3247 int
3248 GFXPixelRGBA ( dst, x, y, r, g, b, a )
3249         SDL_Surface* dst
3250         Sint16 x
3251         Sint16 y
3252         Uint8 r
3253         Uint8 g
3254         Uint8 b
3255         Uint8 a
3256         CODE:
3257                 RETVAL = pixelRGBA( dst, x, y, r, g, b, a );
3258         OUTPUT:
3259                 RETVAL
3260
3261 int
3262 GFXHlineColor ( dst, x1, x2, y, color )
3263         SDL_Surface* dst
3264         Sint16 x1
3265         Sint16 x2
3266         Sint16 y
3267         Uint32 color
3268         CODE:
3269                 RETVAL = hlineColor( dst, x1, x2, y, color );
3270         OUTPUT:
3271                 RETVAL
3272
3273 int
3274 GFXHlineRGBA ( dst, x1, x2, y, r, g, b, a )
3275         SDL_Surface* dst
3276         Sint16 x1
3277         Sint16 x2
3278         Sint16 y
3279         Uint8 r
3280         Uint8 g
3281         Uint8 b
3282         Uint8 a
3283         CODE:
3284                 RETVAL = hlineRGBA( dst, x1, x2, y, r, g, b, a );
3285         OUTPUT:
3286                 RETVAL
3287
3288 int
3289 GFXVlineColor ( dst, x, y1, y2, color )
3290         SDL_Surface* dst
3291         Sint16 x
3292         Sint16 y1
3293         Sint16 y2
3294         Uint32 color
3295         CODE:
3296                 RETVAL = vlineColor( dst, x, y1, y2, color );
3297         OUTPUT:
3298                 RETVAL
3299
3300 int
3301 GFXVlineRGBA ( dst, x, y1, y2, r, g, b, a )
3302         SDL_Surface* dst
3303         Sint16 x
3304         Sint16 y1
3305         Sint16 y2
3306         Uint8 r
3307         Uint8 g
3308         Uint8 b
3309         Uint8 a
3310         CODE:
3311                 RETVAL = vlineRGBA( dst, x, y1, y2, r, g, b, a );
3312         OUTPUT:
3313                 RETVAL
3314
3315 int
3316 GFXRectangleColor ( dst, x1, y1, x2, y2, color )
3317         SDL_Surface* dst
3318         Sint16 x1
3319         Sint16 y1
3320         Sint16 x2
3321         Sint16 y2
3322         Uint32 color
3323         CODE:
3324                 RETVAL = rectangleColor( dst, x1, y1, x2, y2, color );
3325         OUTPUT:
3326                 RETVAL
3327
3328 int
3329 GFXRectangleRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3330         SDL_Surface* dst
3331         Sint16 x1
3332         Sint16 y1
3333         Sint16 x2
3334         Sint16 y2
3335         Uint8 r
3336         Uint8 g
3337         Uint8 b
3338         Uint8 a
3339         CODE:
3340                 RETVAL = rectangleRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3341         OUTPUT:
3342                 RETVAL
3343
3344 int
3345 GFXBoxColor ( dst, x1, y1, x2, y2, color )
3346         SDL_Surface* dst
3347         Sint16 x1
3348         Sint16 y1
3349         Sint16 x2
3350         Sint16 y2
3351         Uint32 color
3352         CODE:
3353                 RETVAL = boxColor( dst, x1, y1, x2, y2, color );
3354         OUTPUT:
3355                 RETVAL
3356
3357 int
3358 GFXBoxRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3359         SDL_Surface* dst;
3360         Sint16 x1
3361         Sint16 y1
3362         Sint16 x2
3363         Sint16 y2
3364         Uint8 r
3365         Uint8 g
3366         Uint8 b
3367         Uint8 a
3368         CODE:
3369                 RETVAL = boxRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3370         OUTPUT:
3371                 RETVAL
3372
3373 int
3374 GFXLineColor ( dst, x1, y1, x2, y2, color )
3375         SDL_Surface* dst
3376         Sint16 x1
3377         Sint16 y1
3378         Sint16 x2
3379         Sint16 y2
3380         Uint32 color
3381         CODE:
3382                 RETVAL = lineColor( dst, x1, y1, x2, y2, color );
3383         OUTPUT:
3384                 RETVAL
3385
3386 int
3387 GFXLineRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3388         SDL_Surface* dst
3389         Sint16 x1
3390         Sint16 y1
3391         Sint16 x2
3392         Sint16 y2
3393         Uint8 r
3394         Uint8 g
3395         Uint8 b
3396         Uint8 a
3397         CODE:
3398                 RETVAL = lineRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3399         OUTPUT:
3400                 RETVAL
3401
3402 int
3403 GFXAalineColor ( dst, x1, y1, x2, y2, color )
3404         SDL_Surface* dst
3405         Sint16 x1
3406         Sint16 y1
3407         Sint16 x2
3408         Sint16 y2
3409         Uint32 color
3410         CODE:
3411                 RETVAL = aalineColor( dst, x1, y1, x2, y2, color );
3412         OUTPUT:
3413                 RETVAL
3414
3415 int
3416 GFXAalineRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3417         SDL_Surface* dst
3418         Sint16 x1
3419         Sint16 y1
3420         Sint16 x2
3421         Sint16 y2
3422         Uint8 r
3423         Uint8 g
3424         Uint8 b
3425         Uint8 a
3426         CODE:
3427                 RETVAL = aalineRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3428         OUTPUT:
3429                 RETVAL
3430
3431 int
3432 GFXCircleColor ( dst, x, y, r, color )
3433         SDL_Surface* dst
3434         Sint16 x
3435         Sint16 y
3436         Sint16 r
3437         Uint32 color
3438         CODE:
3439                 RETVAL = circleColor( dst, x, y, r, color );
3440         OUTPUT:
3441                 RETVAL
3442
3443 int
3444 GFXCircleRGBA ( dst, x, y, rad, r, g, b, a )
3445         SDL_Surface* dst
3446         Sint16 x
3447         Sint16 y
3448         Sint16 rad
3449         Uint8 r
3450         Uint8 g
3451         Uint8 b
3452         Uint8 a
3453         CODE:
3454                 RETVAL = circleRGBA( dst, x, y, rad, r, g, b, a );
3455         OUTPUT:
3456                 RETVAL
3457
3458 int
3459 GFXAacircleColor ( dst, x, y, r, color )
3460         SDL_Surface* dst
3461         Sint16 x
3462         Sint16 y
3463         Sint16 r
3464         Uint32 color
3465         CODE:
3466                 RETVAL = aacircleColor( dst, x, y, r, color );
3467         OUTPUT:
3468                 RETVAL
3469
3470 int
3471 GFXAacircleRGBA ( dst, x, y, rad, r, g, b, a )
3472         SDL_Surface* dst
3473         Sint16 x
3474         Sint16 y
3475         Sint16 rad
3476         Uint8 r
3477         Uint8 g
3478         Uint8 b
3479         Uint8 a
3480         CODE:
3481                 RETVAL = aacircleRGBA( dst, x, y, rad, r, g, b, a );
3482         OUTPUT:
3483                 RETVAL
3484
3485 int
3486 GFXFilledCircleColor ( dst, x, y, r, color )
3487         SDL_Surface* dst
3488         Sint16 x
3489         Sint16 y
3490         Sint16 r
3491         Uint32 color
3492         CODE:
3493                 RETVAL = filledCircleColor( dst, x, y, r, color );
3494         OUTPUT:
3495                 RETVAL
3496
3497 int
3498 GFXFilledCircleRGBA ( dst, x, y, rad, r, g, b, a )
3499         SDL_Surface* dst
3500         Sint16 x
3501         Sint16 y
3502         Sint16 rad
3503         Uint8 r
3504         Uint8 g
3505         Uint8 b
3506         Uint8 a
3507         CODE:
3508                 RETVAL = filledCircleRGBA( dst, x, y, rad, r, g, b, a );
3509         OUTPUT:
3510                 RETVAL
3511
3512 int
3513 GFXEllipseColor ( dst, x, y, rx, ry, color )
3514         SDL_Surface* dst
3515         Sint16 x
3516         Sint16 y
3517         Sint16 rx
3518         Sint16 ry
3519         Uint32 color
3520         CODE:
3521                 RETVAL = ellipseColor( dst, x, y, rx, ry, color );
3522         OUTPUT:
3523                 RETVAL
3524
3525 int
3526 GFXEllipseRGBA ( dst, x, y, rx, ry, r, g, b, a )
3527         SDL_Surface* dst
3528         Sint16 x
3529         Sint16 y
3530         Sint16  rx
3531         Sint16 ry
3532         Uint8 r
3533         Uint8 g
3534         Uint8 b
3535         Uint8 a
3536         CODE:
3537                 RETVAL = ellipseRGBA( dst, x, y, rx, ry, r, g, b, a );
3538         OUTPUT:
3539                 RETVAL
3540
3541 int
3542 GFXAaellipseColor ( dst, xc, yc, rx, ry, color )
3543         SDL_Surface* dst
3544         Sint16 xc
3545         Sint16 yc
3546         Sint16 rx
3547         Sint16 ry
3548         Uint32 color
3549         CODE:
3550                 RETVAL = aaellipseColor( dst, xc, yc, rx, ry, color );
3551         OUTPUT:
3552                 RETVAL
3553
3554 int
3555 GFXAaellipseRGBA ( dst, x, y, rx, ry, r, g, b, a )
3556         SDL_Surface* dst
3557         Sint16 x
3558         Sint16 y
3559         Sint16 rx
3560         Sint16 ry
3561         Uint8 r
3562         Uint8 g
3563         Uint8 b
3564         Uint8 a
3565         CODE:
3566                 RETVAL = aaellipseRGBA( dst, x, y, rx, ry, r, g, b, a );
3567         OUTPUT:
3568                 RETVAL
3569
3570 int
3571 GFXFilledEllipseColor ( dst, x, y, rx, ry, color )
3572         SDL_Surface* dst
3573         Sint16 x
3574         Sint16 y
3575         Sint16 rx
3576         Sint16 ry
3577         Uint32 color
3578         CODE:
3579                 RETVAL = filledEllipseColor( dst, x, y, rx, ry, color );
3580         OUTPUT:
3581                 RETVAL
3582
3583 int
3584 GFXFilledEllipseRGBA ( dst, x, y, rx, ry, r, g, b, a )
3585         SDL_Surface* dst
3586         Sint16 x
3587         Sint16 y
3588         Sint16 rx
3589         Sint16 ry
3590         Uint8 r
3591         Uint8 g
3592         Uint8 b
3593         Uint8 a
3594         CODE:
3595                 RETVAL = filledEllipseRGBA( dst, x, y, rx, ry, r, g, b, a );
3596         OUTPUT:
3597                 RETVAL
3598
3599 int
3600 GFXFilledPieColor ( dst, x, y, rad, start, end, color )
3601         SDL_Surface* dst
3602         Sint16 x
3603         Sint16 y
3604         Sint16 rad
3605         Sint16 start
3606         Sint16 end
3607         Uint32 color
3608         CODE:
3609                 RETVAL = filledPieColor( dst, x, y, rad, start, end, color );
3610         OUTPUT:
3611                 RETVAL
3612
3613 int
3614 GFXFilledPieRGBA ( dst, x, y, rad, start, end, r, g, b, a )
3615         SDL_Surface* dst
3616         Sint16 x
3617         Sint16 y
3618         Sint16 rad
3619         Sint16 start
3620         Sint16 end
3621         Uint8 r
3622         Uint8 g
3623         Uint8 b
3624         Uint8 a
3625         CODE:
3626                 RETVAL = filledPieRGBA( dst, x, y, rad, start, end, r, g, b, a );
3627         OUTPUT:
3628                 RETVAL
3629
3630 int
3631 GFXPolygonColor ( dst, vx, vy, n, color )
3632         SDL_Surface* dst
3633         Sint16* vx
3634         Sint16* vy
3635         int n
3636         Uint32 color;
3637         CODE:
3638                 RETVAL = polygonColor( dst, vx, vy, n, color );
3639         OUTPUT:
3640                 RETVAL
3641
3642 int
3643 GFXPolygonRGBA ( dst, vx, vy, n, r, g, b, a )
3644         SDL_Surface* dst
3645         Sint16* vx
3646         Sint16* vy
3647         int n
3648         Uint8 r
3649         Uint8 g
3650         Uint8 b
3651         Uint8 a
3652         CODE:
3653                 RETVAL = polygonRGBA( dst, vx, vy, n, r, g, b, a );
3654         OUTPUT:
3655                 RETVAL
3656
3657 int
3658 GFXAapolygonColor ( dst, vx, vy, n, color )
3659         SDL_Surface* dst
3660         Sint16* vx
3661         Sint16* vy
3662         int n
3663         Uint32 color
3664         CODE:
3665                 RETVAL = aapolygonColor( dst, vx, vy, n, color );
3666         OUTPUT:
3667                 RETVAL
3668
3669 int
3670 GFXAapolygonRGBA ( dst, vx, vy, n, r, g, b, a )
3671         SDL_Surface* dst
3672         Sint16* vx
3673         Sint16* vy
3674         int n
3675         Uint8 r
3676         Uint8 g
3677         Uint8 b
3678         Uint8 a
3679         CODE:
3680                 RETVAL = aapolygonRGBA( dst, vx, vy, n, r, g, b, a );
3681         OUTPUT:
3682                 RETVAL
3683
3684 int
3685 GFXFilledPolygonColor ( dst, vx, vy, n, color )
3686         SDL_Surface* dst
3687         Sint16* vx
3688         Sint16* vy
3689         int n
3690         int color
3691         CODE:
3692                 RETVAL = filledPolygonColor( dst, vx, vy, n, color );
3693         OUTPUT:
3694                 RETVAL
3695
3696 int
3697 GFXFilledPolygonRGBA ( dst, vx, vy, n, r, g, b, a )
3698         SDL_Surface* dst
3699         Sint16* vx
3700         Sint16* vy
3701         int n
3702         Uint8 r
3703         Uint8 g
3704         Uint8 b
3705         Uint8 a
3706         CODE:
3707                 RETVAL = filledPolygonRGBA( dst, vx, vy, n, r, g, b, a );
3708         OUTPUT:
3709                 RETVAL
3710
3711 int
3712 GFXCharacterColor ( dst, x, y, c, color )
3713         SDL_Surface* dst
3714         Sint16 x
3715         Sint16 y
3716         char c
3717         Uint32 color
3718         CODE:
3719                 RETVAL = characterColor( dst, x, y, c, color );
3720         OUTPUT:
3721                 RETVAL
3722
3723 int
3724 GFXCharacterRGBA ( dst, x, y, c, r, g, b, a )
3725         SDL_Surface* dst
3726         Sint16 x
3727         Sint16 y
3728         char c
3729         Uint8 r
3730         Uint8 g
3731         Uint8 b
3732         Uint8 a
3733         CODE:
3734                 RETVAL = characterRGBA( dst, x, y, c, r, g, b, a );
3735         OUTPUT:
3736                 RETVAL
3737
3738 int
3739 GFXStringColor ( dst, x, y, c, color )
3740         SDL_Surface* dst
3741         Sint16 x
3742         Sint16 y
3743         char* c
3744         Uint32 color
3745         CODE:
3746                 RETVAL = stringColor( dst, x, y, c, color );
3747         OUTPUT:
3748                 RETVAL
3749
3750 int
3751 GFXStringRGBA ( dst, x, y, c, r, g, b, a )
3752         SDL_Surface* dst
3753         Sint16 x
3754         Sint16 y
3755         char* c
3756         Uint8 r
3757         Uint8 g
3758         Uint8 b
3759         Uint8 a
3760         CODE:
3761                 RETVAL = stringRGBA( dst, x, y, c, r, g, b, a );
3762         OUTPUT:
3763                 RETVAL
3764
3765 #endif
3766
3767
3768 #ifdef HAVE_SDL_SVG
3769
3770 SDL_svg_context *
3771 SVG_Load ( filename )
3772         char* filename
3773         CODE:
3774                 RETVAL = SVG_Load(filename);
3775         OUTPUT:
3776                 RETVAL
3777
3778 SDL_svg_context *
3779 SVG_LoadBuffer ( data, len )
3780         char* data
3781         int len
3782         CODE:
3783                 RETVAL = SVG_LoadBuffer(data,len);
3784         OUTPUT:
3785                 RETVAL
3786
3787 int
3788 SVG_SetOffset ( source, xoff, yoff )
3789         SDL_svg_context* source
3790         double xoff
3791         double yoff
3792         CODE:
3793                 RETVAL = SVG_SetOffset(source,xoff,yoff);
3794         OUTPUT:
3795                 RETVAL
3796
3797 int
3798 SVG_SetScale ( source, xscale, yscale )
3799         SDL_svg_context* source
3800         double xscale
3801         double yscale
3802         CODE:
3803                 RETVAL = SVG_SetScale(source,xscale,yscale);
3804         OUTPUT:
3805                 RETVAL
3806
3807 int
3808 SVG_RenderToSurface ( source, x, y, dest )
3809         SDL_svg_context* source
3810         int x
3811         int y
3812         SDL_Surface* dest;
3813         CODE:
3814                 RETVAL = SVG_RenderToSurface(source,x,y,dest);
3815         OUTPUT:
3816                 RETVAL
3817
3818 void
3819 SVG_Free ( source )
3820         SDL_svg_context* source
3821         CODE:
3822                 SVG_Free(source);       
3823
3824 void
3825 SVG_Set_Flags ( source, flags )
3826         SDL_svg_context* source
3827         Uint32 flags
3828         CODE:
3829                 SVG_Set_Flags(source,flags);
3830
3831 float
3832 SVG_Width ( source )
3833         SDL_svg_context* source
3834         CODE:
3835                 RETVAL = SVG_Width(source);
3836         OUTPUT:
3837                 RETVAL
3838
3839 float
3840 SVG_HEIGHT ( source )
3841         SDL_svg_context* source
3842         CODE:
3843                 RETVAL = SVG_Height(source);
3844         OUTPUT:
3845                 RETVAL
3846
3847 void
3848 SVG_SetClipping ( source, minx, miny, maxx, maxy )
3849         SDL_svg_context* source
3850         int minx
3851         int miny
3852         int maxx
3853         int maxy
3854         CODE:
3855                 SVG_SetClipping(source,minx,miny,maxx,maxy);
3856
3857 int
3858 SVG_Version ( )
3859         CODE:
3860                 RETVAL = SVG_Version();
3861         OUTPUT:
3862                 RETVAL
3863
3864
3865 #endif
3866
3867 #ifdef HAVE_SDL_SOUND
3868
3869 Uint16
3870 SoundAudioInfoFormat ( audioinfo )
3871         Sound_AudioInfo* audioinfo
3872         CODE:
3873                 RETVAL = audioinfo->format;
3874         OUTPUT:
3875                 RETVAL
3876
3877 Uint8
3878 SoundAudioInfoChannels ( audioinfo )
3879         Sound_AudioInfo* audioinfo
3880         CODE:
3881                 RETVAL = audioinfo->channels;
3882         OUTPUT:
3883                 RETVAL
3884
3885 Uint32
3886 SoundAudioInforate ( audioinfo )
3887         Sound_AudioInfo* audioinfo
3888         CODE:
3889                 RETVAL = audioinfo->rate;
3890         OUTPUT:
3891                 RETVAL
3892
3893 AV*
3894 SoundDecoderInfoExtensions ( decoderinfo )
3895         Sound_DecoderInfo* decoderinfo
3896         CODE:
3897                 const char **ext;
3898                 for ( ext = decoderinfo->extensions; *ext != NULL; ext++ ){
3899                         av_push(RETVAL,newSVpv(*ext,0));
3900                 }
3901         OUTPUT:
3902                 RETVAL
3903
3904 const char*
3905 SoundDecoderInfoDescription ( decoderinfo )
3906         Sound_DecoderInfo* decoderinfo
3907         CODE:
3908                 RETVAL = decoderinfo->description;
3909         OUTPUT:
3910                 RETVAL
3911
3912 const char*
3913 SoundDecoderInfoAuthor ( decoderinfo )
3914         Sound_DecoderInfo* decoderinfo
3915         CODE:
3916                 RETVAL = decoderinfo->author;
3917         OUTPUT:
3918                 RETVAL
3919
3920 const char*
3921 SoundDecoderInfoUrl ( decoderinfo )
3922         Sound_DecoderInfo* decoderinfo
3923         CODE:
3924                 RETVAL = decoderinfo->url;
3925         OUTPUT:
3926                 RETVAL
3927
3928 const Sound_DecoderInfo*
3929 SoundSampleDecoder ( sample ) 
3930         Sound_Sample* sample
3931         CODE:
3932                 RETVAL = sample->decoder;
3933         OUTPUT:
3934                 RETVAL
3935
3936 Sound_AudioInfo* 
3937 SoundSampleDesired ( sample )
3938         Sound_Sample* sample
3939         CODE:
3940                 RETVAL = &sample->desired;
3941         OUTPUT:
3942                 RETVAL
3943
3944 Sound_AudioInfo*
3945 SoundSampleAcutal ( sample )
3946         Sound_Sample* sample
3947         CODE:
3948                 RETVAL = &sample->actual;
3949         OUTPUT:
3950                 RETVAL
3951
3952 char*
3953 SoundSampleBuffer ( sample )
3954         Sound_Sample* sample
3955         CODE:
3956                 RETVAL = sample->buffer;
3957         OUTPUT:
3958                 RETVAL
3959
3960 Uint32
3961 SoundSampleBufferSize ( sample )
3962         Sound_Sample* sample
3963         CODE:
3964                 RETVAL = sample->buffer_size;
3965         OUTPUT:
3966                 RETVAL
3967
3968 Uint32
3969 SoundSampleFlags ( sample )
3970         Sound_Sample* sample
3971         CODE:
3972                 RETVAL = (Uint32)sample->flags;
3973         OUTPUT:
3974                 RETVAL
3975
3976 int
3977 Sound_Init ( )
3978         CODE:
3979                 RETVAL = Sound_Init();
3980         OUTPUT:
3981                 RETVAL
3982
3983 int
3984 Sound_Quit ( )
3985         CODE:
3986                 RETVAL = Sound_Quit();
3987         OUTPUT:
3988                 RETVAL
3989
3990 AV*
3991 Sound_AvailableDecoders ( )
3992         CODE:
3993                 RETVAL = newAV();
3994                 const Sound_DecoderInfo** sdi;
3995                 sdi = Sound_AvailableDecoders();
3996                 if (sdi != NULL)  {
3997                         for (;*sdi != NULL; ++sdi) {
3998                                 av_push(RETVAL,sv_2mortal(newSViv(PTR2IV(*sdi))));
3999                         }
4000                 }
4001         OUTPUT:
4002                 RETVAL
4003
4004 const char*
4005 Sound_GetError ( )
4006         CODE:
4007                 RETVAL = Sound_GetError();
4008         OUTPUT:
4009                 RETVAL
4010
4011 void
4012 Sound_ClearError ( )
4013         CODE:
4014                 Sound_ClearError();
4015
4016 Sound_Sample*
4017 Sound_NewSample ( rw, ext, desired, buffsize )
4018         SDL_RWops* rw
4019         const char* ext
4020         Sound_AudioInfo* desired
4021         Uint32 buffsize
4022         CODE:
4023                 RETVAL = Sound_NewSample(rw,ext,desired,buffsize);
4024         OUTPUT:
4025                 RETVAL
4026
4027 Sound_Sample*
4028 Sound_NewSampleFromMem ( data, size, ext, desired, buffsize )
4029         const Uint8 *data
4030         Uint32 size
4031         const char* ext
4032         Sound_AudioInfo* desired
4033         Uint32 buffsize
4034         CODE:
4035                 RETVAL = Sound_NewSampleFromMem(data,size,ext,desired,buffsize);
4036         OUTPUT:
4037                 RETVAL
4038
4039 Sound_Sample*
4040 Sound_NewSampleFromFile ( fname, desired, buffsize )
4041         const char* fname
4042         Sound_AudioInfo* desired
4043         Uint32 buffsize
4044         CODE:
4045                 RETVAL = Sound_NewSampleFromFile(fname,desired,buffsize);
4046         OUTPUT:
4047                 RETVAL
4048
4049 void
4050 Sound_FreeSample ( sample )
4051         Sound_Sample* sample
4052         CODE:
4053                 Sound_FreeSample(sample);
4054
4055 Sint32
4056 Sound_GetDuration ( sample )
4057         Sound_Sample* sample
4058         CODE:
4059                 RETVAL = Sound_GetDuration(sample);
4060         OUTPUT:
4061                 RETVAL
4062
4063 int
4064 Sound_SetBufferSize ( sample, size )
4065         Sound_Sample* sample
4066         Uint32 size
4067         CODE:
4068                 RETVAL = Sound_SetBufferSize(sample,size);
4069         OUTPUT:
4070                 RETVAL
4071
4072 Uint32
4073 Sound_Decode ( sample )
4074         Sound_Sample* sample
4075         CODE:
4076                 RETVAL = Sound_Decode(sample);
4077         OUTPUT:
4078                 RETVAL
4079
4080 Uint32
4081 Sound_DecodeAll ( sample ) 
4082         Sound_Sample* sample
4083         CODE:
4084                 RETVAL = Sound_DecodeAll(sample);
4085         OUTPUT:
4086                 RETVAL
4087
4088 int
4089 Sound_Rewind ( sample )
4090         Sound_Sample* sample
4091         CODE:
4092                 RETVAL = Sound_Rewind(sample);
4093         OUTPUT:
4094                 RETVAL
4095
4096 int
4097 Sound_Seek ( sample, ms )
4098         Sound_Sample* sample
4099         Uint32 ms
4100         CODE:
4101                 RETVAL = Sound_Seek(sample,ms);
4102         OUTPUT:
4103                 RETVAL
4104
4105 #endif
4106
4107 #ifdef HAVE_SDL_TTF
4108
4109 int
4110 TTF_Init ()
4111         CODE:
4112                 RETVAL = TTF_Init();
4113         OUTPUT:
4114                 RETVAL
4115
4116 void
4117 TTF_Quit ()
4118         CODE:
4119                 TTF_Quit();
4120
4121 TTF_Font*
4122 TTF_OpenFont ( file, ptsize )
4123         char *file
4124         int ptsize
4125         CODE:
4126                 char* CLASS = "SDL::TTF_Font";
4127                 RETVAL = TTF_OpenFont(file,ptsize);
4128         OUTPUT:
4129                 RETVAL
4130
4131 AV*
4132 TTF_SizeText ( font, text )
4133         TTF_Font *font
4134         char *text
4135         CODE:
4136                 int w,h;
4137                 RETVAL = newAV();
4138                 if(TTF_SizeText(font,text,&w,&h))
4139                 {
4140                         printf("TTF error at TTFSizeText: %s \n", TTF_GetError());
4141                         Perl_croak (aTHX_ "TTF error \n");
4142                 }
4143                 else
4144                 {
4145                         av_push(RETVAL,newSViv(w));
4146                         av_push(RETVAL,newSViv(h));
4147                         sv_2mortal((SV*)RETVAL);
4148                 }
4149         OUTPUT:
4150                 RETVAL
4151
4152 SDL_Surface*
4153 TTF_RenderText_Blended ( font, text, fg )
4154         TTF_Font *font
4155         char *text
4156         SDL_Color *fg
4157         CODE:
4158                 char* CLASS = "SDL::Surface";
4159                 RETVAL = TTF_RenderText_Blended(font,text,*fg);
4160         OUTPUT:
4161                 RETVAL
4162
4163 #endif
4164
4165 MODULE = SDL            PACKAGE = SDL
4166 PROTOTYPES : DISABLE
4167
4168