8e14ce2124fc2b9f3bccf7b9726cfcd7a4a5539e
[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 init_subsystem ( flags )
268         Uint32 flags
269         CODE:
270                 RETVAL = SDL_InitSubSystem(flags);
271         OUTPUT:
272                 RETVAL
273
274 void
275 quit_subsystem ( 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 was_init ( 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 key_scancode ( 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 button_state ( e )
778         SDL_Event *e
779         CODE:
780                 RETVAL = e->button.state;
781         OUTPUT:
782                 RETVAL
783
784 Uint8
785 button ( e )
786         SDL_Event *e
787         CODE:
788                 RETVAL = e->button.button;
789         OUTPUT:
790                 RETVAL
791
792 Uint16
793 button_x ( e )
794         SDL_Event *e
795         CODE:
796                 RETVAL = e->button.x;
797         OUTPUT:
798                 RETVAL
799
800 Uint16
801 button_y ( 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 get_key_name ( 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 =skip
1214
1215 SDL_Palette *
1216 NewPalette ( number )
1217         int number
1218         CODE:
1219                 RETVAL = (SDL_Palette *)safemalloc(sizeof(SDL_Palette));
1220                 RETVAL->colors = (SDL_Color *)safemalloc(number * 
1221                                                 sizeof(SDL_Color));
1222                 RETVAL->ncolors = number;
1223         OUTPUT:
1224                 RETVAL
1225 =cut
1226
1227 int
1228 PaletteNColors ( palette, ... )
1229         SDL_Palette *palette
1230         CODE:
1231                 if ( items > 1 ) palette->ncolors = SvIV(ST(1));
1232                 RETVAL = palette->ncolors;
1233         OUTPUT:
1234                 RETVAL
1235
1236 SDL_Surface *
1237 SetVideoMode ( width, height, bpp, flags )
1238
1239         int width
1240         int height
1241         int bpp
1242         Uint32 flags
1243
1244         CODE:
1245                 char *CLASS = "SDL::Surface";
1246                 RETVAL = SDL_SetVideoMode(width,height,bpp,flags);
1247         OUTPUT:
1248                 RETVAL
1249
1250 int
1251 Flip ( surface )
1252         SDL_Surface *surface
1253         CODE:
1254                 RETVAL = SDL_Flip(surface);
1255         OUTPUT:
1256                 RETVAL
1257
1258 int
1259 BlitSurface ( src, src_rect, dest, dest_rect )
1260         SDL_Surface *src
1261         SDL_Surface *dest
1262         SDL_Rect *src_rect
1263         SDL_Rect *dest_rect
1264         CODE:
1265                 RETVAL = SDL_BlitSurface(src,src_rect,dest,dest_rect);
1266         OUTPUT:
1267                 RETVAL
1268
1269 Uint32
1270 MapRGB ( pixel_format, r, g, b )
1271         SDL_PixelFormat *pixel_format
1272         Uint8 r
1273         Uint8 g
1274         Uint8 b
1275         CODE:
1276                 RETVAL = SDL_MapRGB(pixel_format,r,g,b);
1277         OUTPUT:
1278                 RETVAL
1279
1280 void
1281 UpdateRect ( surface, x, y, w ,h )
1282         SDL_Surface *surface
1283         int x
1284         int y
1285         int w
1286         int h
1287         CODE:
1288                 SDL_UpdateRect(surface,x,y,w,h);
1289
1290 SDL_Surface *
1291 DisplayFormat ( surface )
1292         SDL_Surface *surface
1293         CODE:
1294                 char* CLASS = "SDL::Surface";
1295                 RETVAL = SDL_DisplayFormat(surface);
1296         OUTPUT:
1297                 RETVAL
1298
1299 SDL_Surface *
1300 DisplayFormatAlpha ( surface )
1301         SDL_Surface *surface
1302         CODE:
1303                 char* CLASS = "SDL::Surface";
1304                 RETVAL = SDL_DisplayFormatAlpha(surface);
1305         OUTPUT:
1306                 RETVAL
1307
1308 void
1309 UpdateRects ( surface, ... )
1310         SDL_Surface *surface
1311         CODE:
1312                 SDL_Rect *rects;
1313                 int num_rects,i;
1314                 if ( items < 2 ) return;
1315                 num_rects = items - 1;
1316                 rects = (SDL_Rect *)safemalloc(sizeof(SDL_Rect)*items);
1317                 for(i=0;i<num_rects;i++) {
1318                         rects[i] = *(SDL_Rect *)SvIV((SV*)SvRV( ST(i + 1) ));
1319                 }
1320                 SDL_UpdateRects(surface,num_rects,rects);
1321                 safefree(rects);
1322
1323 =for comment
1324
1325 Comment out for now as it does not compile
1326
1327 int
1328 VideoModeOK ( width, height, bpp, flags )
1329         int width
1330         int height
1331         int bpp
1332         Uint32 flags
1333         CODE:
1334                 RETVAL = SDL_VideoModeOK(width,height,bpp,flags);
1335         OUTPUT:
1336                 RETVAL
1337
1338 SDL_Surface *
1339 SetVideoMode ( width, height, bpp, flags )
1340         int width
1341         int height
1342         int bpp
1343         Uint32 flags
1344         CODE:
1345                 RETVAL = SDL_SetVideoMode(width,height,bpp,flags);
1346         OUTPUT:
1347                 RETVAL
1348
1349 int
1350 Flip ( surface )
1351         SDL_Surface *surface
1352         CODE:
1353                 RETVAL = SDL_Flip(surface);
1354         OUTPUT:
1355                 RETVAL
1356
1357 int
1358 SetColors ( surface, start, ... )
1359         SDL_Surface *surface
1360         int start
1361         CODE:
1362                 SDL_Color *colors,*temp;
1363                 int i, length;
1364                 if ( items < 3 ) { RETVAL = 0;  goto all_done; }
1365                 length = items - 2;
1366                 colors = (SDL_Color *)safemalloc(sizeof(SDL_Color)*(length+1));
1367                 for ( i = 0; i < length ; i++ ) {
1368                         temp = (SDL_Color *)SvIV(ST(i+2));
1369                         colors[i].r = temp->r;
1370                         colors[i].g = temp->g;
1371                         colors[i].b = temp->b;
1372                 }
1373                 RETVAL = SDL_SetColors(surface, colors, start, length );
1374                 safefree(colors);
1375 all_done:
1376         OUTPUT: 
1377                 RETVAL
1378
1379 Uint32
1380 MapRGBA ( surface, r, g, b, a )
1381         SDL_Surface *surface
1382         Uint8 r
1383         Uint8 g
1384         Uint8 b
1385         Uint8 a
1386         CODE:
1387                 RETVAL = SDL_MapRGBA(surface->format,r,g,b,a);
1388         OUTPUT:
1389                 RETVAL
1390
1391 AV *
1392 GetRGB ( surface, pixel )
1393         SDL_Surface *surface
1394         Uint32 pixel
1395         CODE:
1396                 Uint8 r,g,b;
1397                 SDL_GetRGB(pixel,surface->format,&r,&g,&b);
1398                 RETVAL = newAV();
1399                 av_push(RETVAL,newSViv(r));
1400                 av_push(RETVAL,newSViv(g));
1401                 av_push(RETVAL,newSViv(b));
1402         OUTPUT:
1403                 RETVAL
1404
1405 AV *
1406 GetRGBA ( surface, pixel )
1407         SDL_Surface *surface
1408         Uint32 pixel
1409         CODE:
1410                 Uint8 r,g,b,a;
1411                 SDL_GetRGBA(pixel,surface->format,&r,&g,&b,&a);
1412                 RETVAL = newAV();
1413                 av_push(RETVAL,newSViv(r));
1414                 av_push(RETVAL,newSViv(g));
1415                 av_push(RETVAL,newSViv(b));
1416                 av_push(RETVAL,newSViv(a));
1417         OUTPUT:
1418                 RETVAL
1419
1420 int
1421 SaveBMP ( surface, filename )
1422         SDL_Surface *surface
1423         char *filename
1424         CODE:
1425                 RETVAL = SDL_SaveBMP(surface,filename);
1426         OUTPUT:
1427                 RETVAL  
1428
1429 int
1430 SetColorKey ( surface, flag, key )
1431         SDL_Surface *surface
1432         Uint32 flag
1433         SDL_Color *key
1434         CODE:
1435                 Uint32 pixel = SDL_MapRGB(surface->format,key->r,key->g,key->b);
1436                 RETVAL = SDL_SetColorKey(surface,flag,pixel);
1437         OUTPUT:
1438                 RETVAL
1439
1440 int
1441 SetAlpha ( surface, flag, alpha )
1442         SDL_Surface *surface
1443         Uint32 flag
1444         Uint8 alpha
1445         CODE:
1446                 RETVAL = SDL_SetAlpha(surface,flag,alpha);
1447         OUTPUT:
1448                 RETVAL
1449
1450 SDL_Surface*
1451 ConvertRGB ( surface )
1452         SDL_Surface * surface
1453         CODE:
1454                 SDL_PixelFormat fmt;
1455                 fmt.palette = NULL;
1456                 fmt.BitsPerPixel = 24;
1457                 fmt.BytesPerPixel = 3;
1458                 fmt.Rmask = 0x000000ff;
1459                 fmt.Gmask = 0x0000ff00;
1460                 fmt.Bmask = 0x00ff0000;
1461                 fmt.Amask = 0x00000000;
1462                 fmt.Rloss = 0;
1463                 fmt.Gloss = 0;
1464                 fmt.Bloss = 0;
1465                 fmt.Aloss = 0;
1466                 fmt.Rshift = 0;
1467                 fmt.Gshift = 8;
1468                 fmt.Bshift = 16;
1469                 fmt.Ashift = 24;
1470                 fmt.colorkey = 0;
1471                 fmt.alpha = 0;
1472                 RETVAL = SDL_ConvertSurface(surface,&fmt,surface->flags);
1473         OUTPUT:
1474                 RETVAL
1475
1476 SDL_Surface* 
1477 ConvertRGBA ( surface )
1478         SDL_Surface * surface
1479         CODE:
1480                 SDL_PixelFormat fmt;
1481                 fmt.palette = NULL;
1482                 fmt.BitsPerPixel = 32;
1483                 fmt.BytesPerPixel = 4;
1484                 fmt.Rmask = 0x000000ff;
1485                 fmt.Gmask = 0x0000ff00;
1486                 fmt.Bmask = 0x00ff0000;
1487                 fmt.Amask = 0xff000000;
1488                 fmt.Rloss = 0;
1489                 fmt.Gloss = 0;
1490                 fmt.Bloss = 0;
1491                 fmt.Aloss = 0;
1492                 fmt.Rshift = 0;
1493                 fmt.Gshift = 8;
1494                 fmt.Bshift = 16;
1495                 fmt.Ashift = 24;
1496                 fmt.colorkey = 0;
1497                 fmt.alpha = 0;
1498                 RETVAL = SDL_ConvertSurface(surface,&fmt,surface->flags);
1499         OUTPUT:
1500                 RETVAL
1501
1502 =cut
1503
1504 int
1505 FillRect ( dest, dest_rect, pixel )
1506         SDL_Surface *dest
1507         SDL_Rect *dest_rect
1508         Uint32 pixel
1509         CODE:
1510                 RETVAL = SDL_FillRect(dest,dest_rect,pixel);
1511         OUTPUT:
1512                 RETVAL
1513
1514 Uint8
1515 GetAppState ()
1516         CODE:
1517                 RETVAL = SDL_GetAppState();
1518         OUTPUT:
1519                 RETVAL
1520
1521
1522 void
1523 WMSetCaption ( title, icon )
1524         char *title
1525         char *icon
1526         CODE:
1527                 SDL_WM_SetCaption(title,icon);
1528
1529 AV *
1530 WMGetCaption ()
1531         CODE:
1532                 char *title,*icon;
1533                 SDL_WM_GetCaption(&title,&icon);
1534                 RETVAL = newAV();
1535                 av_push(RETVAL,newSVpv(title,0));
1536                 av_push(RETVAL,newSVpv(icon,0));
1537         OUTPUT:
1538                 RETVAL
1539
1540 void
1541 WMSetIcon ( icon )
1542         SDL_Surface *icon
1543         CODE:
1544                 SDL_WM_SetIcon(icon,NULL);
1545
1546 void
1547 WarpMouse ( x, y )
1548         Uint16 x
1549         Uint16 y
1550         CODE:
1551                 SDL_WarpMouse(x,y);
1552
1553 AV*
1554 GetMouseState ()
1555         CODE:
1556                 Uint8 mask;
1557                 int x;
1558                 int y;
1559                 mask = SDL_GetMouseState(&x,&y);
1560                 RETVAL = newAV();
1561                 av_push(RETVAL,newSViv(mask));
1562                 av_push(RETVAL,newSViv(x));
1563                 av_push(RETVAL,newSViv(y));
1564         OUTPUT:
1565                 RETVAL  
1566
1567 AV*
1568 GetRelativeMouseState ()
1569         CODE:
1570                 Uint8 mask;
1571                 int x;
1572                 int y;
1573                 mask = SDL_GetRelativeMouseState(&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 SDL_Cursor *
1582 NewCursor ( data, mask, x ,y )
1583         SDL_Surface *data
1584         SDL_Surface *mask
1585         int x
1586         int y
1587         CODE:
1588                 RETVAL = SDL_CreateCursor((Uint8*)data->pixels,
1589                                 (Uint8*)mask->pixels,data->w,data->h,x,y);
1590         OUTPUT:
1591                 RETVAL
1592
1593 void
1594 FreeCursor ( cursor )
1595         SDL_Cursor *cursor
1596         CODE:
1597                 SDL_FreeCursor(cursor);
1598
1599 void
1600 SetCursor ( cursor )
1601         SDL_Cursor *cursor
1602         CODE:
1603                 SDL_SetCursor(cursor);
1604
1605 SDL_Cursor *
1606 GetCursor ()
1607         CODE:
1608                 RETVAL = SDL_GetCursor();
1609         OUTPUT:
1610                 RETVAL
1611
1612 int
1613 ShowCursor ( toggle )
1614         int toggle
1615         CODE:
1616                 RETVAL = SDL_ShowCursor(toggle);
1617         OUTPUT: 
1618                 RETVAL
1619
1620 SDL_AudioSpec *
1621 NewAudioSpec ( freq, format, channels, samples )
1622         int freq
1623         Uint16 format
1624         Uint8 channels
1625         Uint16 samples
1626         CODE:
1627                 RETVAL = (SDL_AudioSpec *)safemalloc(sizeof(SDL_AudioSpec));
1628                 RETVAL->freq = freq;
1629                 RETVAL->format = format;
1630                 RETVAL->channels = channels;
1631                 RETVAL->samples = samples;
1632         OUTPUT:
1633                 RETVAL
1634
1635 void
1636 FreeAudioSpec ( spec )
1637         SDL_AudioSpec *spec
1638         CODE:
1639                 safefree(spec);
1640
1641 SDL_AudioCVT *
1642 NewAudioCVT ( src_format, src_channels, src_rate, dst_format, dst_channels, dst_rate)
1643         Uint16 src_format
1644         Uint8 src_channels
1645         int src_rate
1646         Uint16 dst_format
1647         Uint8 dst_channels
1648         int dst_rate
1649         CODE:
1650                 RETVAL = (SDL_AudioCVT *)safemalloc(sizeof(SDL_AudioCVT));
1651                 if (SDL_BuildAudioCVT(RETVAL,src_format, src_channels, src_rate,
1652                         dst_format, dst_channels, dst_rate)) { 
1653                         safefree(RETVAL); RETVAL = NULL; }
1654         OUTPUT:
1655                 RETVAL
1656
1657 void
1658 FreeAudioCVT ( cvt )
1659         SDL_AudioCVT *cvt
1660         CODE:
1661                 safefree(cvt);
1662
1663 int
1664 ConvertAudioData ( cvt, data, len )
1665         SDL_AudioCVT *cvt
1666         Uint8 *data
1667         int len
1668         CODE:
1669                 cvt->len = len;
1670                 cvt->buf = (Uint8*) safemalloc(cvt->len*cvt->len_mult);
1671                 memcpy(cvt->buf,data,cvt->len);
1672                 RETVAL = SDL_ConvertAudio(cvt);
1673         OUTPUT:
1674                 RETVAL                  
1675
1676 int
1677 OpenAudio ( spec, callback )
1678         SDL_AudioSpec *spec
1679         SV* callback
1680         CODE:
1681                 spec->userdata = (void*)callback;
1682                 spec->callback = sdl_perl_audio_callback;
1683                 RETVAL = SDL_OpenAudio(spec,NULL);
1684         OUTPUT:
1685                 RETVAL
1686
1687 Uint32
1688 GetAudioStatus ()
1689         CODE:
1690                 RETVAL = SDL_GetAudioStatus ();
1691         OUTPUT:
1692                 RETVAL
1693
1694 void
1695 PauseAudio ( p_on )
1696         int p_on
1697         CODE:
1698                 SDL_PauseAudio(p_on);
1699         
1700 void
1701 LockAudio ()
1702         CODE:
1703                 SDL_LockAudio();
1704
1705 void
1706 UnlockAudio ()
1707         CODE:
1708                 SDL_UnlockAudio();
1709
1710 void
1711 CloseAudio ()
1712         CODE:
1713                 SDL_CloseAudio();
1714
1715 void
1716 FreeWAV ( buf )
1717         Uint8 *buf
1718         CODE:
1719                 SDL_FreeWAV(buf);
1720
1721 AV *
1722 LoadWAV ( filename, spec )
1723         char *filename
1724         SDL_AudioSpec *spec
1725         CODE:
1726                 SDL_AudioSpec *temp;
1727                 Uint8 *buf;
1728                 Uint32 len;
1729
1730                 RETVAL = newAV();
1731                 temp = SDL_LoadWAV(filename,spec,&buf,&len);
1732                 if ( ! temp ) goto error;
1733                 av_push(RETVAL,newSViv(PTR2IV(temp)));
1734                 av_push(RETVAL,newSViv(PTR2IV(buf)));
1735                 av_push(RETVAL,newSViv(len));
1736 error:
1737         OUTPUT:
1738                 RETVAL
1739         
1740 #ifdef HAVE_SDL_MIXER
1741
1742 void
1743 MixAudio ( dst, src, len, volume )
1744         Uint8 *dst
1745         Uint8 *src
1746         Uint32 len
1747         int volume
1748         CODE:
1749                 SDL_MixAudio(dst,src,len,volume);
1750
1751 int
1752 MixOpenAudio ( frequency, format, channels, chunksize )
1753         int frequency
1754         Uint16 format
1755         int channels
1756         int chunksize   
1757         CODE:
1758                 RETVAL = Mix_OpenAudio(frequency, format, channels, chunksize);
1759         OUTPUT:
1760                 RETVAL
1761
1762 int
1763 MixAllocateChannels ( number )
1764         int number
1765         CODE:
1766                 RETVAL = Mix_AllocateChannels(number);
1767         OUTPUT:
1768                 RETVAL
1769
1770 AV *
1771 MixQuerySpec ()
1772         CODE:
1773                 int freq, channels, status;
1774                 Uint16 format;
1775                 status = Mix_QuerySpec(&freq,&format,&channels);
1776                 RETVAL = newAV();
1777                 av_push(RETVAL,newSViv(status));
1778                 av_push(RETVAL,newSViv(freq));
1779                 av_push(RETVAL,newSViv(format));
1780                 av_push(RETVAL,newSViv(channels));
1781         OUTPUT:
1782                 RETVAL
1783
1784 Mix_Chunk *
1785 MixLoadWAV ( filename )
1786         char *filename
1787         CODE:
1788                 RETVAL = Mix_LoadWAV(filename);
1789         OUTPUT:
1790                 RETVAL
1791
1792 Mix_Music *
1793 MixLoadMusic ( filename )
1794         char *filename
1795         CODE:
1796                 RETVAL = Mix_LoadMUS(filename);
1797         OUTPUT:
1798                 RETVAL
1799
1800 Mix_Chunk *
1801 MixQuickLoadWAV ( buf )
1802         Uint8 *buf
1803         CODE:
1804                 RETVAL = Mix_QuickLoad_WAV(buf);
1805         OUTPUT:
1806                 RETVAL
1807
1808 void
1809 MixFreeChunk( chunk )
1810         Mix_Chunk *chunk
1811         CODE:
1812                 Mix_FreeChunk(chunk);
1813
1814 void
1815 MixFreeMusic ( music )
1816         Mix_Music *music
1817         CODE:
1818                 Mix_FreeMusic(music);
1819
1820 void
1821 MixSetPostMixCallback ( func, arg )
1822         void *func
1823         void *arg
1824         CODE:
1825                 Mix_SetPostMix(func,arg);
1826
1827 void*
1828 PerlMixMusicHook ()
1829         CODE:
1830                 RETVAL = sdl_perl_music_callback;
1831         OUTPUT:
1832                 RETVAL
1833
1834 void
1835 MixSetMusicHook ( func, arg )
1836         void *func
1837         void *arg
1838         CODE:
1839                 Mix_HookMusic(func,arg);
1840
1841 void
1842 MixSetMusicFinishedHook ( func )
1843         void *func
1844         CODE:
1845                 mix_music_finished_cv = func;
1846                 Mix_HookMusicFinished(sdl_perl_music_finished_callback);
1847
1848 void *
1849 MixGetMusicHookData ()
1850         CODE:
1851                 RETVAL = Mix_GetMusicHookData();
1852         OUTPUT:
1853                 RETVAL
1854
1855 int
1856 MixReverseChannels ( number )
1857         int number
1858         CODE:
1859                 RETVAL = Mix_ReserveChannels ( number );
1860         OUTPUT:
1861                 RETVAL
1862
1863 int
1864 MixGroupChannel ( which, tag )
1865         int which
1866         int tag
1867         CODE:
1868                 RETVAL = Mix_GroupChannel(which,tag);
1869         OUTPUT:
1870                 RETVAL
1871
1872 int
1873 MixGroupChannels ( from, to, tag )
1874         int from
1875         int to
1876         int tag
1877         CODE:
1878                 RETVAL = Mix_GroupChannels(from,to,tag);
1879         OUTPUT:
1880                 RETVAL
1881
1882 int
1883 MixGroupAvailable ( tag )
1884         int tag
1885         CODE:
1886                 RETVAL = Mix_GroupAvailable(tag);
1887         OUTPUT:
1888                 RETVAL
1889
1890 int
1891 MixGroupCount ( tag )
1892         int tag
1893         CODE:
1894                 RETVAL = Mix_GroupCount(tag);
1895         OUTPUT:
1896                 RETVAL
1897
1898 int
1899 MixGroupOldest ( tag )
1900         int tag
1901         CODE:
1902                 RETVAL = Mix_GroupOldest(tag);
1903         OUTPUT:
1904                 RETVAL
1905
1906 int
1907 MixGroupNewer ( tag )
1908         int tag
1909         CODE:
1910                 RETVAL = Mix_GroupNewer(tag);
1911         OUTPUT:
1912                 RETVAL
1913
1914 int
1915 MixPlayChannel ( channel, chunk, loops )
1916         int channel
1917         Mix_Chunk *chunk
1918         int loops
1919         CODE:
1920                 RETVAL = Mix_PlayChannel(channel,chunk,loops);
1921         OUTPUT:
1922                 RETVAL
1923
1924 int
1925 MixPlayChannelTimed ( channel, chunk, loops, ticks )
1926         int channel
1927         Mix_Chunk *chunk
1928         int loops
1929         int ticks
1930         CODE:
1931                 RETVAL = Mix_PlayChannelTimed(channel,chunk,loops,ticks);
1932         OUTPUT:
1933                 RETVAL
1934
1935 int
1936 MixPlayMusic ( music, loops )
1937         Mix_Music *music
1938         int loops
1939         CODE:
1940                 RETVAL = Mix_PlayMusic(music,loops);
1941         OUTPUT:
1942                 RETVAL
1943
1944 int
1945 MixFadeInChannel ( channel, chunk, loops, ms )
1946         int channel
1947         Mix_Chunk *chunk
1948         int loops
1949         int ms
1950         CODE:
1951                 RETVAL = Mix_FadeInChannel(channel,chunk,loops,ms);
1952         OUTPUT:
1953                 RETVAL
1954
1955 int
1956 MixFadeInChannelTimed ( channel, chunk, loops, ms, ticks )
1957         int channel
1958         Mix_Chunk *chunk
1959         int loops
1960         int ticks
1961         int ms
1962         CODE:
1963                 RETVAL = Mix_FadeInChannelTimed(channel,chunk,loops,ms,ticks);
1964         OUTPUT:
1965                 RETVAL
1966
1967 int
1968 MixFadeInMusic ( music, loops, ms )
1969         Mix_Music *music
1970         int loops
1971         int ms
1972         CODE:
1973                 RETVAL = Mix_FadeInMusic(music,loops,ms);
1974         OUTPUT:
1975                 RETVAL
1976
1977 int
1978 MixVolume ( channel, volume )
1979         int channel
1980         int volume
1981         CODE:   
1982                 RETVAL = Mix_Volume(channel,volume);
1983         OUTPUT:
1984                 RETVAL
1985
1986 int
1987 MixVolumeChunk ( chunk, volume )
1988         Mix_Chunk *chunk
1989         int volume
1990         CODE:
1991                 RETVAL = Mix_VolumeChunk(chunk,volume);
1992         OUTPUT:
1993                 RETVAL
1994
1995 int
1996 MixVolumeMusic ( volume )
1997         int volume
1998         CODE:
1999                 RETVAL = Mix_VolumeMusic(volume);
2000         OUTPUT:
2001                 RETVAL
2002
2003 int
2004 MixHaltChannel ( channel )
2005         int channel
2006         CODE:
2007                 RETVAL = Mix_HaltChannel(channel);
2008         OUTPUT:
2009                 RETVAL
2010
2011 int
2012 MixHaltGroup ( tag )
2013         int tag
2014         CODE:
2015                 RETVAL = Mix_HaltGroup(tag);
2016         OUTPUT:
2017                 RETVAL
2018
2019 int
2020 MixHaltMusic ()
2021         CODE:
2022                 RETVAL = Mix_HaltMusic();
2023         OUTPUT:
2024                 RETVAL
2025
2026 int
2027 MixExpireChannel ( channel, ticks )
2028         int channel
2029         int ticks
2030         CODE:
2031                 RETVAL = Mix_ExpireChannel ( channel,ticks);
2032         OUTPUT:
2033                 RETVAL
2034
2035 int
2036 MixFadeOutChannel ( which, ms )
2037         int which
2038         int ms
2039         CODE:
2040                 RETVAL = Mix_FadeOutChannel(which,ms);
2041         OUTPUT:
2042                 RETVAL
2043
2044 int
2045 MixFadeOutGroup ( which, ms )
2046         int which
2047         int ms
2048         CODE:
2049                 RETVAL = Mix_FadeOutGroup(which,ms);
2050         OUTPUT:
2051                 RETVAL
2052
2053 int
2054 MixFadeOutMusic ( ms )
2055         int ms
2056         CODE:
2057                 RETVAL = Mix_FadeOutMusic(ms);
2058         OUTPUT:
2059                 RETVAL
2060
2061 Mix_Fading
2062 MixFadingMusic()
2063         CODE:
2064                 RETVAL = Mix_FadingMusic();
2065         OUTPUT:
2066                 RETVAL
2067
2068 Mix_Fading
2069 MixFadingChannel( which )
2070         int which
2071         CODE:
2072                 RETVAL = Mix_FadingChannel(which);
2073         OUTPUT:
2074                 RETVAL
2075
2076 void
2077 MixPause ( channel )
2078         int channel
2079         CODE:
2080                 Mix_Pause(channel);
2081
2082 void
2083 MixResume ( channel )
2084         int channel
2085         CODE:
2086                 Mix_Resume(channel);
2087
2088 int
2089 MixPaused ( channel )
2090         int channel
2091         CODE:
2092                 RETVAL = Mix_Paused(channel);
2093         OUTPUT:
2094                 RETVAL
2095
2096 void
2097 MixPauseMusic ()
2098         CODE:
2099                 Mix_PauseMusic();
2100
2101 void
2102 MixResumeMusic ()
2103         CODE:
2104                 Mix_ResumeMusic();
2105
2106 void
2107 MixRewindMusic ()
2108         CODE:
2109                 Mix_RewindMusic();
2110
2111 int
2112 MixPausedMusic ()
2113         CODE:
2114                 RETVAL = Mix_PausedMusic();
2115         OUTPUT:
2116                 RETVAL
2117
2118 int
2119 MixPlaying( channel )
2120         int channel     
2121         CODE:
2122                 RETVAL = Mix_Playing(channel);
2123         OUTPUT:
2124                 RETVAL
2125
2126 int
2127 MixPlayingMusic()
2128         CODE:
2129                 RETVAL = Mix_PlayingMusic();
2130         OUTPUT:
2131                 RETVAL
2132
2133 int
2134 MixSetPanning ( channel, left, right )
2135         int channel
2136         int left
2137         int right
2138         CODE:
2139                 RETVAL = Mix_SetPanning(channel, left, right);
2140         OUTPUT:
2141                 RETVAL
2142
2143 void
2144 MixCloseAudio ()
2145         CODE:
2146                 Mix_CloseAudio();
2147
2148 #endif
2149
2150 int
2151 GLLoadLibrary ( path )
2152         char *path
2153         CODE:
2154                 RETVAL = SDL_GL_LoadLibrary(path);
2155         OUTPUT:
2156                 RETVAL
2157
2158 void*
2159 GLGetProcAddress ( proc )
2160         char *proc
2161         CODE:
2162                 RETVAL = SDL_GL_GetProcAddress(proc);
2163         OUTPUT:
2164                 RETVAL
2165
2166 int
2167 GLSetAttribute ( attr,  value )
2168         int        attr
2169         int        value
2170         CODE:
2171                 RETVAL = SDL_GL_SetAttribute(attr, value);
2172         OUTPUT:
2173                 RETVAL
2174
2175 AV *
2176 GLGetAttribute ( attr )
2177         int        attr
2178         CODE:
2179                 int value;
2180                 RETVAL = newAV();
2181                 av_push(RETVAL,newSViv(SDL_GL_GetAttribute(attr, &value)));
2182                 av_push(RETVAL,newSViv(value));
2183         OUTPUT:
2184                 RETVAL
2185
2186 void
2187 GLSwapBuffers ()
2188         CODE:
2189                 SDL_GL_SwapBuffers ();
2190
2191
2192 int
2193 BigEndian ()
2194         CODE:
2195                 RETVAL = (SDL_BYTEORDER == SDL_BIG_ENDIAN);
2196         OUTPUT:
2197                 RETVAL
2198
2199 int
2200 NumJoysticks ()
2201         CODE:
2202                 RETVAL = SDL_NumJoysticks();
2203         OUTPUT:
2204                 RETVAL
2205
2206 char *
2207 JoystickName ( index )
2208         int index
2209         CODE:
2210                 RETVAL = (char*)SDL_JoystickName(index);
2211         OUTPUT:
2212                 RETVAL
2213
2214 SDL_Joystick *
2215 JoystickOpen ( index ) 
2216         int index
2217         CODE:
2218                 RETVAL = SDL_JoystickOpen(index);
2219         OUTPUT:
2220                 RETVAL
2221
2222 int
2223 JoystickOpened ( index )
2224         int index
2225         CODE:
2226                 RETVAL = SDL_JoystickOpened(index);
2227         OUTPUT:
2228                 RETVAL
2229
2230 int
2231 JoystickIndex ( joystick )
2232         SDL_Joystick *joystick
2233         CODE:
2234                 RETVAL = SDL_JoystickIndex(joystick);
2235         OUTPUT:
2236                 RETVAL
2237
2238 int
2239 JoystickNumAxes ( joystick )
2240         SDL_Joystick *joystick
2241         CODE:
2242                 RETVAL = SDL_JoystickNumAxes(joystick);
2243         OUTPUT:
2244                 RETVAL
2245
2246 int
2247 JoystickNumBalls ( joystick )
2248         SDL_Joystick *joystick
2249         CODE:
2250                 RETVAL = SDL_JoystickNumBalls(joystick);
2251         OUTPUT:
2252                 RETVAL
2253
2254 int
2255 JoystickNumHats ( joystick )
2256         SDL_Joystick *joystick
2257         CODE:
2258                 RETVAL = SDL_JoystickNumHats(joystick);
2259         OUTPUT:
2260                 RETVAL
2261
2262 int
2263 JoystickNumButtons ( joystick )
2264         SDL_Joystick *joystick
2265         CODE:
2266                 RETVAL = SDL_JoystickNumButtons(joystick);
2267         OUTPUT:
2268                 RETVAL
2269
2270 void
2271 JoystickUpdate ()
2272         CODE:
2273                 SDL_JoystickUpdate();
2274
2275 Sint16
2276 JoystickGetAxis ( joystick, axis )
2277         SDL_Joystick *joystick
2278         int axis
2279         CODE:
2280                 RETVAL = SDL_JoystickGetAxis(joystick,axis);
2281         OUTPUT:
2282                 RETVAL
2283
2284 Uint8
2285 JoystickGetHat ( joystick, hat )
2286         SDL_Joystick *joystick
2287         int hat 
2288         CODE:
2289                 RETVAL = SDL_JoystickGetHat(joystick,hat);
2290         OUTPUT:
2291                 RETVAL
2292
2293 Uint8
2294 JoystickGetButton ( joystick, button)
2295         SDL_Joystick *joystick
2296         int button 
2297         CODE:
2298                 RETVAL = SDL_JoystickGetButton(joystick,button);
2299         OUTPUT:
2300                 RETVAL
2301
2302 AV *
2303 JoystickGetBall ( joystick, ball )
2304         SDL_Joystick *joystick
2305         int ball 
2306         CODE:
2307                 int success,dx,dy;
2308                 success = SDL_JoystickGetBall(joystick,ball,&dx,&dy);
2309                 RETVAL = newAV();
2310                 av_push(RETVAL,newSViv(success));
2311                 av_push(RETVAL,newSViv(dx));
2312                 av_push(RETVAL,newSViv(dy));
2313         OUTPUT:
2314                 RETVAL  
2315
2316 void
2317 JoystickClose ( joystick )
2318         SDL_Joystick *joystick
2319         CODE:
2320                 SDL_JoystickClose(joystick);
2321
2322 Sint16
2323 JoyAxisEventWhich ( e )
2324         SDL_Event *e
2325         CODE:
2326                 RETVAL = e->jaxis.which;
2327         OUTPUT:
2328                 RETVAL
2329
2330 Uint8
2331 JoyAxisEventAxis ( e )
2332         SDL_Event *e
2333         CODE:
2334                 RETVAL = e->jaxis.axis;
2335         OUTPUT:
2336                 RETVAL
2337
2338 Sint16
2339 JoyAxisEventValue ( e )
2340         SDL_Event *e
2341         CODE:
2342                 RETVAL = e->jaxis.value;
2343         OUTPUT:
2344                 RETVAL
2345
2346 Uint8
2347 JoyButtonEventWhich ( e )
2348         SDL_Event *e
2349         CODE:
2350                 RETVAL = e->jbutton.which;
2351         OUTPUT:
2352                 RETVAL
2353
2354 Uint8
2355 JoyButtonEventButton ( e )
2356         SDL_Event *e
2357         CODE:
2358                 RETVAL = e->jbutton.button;
2359         OUTPUT:
2360                 RETVAL
2361
2362 Uint8
2363 JoyButtonEventState ( e )
2364         SDL_Event *e
2365         CODE:
2366                 RETVAL = e->jbutton.state;
2367         OUTPUT:
2368                 RETVAL
2369         
2370 Uint8
2371 JoyHatEventWhich ( e )
2372         SDL_Event *e
2373         CODE:
2374                 RETVAL = e->jhat.which;
2375         OUTPUT:
2376                 RETVAL
2377
2378 Uint8
2379 JoyHatEventHat ( e )
2380         SDL_Event *e
2381         CODE:
2382                 RETVAL = e->jhat.hat;
2383         OUTPUT:
2384                 RETVAL
2385
2386 Uint8
2387 JoyHatEventValue ( e )
2388         SDL_Event *e
2389         CODE:
2390                 RETVAL = e->jhat.value;
2391         OUTPUT:
2392                 RETVAL
2393
2394 Uint8
2395 JoyBallEventWhich ( e )
2396         SDL_Event *e
2397         CODE: 
2398                 RETVAL = e->jball.which;
2399         OUTPUT:
2400                 RETVAL
2401
2402 Uint8
2403 JoyBallEventBall ( e )
2404         SDL_Event *e
2405         CODE:
2406                 RETVAL = e->jball.ball;
2407         OUTPUT:
2408                 RETVAL
2409
2410 Sint16
2411 JoyBallEventXrel ( e )
2412         SDL_Event *e
2413         CODE:
2414                 RETVAL = e->jball.xrel;
2415         OUTPUT:
2416                 RETVAL
2417
2418 Sint16
2419 JoyBallEventYrel ( e )
2420         SDL_Event *e
2421         CODE:
2422                 RETVAL = e->jball.yrel;
2423         OUTPUT:
2424                 RETVAL
2425
2426 void
2427 SetClipRect ( surface, rect )
2428         SDL_Surface *surface
2429         SDL_Rect *rect
2430         CODE:
2431                 SDL_SetClipRect(surface,rect);
2432         
2433 void
2434 GetClipRect ( surface, rect )
2435         SDL_Surface *surface
2436         SDL_Rect *rect;
2437         CODE:
2438                 SDL_GetClipRect(surface, rect);
2439
2440
2441 #ifdef HAVE_SDL_NET
2442
2443 int
2444 NetInit ()
2445         CODE:
2446                 RETVAL = SDLNet_Init();
2447         OUTPUT:
2448                 RETVAL
2449
2450 void
2451 NetQuit ()
2452         CODE:
2453                 SDLNet_Quit();
2454
2455 IPaddress*
2456 NetNewIPaddress ( host, port )
2457         Uint32 host
2458         Uint16 port
2459         CODE:
2460                 RETVAL = (IPaddress*) safemalloc(sizeof(IPaddress));
2461                 RETVAL->host = host;
2462                 RETVAL->port = port;
2463         OUTPUT:
2464                 RETVAL
2465
2466 Uint32
2467 NetIPaddressHost ( ip )
2468         IPaddress *ip
2469         CODE:
2470                 RETVAL = ip->host;
2471         OUTPUT:
2472                 RETVAL
2473
2474 Uint16
2475 NetIPaddressPort ( ip )
2476         IPaddress *ip
2477         CODE:
2478                 RETVAL = ip->port;
2479         OUTPUT:
2480                 RETVAL
2481
2482 void
2483 NetFreeIPaddress ( ip )
2484         IPaddress *ip
2485         CODE:
2486                 safefree(ip);
2487
2488 const char*
2489 NetResolveIP ( address )
2490         IPaddress *address
2491         CODE:
2492                 RETVAL = SDLNet_ResolveIP(address);
2493         OUTPUT:
2494                 RETVAL
2495
2496 int
2497 NetResolveHost ( address, host, port )
2498         IPaddress *address
2499         const char *host
2500         Uint16 port
2501         CODE:
2502                 RETVAL = SDLNet_ResolveHost(address,host,port);
2503         OUTPUT:
2504                 RETVAL
2505         
2506 TCPsocket
2507 NetTCPOpen ( ip )
2508         IPaddress *ip
2509         CODE:
2510                 RETVAL = SDLNet_TCP_Open(ip);
2511         OUTPUT:
2512                 RETVAL
2513
2514 TCPsocket
2515 NetTCPAccept ( server )
2516         TCPsocket server
2517         CODE:
2518                 RETVAL = SDLNet_TCP_Accept(server);
2519         OUTPUT:
2520                 RETVAL
2521
2522 IPaddress*
2523 NetTCPGetPeerAddress ( sock )
2524         TCPsocket sock
2525         CODE:
2526                 RETVAL = SDLNet_TCP_GetPeerAddress(sock);
2527         OUTPUT:
2528                 RETVAL
2529
2530 int
2531 NetTCPSend ( sock, data, len  )
2532         TCPsocket sock
2533         void *data
2534         int len
2535         CODE:
2536                 RETVAL = SDLNet_TCP_Send(sock,data,len);
2537         OUTPUT:
2538                 RETVAL
2539
2540 AV*
2541 NetTCPRecv ( sock, maxlen )
2542         TCPsocket sock
2543         int maxlen
2544         CODE:
2545                 int status;
2546                 void *buffer;
2547                 buffer = safemalloc(maxlen);
2548                 RETVAL = newAV();
2549                 status = SDLNet_TCP_Recv(sock,buffer,maxlen);
2550                 av_push(RETVAL,newSViv(status));
2551                 av_push(RETVAL,newSVpvn((char*)buffer,maxlen));
2552         OUTPUT:
2553                 RETVAL  
2554         
2555 void
2556 NetTCPClose ( sock )
2557         TCPsocket sock
2558         CODE:
2559                 SDLNet_TCP_Close(sock);
2560
2561 UDPpacket*
2562 NetAllocPacket ( size )
2563         int size
2564         CODE:
2565                 RETVAL = SDLNet_AllocPacket(size);
2566         OUTPUT:
2567                 RETVAL
2568
2569 UDPpacket**
2570 NetAllocPacketV ( howmany, size )
2571         int howmany
2572         int size
2573         CODE:
2574                 RETVAL = SDLNet_AllocPacketV(howmany,size);
2575         OUTPUT:
2576                 RETVAL
2577
2578 int
2579 NetResizePacket ( packet, newsize )
2580         UDPpacket *packet
2581         int newsize
2582         CODE:
2583                 RETVAL = SDLNet_ResizePacket(packet,newsize);
2584         OUTPUT:
2585                 RETVAL
2586
2587 void
2588 NetFreePacket ( packet )
2589         UDPpacket *packet
2590         CODE:
2591                 SDLNet_FreePacket(packet);
2592
2593 void
2594 NetFreePacketV ( packet )
2595         UDPpacket **packet
2596         CODE:
2597                 SDLNet_FreePacketV(packet);
2598
2599 UDPsocket
2600 NetUDPOpen ( port )
2601         Uint16 port
2602         CODE:
2603                 RETVAL = SDLNet_UDP_Open(port);
2604         OUTPUT:
2605                 RETVAL
2606
2607 int
2608 NetUDPBind ( sock, channel, address )
2609         UDPsocket sock
2610         int channel
2611         IPaddress *address
2612         CODE:
2613                 RETVAL = SDLNet_UDP_Bind(sock,channel,address);
2614         OUTPUT:
2615                 RETVAL
2616
2617 void
2618 NetUDPUnbind ( sock, channel )
2619         UDPsocket sock
2620         int channel
2621         CODE:
2622                 SDLNet_UDP_Unbind(sock,channel);
2623
2624 IPaddress*
2625 NetUDPGetPeerAddress ( sock, channel )
2626         UDPsocket sock
2627         int channel
2628         CODE:
2629                 RETVAL = SDLNet_UDP_GetPeerAddress(sock,channel);
2630         OUTPUT:
2631                 RETVAL
2632
2633 int
2634 NetUDPSendV ( sock, packets, npackets )
2635         UDPsocket sock
2636         UDPpacket **packets
2637         int npackets
2638         CODE:
2639                 RETVAL = SDLNet_UDP_SendV(sock,packets,npackets);
2640         OUTPUT:
2641                 RETVAL
2642
2643 int
2644 NetUDPSend ( sock, channel, packet )
2645         UDPsocket sock
2646         int channel
2647         UDPpacket *packet 
2648         CODE:
2649                 RETVAL = SDLNet_UDP_Send(sock,channel,packet);
2650         OUTPUT:
2651                 RETVAL
2652
2653 int
2654 NetUDPRecvV ( sock, packets )
2655         UDPsocket sock
2656         UDPpacket **packets
2657         CODE:
2658                 RETVAL = SDLNet_UDP_RecvV(sock,packets);
2659         OUTPUT:
2660                 RETVAL
2661
2662 int
2663 NetUDPRecv ( sock, packet )
2664         UDPsocket sock
2665         UDPpacket *packet
2666         CODE:
2667                 RETVAL = SDLNet_UDP_Recv(sock,packet);
2668         OUTPUT:
2669                 RETVAL
2670
2671 void
2672 NetUDPClose ( sock )
2673         UDPsocket sock
2674         CODE:
2675                 SDLNet_UDP_Close(sock);
2676
2677 SDLNet_SocketSet
2678 NetAllocSocketSet ( maxsockets )
2679         int maxsockets
2680         CODE:
2681                 RETVAL = SDLNet_AllocSocketSet(maxsockets);
2682         OUTPUT:
2683                 RETVAL
2684
2685 int
2686 NetTCP_AddSocket ( set, sock )
2687         SDLNet_SocketSet set
2688         TCPsocket sock
2689         CODE:
2690                 RETVAL = SDLNet_TCP_AddSocket(set,sock);
2691         OUTPUT:
2692                 RETVAL
2693
2694 int
2695 NetUDP_AddSocket ( set, sock )
2696         SDLNet_SocketSet set
2697         UDPsocket sock
2698         CODE:
2699                 RETVAL = SDLNet_UDP_AddSocket(set,sock);
2700         OUTPUT:
2701                 RETVAL
2702
2703 int
2704 NetTCP_DelSocket ( set, sock )
2705         SDLNet_SocketSet set
2706         TCPsocket sock
2707         CODE:
2708                 RETVAL = SDLNet_TCP_DelSocket(set,sock);
2709         OUTPUT:
2710                 RETVAL
2711
2712 int
2713 NetUDP_DelSocket ( set, sock )
2714         SDLNet_SocketSet set
2715         UDPsocket sock
2716         CODE:
2717                 RETVAL = SDLNet_UDP_DelSocket(set,sock);
2718         OUTPUT:
2719                 RETVAL
2720
2721 int
2722 NetCheckSockets ( set, timeout )
2723         SDLNet_SocketSet set
2724         Uint32 timeout
2725         CODE:
2726                 RETVAL = SDLNet_CheckSockets(set,timeout);
2727         OUTPUT:
2728                 RETVAL
2729
2730 int
2731 NetSocketReady ( sock )
2732         SDLNet_GenericSocket sock
2733         CODE:
2734                 RETVAL = SDLNet_SocketReady(sock);
2735         OUTPUT:
2736                 RETVAL
2737
2738 void
2739 NetFreeSocketSet ( set )
2740         SDLNet_SocketSet set
2741         CODE:
2742                 SDLNet_FreeSocketSet(set);
2743
2744 void
2745 NetWrite16 ( value, area )
2746         Uint16 value
2747         void *area
2748         CODE:
2749                 SDLNet_Write16(value,area);
2750
2751 void
2752 NetWrite32 ( value, area )
2753         Uint32 value
2754         void *area
2755         CODE:
2756                 SDLNet_Write32(value,area);
2757         
2758 Uint16
2759 NetRead16 ( area )
2760         void *area
2761         CODE:
2762                 RETVAL = SDLNet_Read16(area);
2763         OUTPUT:
2764                 RETVAL
2765
2766 Uint32
2767 NetRead32 ( area )
2768         void *area
2769         CODE:
2770                 RETVAL = SDLNet_Read32(area);
2771         OUTPUT:
2772                 RETVAL
2773
2774 #endif 
2775
2776 int
2777 LockYUVOverlay ( overlay )
2778         SDL_Overlay *overlay
2779         CODE:
2780                 RETVAL = SDL_LockYUVOverlay(overlay);
2781         OUTPUT:
2782                 RETVAL
2783
2784 void
2785 UnlockYUVOverlay ( overlay )
2786         SDL_Overlay *overlay
2787         CODE:
2788                 SDL_UnlockYUVOverlay(overlay);
2789
2790 int
2791 DisplayYUVOverlay ( overlay, dstrect )
2792         SDL_Overlay *overlay
2793         SDL_Rect *dstrect
2794         CODE:
2795                 RETVAL = SDL_DisplayYUVOverlay ( overlay, dstrect );
2796         OUTPUT:
2797                 RETVAL
2798
2799 Uint32
2800 OverlayFormat ( overlay, ... )
2801         SDL_Overlay *overlay
2802         CODE:
2803                 if ( items > 1 ) 
2804                         overlay->format = SvIV(ST(1));
2805                 RETVAL = overlay->format;
2806         OUTPUT:
2807                 RETVAL
2808
2809 int 
2810 OverlayW ( overlay, ... )
2811         SDL_Overlay *overlay
2812         CODE:
2813                 if ( items > 1 ) 
2814                         overlay->w = SvIV(ST(1));
2815                 RETVAL = overlay->w;
2816         OUTPUT:
2817                 RETVAL
2818
2819 int
2820 OverlayH ( overlay, ... )
2821         SDL_Overlay *overlay
2822         CODE:
2823                 if ( items > 1 )
2824                         overlay->h = SvIV(ST(1));
2825                 RETVAL = overlay->h;
2826         OUTPUT:
2827                 RETVAL 
2828
2829 int
2830 OverlayPlanes ( overlay, ... )
2831         SDL_Overlay *overlay
2832         CODE:
2833                 if ( items > 1 )
2834                         overlay->planes = SvIV(ST(1));
2835                 RETVAL = overlay->planes;
2836         OUTPUT:
2837                 RETVAL
2838
2839 Uint32
2840 OverlayHW ( overlay )
2841         SDL_Overlay *overlay
2842         CODE:
2843                 RETVAL = overlay->hw_overlay;
2844         OUTPUT:
2845                 RETVAL
2846
2847 Uint16*
2848 OverlayPitches ( overlay )
2849         SDL_Overlay *overlay
2850         CODE:
2851                 RETVAL = overlay->pitches;
2852         OUTPUT:
2853                 RETVAL
2854
2855 Uint8**
2856 OverlayPixels ( overlay )
2857         SDL_Overlay *overlay
2858         CODE:
2859                 RETVAL = overlay->pixels;
2860         OUTPUT:
2861                 RETVAL
2862
2863 int
2864 WMToggleFullScreen ( surface )
2865         SDL_Surface *surface
2866         CODE:
2867                 RETVAL = SDL_WM_ToggleFullScreen(surface);
2868         OUTPUT:
2869                 RETVAL
2870
2871 Uint32
2872 WMGrabInput ( mode )
2873         Uint32 mode
2874         CODE:
2875                 RETVAL = SDL_WM_GrabInput(mode);
2876         OUTPUT:
2877                 RETVAL
2878
2879 int
2880 WMIconifyWindow ()
2881         CODE:
2882                 RETVAL = SDL_WM_IconifyWindow();
2883         OUTPUT:
2884                 RETVAL
2885
2886 int
2887 ResizeEventW ( e )
2888         SDL_Event *e
2889         CODE:
2890                 RETVAL = e->resize.w;
2891         OUTPUT:
2892                 RETVAL
2893
2894 int
2895 ResizeEventH ( e )
2896         SDL_Event *e
2897         CODE:
2898                 RETVAL = e->resize.h;
2899         OUTPUT:
2900                 RETVAL
2901
2902 char*
2903 AudioDriverName ()
2904         CODE:
2905                 char name[32];
2906                 RETVAL = SDL_AudioDriverName(name,32);
2907         OUTPUT:
2908                 RETVAL
2909
2910 Uint32
2911 GetKeyState ( k )
2912         SDLKey k
2913         CODE:
2914                 if (k >= SDLK_LAST) Perl_croak (aTHX_ "Key out of range");      
2915                 RETVAL = SDL_GetKeyState(NULL)[k];
2916         OUTPUT:
2917                 RETVAL
2918
2919 #ifdef HAVE_SMPEG
2920
2921 SMPEG_Info *
2922 NewSMPEGInfo()
2923         CODE:   
2924                 RETVAL = (SMPEG_Info *) safemalloc (sizeof(SMPEG_Info));
2925         OUTPUT:
2926                 RETVAL
2927
2928 void
2929 FreeSMPEGInfo ( info )
2930         SMPEG_Info *info
2931         CODE:   
2932                 safefree(info);
2933
2934 int
2935 SMPEGInfoHasAudio ( info )
2936         SMPEG_Info* info
2937         CODE:
2938                 RETVAL = info->has_audio;
2939         OUTPUT:
2940                 RETVAL
2941
2942 int
2943 SMPEGInfoHasVideo ( info )
2944         SMPEG_Info* info
2945         CODE:
2946                 RETVAL = info->has_video;
2947         OUTPUT:
2948                 RETVAL
2949
2950 int
2951 SMPEGInfoWidth ( info )
2952         SMPEG_Info* info
2953         CODE:
2954                 RETVAL = info->width;
2955         OUTPUT:
2956                 RETVAL
2957
2958 int
2959 SMPEGInfoHeight ( info )
2960         SMPEG_Info* info
2961         CODE:
2962                 RETVAL = info->height;
2963         OUTPUT:
2964                 RETVAL
2965
2966 int
2967 SMPEGInfoCurrentFrame ( info )
2968         SMPEG_Info* info
2969         CODE:
2970                 RETVAL = info->current_frame;
2971         OUTPUT:
2972                 RETVAL
2973
2974 double
2975 SMPEGInfoCurrentFPS ( info )
2976         SMPEG_Info* info
2977         CODE:
2978                 RETVAL = info->current_fps;
2979         OUTPUT:
2980                 RETVAL
2981
2982 int
2983 SMPEGInfoCurrentAudioFrame ( info )
2984         SMPEG_Info* info
2985         CODE:
2986                 RETVAL = info->audio_current_frame;
2987         OUTPUT:
2988                 RETVAL
2989
2990 int
2991 SMPEGInfoCurrentOffset ( info )
2992         SMPEG_Info* info
2993         CODE:
2994                 RETVAL = info->current_offset;
2995         OUTPUT:
2996                 RETVAL
2997
2998 int
2999 SMPEGInfoTotalSize ( info )
3000         SMPEG_Info* info
3001         CODE:
3002                 RETVAL = info->total_size;
3003         OUTPUT:
3004                 RETVAL
3005
3006 double
3007 SMPEGInfoCurrentTime ( info )
3008         SMPEG_Info* info
3009         CODE:
3010                 RETVAL = info->current_time;
3011         OUTPUT:
3012                 RETVAL
3013
3014 double
3015 SMPEGInfoTotalTime ( info )
3016         SMPEG_Info* info
3017         CODE:
3018                 RETVAL = info->total_time;
3019         OUTPUT:
3020                 RETVAL
3021
3022 char *
3023 SMPEGError ( mpeg )
3024         SMPEG* mpeg
3025         CODE:   
3026                 RETVAL = SMPEG_error(mpeg);
3027         OUTPUT:
3028                 RETVAL
3029
3030 SMPEG*
3031 NewSMPEG ( filename, info, use_audio )
3032         char* filename
3033         SMPEG_Info* info
3034         int use_audio
3035         CODE:   
3036 #ifdef HAVE_SDL_MIXER
3037                 RETVAL = SMPEG_new(filename,info,0);
3038 #else
3039                 RETVAL = SMPEG_new(filename,info,use_audio);
3040 #endif
3041         OUTPUT:
3042                 RETVAL
3043
3044 void
3045 FreeSMPEG ( mpeg )
3046         SMPEG* mpeg
3047         CODE:
3048                 SMPEG_delete(mpeg);
3049
3050 void
3051 SMPEGEnableAudio ( mpeg , flag )
3052         SMPEG* mpeg
3053         int flag
3054         CODE:   
3055                 SMPEG_enableaudio(mpeg,flag);
3056 #ifdef HAVE_SDL_MIXER
3057                 sdl_perl_use_smpeg_audio = flag;
3058 #endif
3059
3060 void
3061 SMPEGEnableVideo ( mpeg , flag )
3062         SMPEG* mpeg
3063         int flag
3064         CODE:   
3065                 SMPEG_enablevideo(mpeg,flag);
3066
3067 void
3068 SMPEGSetVolume ( mpeg , volume )
3069         SMPEG* mpeg
3070         int volume
3071         CODE:   
3072                 SMPEG_setvolume(mpeg,volume);
3073
3074 void
3075 SMPEGSetDisplay ( mpeg, dest, surfLock )
3076         SMPEG* mpeg
3077         SDL_Surface* dest
3078         SDL_mutex*  surfLock
3079         CODE:
3080                 SMPEG_setdisplay(mpeg,dest,surfLock,NULL);
3081
3082 void
3083 SMPEGScaleXY ( mpeg, w, h)
3084         SMPEG* mpeg
3085         int w
3086         int h
3087         CODE:
3088                 SMPEG_scaleXY(mpeg,w,h);
3089
3090 void
3091 SMPEGScale ( mpeg, scale )
3092         SMPEG* mpeg
3093         int scale
3094         CODE:
3095                 SMPEG_scale(mpeg,scale);
3096
3097 void
3098 SMPEGPlay ( mpeg )
3099         SMPEG* mpeg
3100         CODE:
3101                 SDL_AudioSpec audiofmt;
3102                 Uint16 format;
3103                 int freq, channels;
3104 #ifdef HAVE_SDL_MIXER
3105                 if  (sdl_perl_use_smpeg_audio ) {
3106                         SMPEG_enableaudio(mpeg, 0);
3107                         Mix_QuerySpec(&freq, &format, &channels);
3108                         audiofmt.format = format;
3109                         audiofmt.freq = freq;
3110                         audiofmt.channels = channels;
3111                         SMPEG_actualSpec(mpeg, &audiofmt);
3112                         Mix_HookMusic(SMPEG_playAudioSDL, mpeg);
3113                         SMPEG_enableaudio(mpeg, 1);
3114                 }
3115 #endif
3116                 SMPEG_play(mpeg);
3117
3118 SMPEGstatus
3119 SMPEGStatus ( mpeg )
3120         SMPEG* mpeg
3121         CODE:
3122                 RETVAL = SMPEG_status(mpeg);
3123         OUTPUT:
3124                 RETVAL
3125
3126 void
3127 SMPEGPause ( mpeg )
3128         SMPEG* mpeg
3129         CODE:
3130                 SMPEG_pause(mpeg);
3131
3132 void
3133 SMPEGLoop ( mpeg, repeat )
3134         SMPEG* mpeg
3135         int repeat
3136         CODE:
3137                 SMPEG_loop(mpeg,repeat);
3138
3139 void
3140 SMPEGStop ( mpeg )
3141         SMPEG* mpeg
3142         CODE:
3143                 SMPEG_stop(mpeg);
3144 #ifdef HAVE_SDL_MIXER
3145                 Mix_HookMusic(NULL, NULL);
3146 #endif
3147
3148 void
3149 SMPEGRewind ( mpeg )
3150         SMPEG* mpeg
3151         CODE:
3152                 SMPEG_rewind(mpeg);
3153
3154 void
3155 SMPEGSeek ( mpeg, bytes )
3156         SMPEG* mpeg
3157         int bytes
3158         CODE:
3159                 SMPEG_seek(mpeg,bytes);
3160
3161 void
3162 SMPEGSkip ( mpeg, seconds )
3163         SMPEG* mpeg
3164         float seconds
3165         CODE:
3166                 SMPEG_skip(mpeg,seconds);
3167
3168 void
3169 SMPEGSetDisplayRegion ( mpeg, rect )
3170         SMPEG* mpeg
3171         SDL_Rect* rect
3172         CODE:
3173                 SMPEG_setdisplayregion(mpeg,rect->x,rect->y,rect->w,rect->h);
3174
3175 void
3176 SMPEGRenderFrame ( mpeg, frame )
3177         SMPEG* mpeg
3178         int frame
3179         CODE:
3180                 SMPEG_renderFrame(mpeg,frame);
3181
3182 SMPEG_Info *
3183 SMPEGGetInfo ( mpeg )
3184         SMPEG* mpeg
3185         CODE:
3186                 RETVAL = (SMPEG_Info *) safemalloc (sizeof(SMPEG_Info));
3187                 SMPEG_getinfo(mpeg,RETVAL);
3188         OUTPUT:
3189                 RETVAL
3190         
3191
3192 #endif
3193
3194 #ifdef HAVE_SDL_GFX
3195
3196 =cut
3197
3198 SDL_Surface *
3199 GFXRotoZoom ( src, angle, zoom, smooth)
3200         SDL_Surface * src
3201         double angle
3202         double zoom
3203         int smooth
3204         CODE:
3205                 RETVAL = rotozoomSurface( src, angle, zoom, smooth);
3206         OUTPUT:
3207                 RETVAL
3208
3209 SDL_Surface *
3210 GFXZoom ( src, zoomx, zoomy, smooth)
3211         SDL_Surface *src
3212         double zoomx
3213         double zoomy
3214         int smooth
3215         CODE:
3216                 RETVAL = zoomSurface( src, zoomx, zoomy, smooth);
3217         OUTPUT:
3218                 RETVAL
3219
3220 =cut
3221
3222 int
3223 GFXPixelColor ( dst, x, y, color )
3224         SDL_Surface* dst
3225         Sint16 x
3226         Sint16 y
3227         Uint32 color
3228         CODE:
3229                 RETVAL = pixelColor( dst, x, y, color);
3230         OUTPUT:
3231                 RETVAL
3232
3233 int
3234 GFXPixelRGBA ( dst, x, y, r, g, b, a )
3235         SDL_Surface* dst
3236         Sint16 x
3237         Sint16 y
3238         Uint8 r
3239         Uint8 g
3240         Uint8 b
3241         Uint8 a
3242         CODE:
3243                 RETVAL = pixelRGBA( dst, x, y, r, g, b, a );
3244         OUTPUT:
3245                 RETVAL
3246
3247 int
3248 GFXHlineColor ( dst, x1, x2, y, color )
3249         SDL_Surface* dst
3250         Sint16 x1
3251         Sint16 x2
3252         Sint16 y
3253         Uint32 color
3254         CODE:
3255                 RETVAL = hlineColor( dst, x1, x2, y, color );
3256         OUTPUT:
3257                 RETVAL
3258
3259 int
3260 GFXHlineRGBA ( dst, x1, x2, y, r, g, b, a )
3261         SDL_Surface* dst
3262         Sint16 x1
3263         Sint16 x2
3264         Sint16 y
3265         Uint8 r
3266         Uint8 g
3267         Uint8 b
3268         Uint8 a
3269         CODE:
3270                 RETVAL = hlineRGBA( dst, x1, x2, y, r, g, b, a );
3271         OUTPUT:
3272                 RETVAL
3273
3274 int
3275 GFXVlineColor ( dst, x, y1, y2, color )
3276         SDL_Surface* dst
3277         Sint16 x
3278         Sint16 y1
3279         Sint16 y2
3280         Uint32 color
3281         CODE:
3282                 RETVAL = vlineColor( dst, x, y1, y2, color );
3283         OUTPUT:
3284                 RETVAL
3285
3286 int
3287 GFXVlineRGBA ( dst, x, y1, y2, r, g, b, a )
3288         SDL_Surface* dst
3289         Sint16 x
3290         Sint16 y1
3291         Sint16 y2
3292         Uint8 r
3293         Uint8 g
3294         Uint8 b
3295         Uint8 a
3296         CODE:
3297                 RETVAL = vlineRGBA( dst, x, y1, y2, r, g, b, a );
3298         OUTPUT:
3299                 RETVAL
3300
3301 int
3302 GFXRectangleColor ( dst, x1, y1, x2, y2, color )
3303         SDL_Surface* dst
3304         Sint16 x1
3305         Sint16 y1
3306         Sint16 x2
3307         Sint16 y2
3308         Uint32 color
3309         CODE:
3310                 RETVAL = rectangleColor( dst, x1, y1, x2, y2, color );
3311         OUTPUT:
3312                 RETVAL
3313
3314 int
3315 GFXRectangleRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3316         SDL_Surface* dst
3317         Sint16 x1
3318         Sint16 y1
3319         Sint16 x2
3320         Sint16 y2
3321         Uint8 r
3322         Uint8 g
3323         Uint8 b
3324         Uint8 a
3325         CODE:
3326                 RETVAL = rectangleRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3327         OUTPUT:
3328                 RETVAL
3329
3330 int
3331 GFXBoxColor ( dst, x1, y1, x2, y2, color )
3332         SDL_Surface* dst
3333         Sint16 x1
3334         Sint16 y1
3335         Sint16 x2
3336         Sint16 y2
3337         Uint32 color
3338         CODE:
3339                 RETVAL = boxColor( dst, x1, y1, x2, y2, color );
3340         OUTPUT:
3341                 RETVAL
3342
3343 int
3344 GFXBoxRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3345         SDL_Surface* dst;
3346         Sint16 x1
3347         Sint16 y1
3348         Sint16 x2
3349         Sint16 y2
3350         Uint8 r
3351         Uint8 g
3352         Uint8 b
3353         Uint8 a
3354         CODE:
3355                 RETVAL = boxRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3356         OUTPUT:
3357                 RETVAL
3358
3359 int
3360 GFXLineColor ( dst, x1, y1, x2, y2, color )
3361         SDL_Surface* dst
3362         Sint16 x1
3363         Sint16 y1
3364         Sint16 x2
3365         Sint16 y2
3366         Uint32 color
3367         CODE:
3368                 RETVAL = lineColor( dst, x1, y1, x2, y2, color );
3369         OUTPUT:
3370                 RETVAL
3371
3372 int
3373 GFXLineRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3374         SDL_Surface* dst
3375         Sint16 x1
3376         Sint16 y1
3377         Sint16 x2
3378         Sint16 y2
3379         Uint8 r
3380         Uint8 g
3381         Uint8 b
3382         Uint8 a
3383         CODE:
3384                 RETVAL = lineRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3385         OUTPUT:
3386                 RETVAL
3387
3388 int
3389 GFXAalineColor ( dst, x1, y1, x2, y2, color )
3390         SDL_Surface* dst
3391         Sint16 x1
3392         Sint16 y1
3393         Sint16 x2
3394         Sint16 y2
3395         Uint32 color
3396         CODE:
3397                 RETVAL = aalineColor( dst, x1, y1, x2, y2, color );
3398         OUTPUT:
3399                 RETVAL
3400
3401 int
3402 GFXAalineRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3403         SDL_Surface* dst
3404         Sint16 x1
3405         Sint16 y1
3406         Sint16 x2
3407         Sint16 y2
3408         Uint8 r
3409         Uint8 g
3410         Uint8 b
3411         Uint8 a
3412         CODE:
3413                 RETVAL = aalineRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3414         OUTPUT:
3415                 RETVAL
3416
3417 int
3418 GFXCircleColor ( dst, x, y, r, color )
3419         SDL_Surface* dst
3420         Sint16 x
3421         Sint16 y
3422         Sint16 r
3423         Uint32 color
3424         CODE:
3425                 RETVAL = circleColor( dst, x, y, r, color );
3426         OUTPUT:
3427                 RETVAL
3428
3429 int
3430 GFXCircleRGBA ( dst, x, y, rad, r, g, b, a )
3431         SDL_Surface* dst
3432         Sint16 x
3433         Sint16 y
3434         Sint16 rad
3435         Uint8 r
3436         Uint8 g
3437         Uint8 b
3438         Uint8 a
3439         CODE:
3440                 RETVAL = circleRGBA( dst, x, y, rad, r, g, b, a );
3441         OUTPUT:
3442                 RETVAL
3443
3444 int
3445 GFXAacircleColor ( dst, x, y, r, color )
3446         SDL_Surface* dst
3447         Sint16 x
3448         Sint16 y
3449         Sint16 r
3450         Uint32 color
3451         CODE:
3452                 RETVAL = aacircleColor( dst, x, y, r, color );
3453         OUTPUT:
3454                 RETVAL
3455
3456 int
3457 GFXAacircleRGBA ( dst, x, y, rad, r, g, b, a )
3458         SDL_Surface* dst
3459         Sint16 x
3460         Sint16 y
3461         Sint16 rad
3462         Uint8 r
3463         Uint8 g
3464         Uint8 b
3465         Uint8 a
3466         CODE:
3467                 RETVAL = aacircleRGBA( dst, x, y, rad, r, g, b, a );
3468         OUTPUT:
3469                 RETVAL
3470
3471 int
3472 GFXFilledCircleColor ( dst, x, y, r, color )
3473         SDL_Surface* dst
3474         Sint16 x
3475         Sint16 y
3476         Sint16 r
3477         Uint32 color
3478         CODE:
3479                 RETVAL = filledCircleColor( dst, x, y, r, color );
3480         OUTPUT:
3481                 RETVAL
3482
3483 int
3484 GFXFilledCircleRGBA ( dst, x, y, rad, r, g, b, a )
3485         SDL_Surface* dst
3486         Sint16 x
3487         Sint16 y
3488         Sint16 rad
3489         Uint8 r
3490         Uint8 g
3491         Uint8 b
3492         Uint8 a
3493         CODE:
3494                 RETVAL = filledCircleRGBA( dst, x, y, rad, r, g, b, a );
3495         OUTPUT:
3496                 RETVAL
3497
3498 int
3499 GFXEllipseColor ( dst, x, y, rx, ry, color )
3500         SDL_Surface* dst
3501         Sint16 x
3502         Sint16 y
3503         Sint16 rx
3504         Sint16 ry
3505         Uint32 color
3506         CODE:
3507                 RETVAL = ellipseColor( dst, x, y, rx, ry, color );
3508         OUTPUT:
3509                 RETVAL
3510
3511 int
3512 GFXEllipseRGBA ( dst, x, y, rx, ry, r, g, b, a )
3513         SDL_Surface* dst
3514         Sint16 x
3515         Sint16 y
3516         Sint16  rx
3517         Sint16 ry
3518         Uint8 r
3519         Uint8 g
3520         Uint8 b
3521         Uint8 a
3522         CODE:
3523                 RETVAL = ellipseRGBA( dst, x, y, rx, ry, r, g, b, a );
3524         OUTPUT:
3525                 RETVAL
3526
3527 int
3528 GFXAaellipseColor ( dst, xc, yc, rx, ry, color )
3529         SDL_Surface* dst
3530         Sint16 xc
3531         Sint16 yc
3532         Sint16 rx
3533         Sint16 ry
3534         Uint32 color
3535         CODE:
3536                 RETVAL = aaellipseColor( dst, xc, yc, rx, ry, color );
3537         OUTPUT:
3538                 RETVAL
3539
3540 int
3541 GFXAaellipseRGBA ( dst, x, y, rx, ry, r, g, b, a )
3542         SDL_Surface* dst
3543         Sint16 x
3544         Sint16 y
3545         Sint16 rx
3546         Sint16 ry
3547         Uint8 r
3548         Uint8 g
3549         Uint8 b
3550         Uint8 a
3551         CODE:
3552                 RETVAL = aaellipseRGBA( dst, x, y, rx, ry, r, g, b, a );
3553         OUTPUT:
3554                 RETVAL
3555
3556 int
3557 GFXFilledEllipseColor ( dst, x, y, rx, ry, color )
3558         SDL_Surface* dst
3559         Sint16 x
3560         Sint16 y
3561         Sint16 rx
3562         Sint16 ry
3563         Uint32 color
3564         CODE:
3565                 RETVAL = filledEllipseColor( dst, x, y, rx, ry, color );
3566         OUTPUT:
3567                 RETVAL
3568
3569 int
3570 GFXFilledEllipseRGBA ( dst, x, y, rx, ry, r, g, b, a )
3571         SDL_Surface* dst
3572         Sint16 x
3573         Sint16 y
3574         Sint16 rx
3575         Sint16 ry
3576         Uint8 r
3577         Uint8 g
3578         Uint8 b
3579         Uint8 a
3580         CODE:
3581                 RETVAL = filledEllipseRGBA( dst, x, y, rx, ry, r, g, b, a );
3582         OUTPUT:
3583                 RETVAL
3584
3585 int
3586 GFXFilledPieColor ( dst, x, y, rad, start, end, color )
3587         SDL_Surface* dst
3588         Sint16 x
3589         Sint16 y
3590         Sint16 rad
3591         Sint16 start
3592         Sint16 end
3593         Uint32 color
3594         CODE:
3595                 RETVAL = filledPieColor( dst, x, y, rad, start, end, color );
3596         OUTPUT:
3597                 RETVAL
3598
3599 int
3600 GFXFilledPieRGBA ( dst, x, y, rad, start, end, r, g, b, a )
3601         SDL_Surface* dst
3602         Sint16 x
3603         Sint16 y
3604         Sint16 rad
3605         Sint16 start
3606         Sint16 end
3607         Uint8 r
3608         Uint8 g
3609         Uint8 b
3610         Uint8 a
3611         CODE:
3612                 RETVAL = filledPieRGBA( dst, x, y, rad, start, end, r, g, b, a );
3613         OUTPUT:
3614                 RETVAL
3615
3616 int
3617 GFXPolygonColor ( dst, vx, vy, n, color )
3618         SDL_Surface* dst
3619         Sint16* vx
3620         Sint16* vy
3621         int n
3622         Uint32 color;
3623         CODE:
3624                 RETVAL = polygonColor( dst, vx, vy, n, color );
3625         OUTPUT:
3626                 RETVAL
3627
3628 int
3629 GFXPolygonRGBA ( dst, vx, vy, n, r, g, b, a )
3630         SDL_Surface* dst
3631         Sint16* vx
3632         Sint16* vy
3633         int n
3634         Uint8 r
3635         Uint8 g
3636         Uint8 b
3637         Uint8 a
3638         CODE:
3639                 RETVAL = polygonRGBA( dst, vx, vy, n, r, g, b, a );
3640         OUTPUT:
3641                 RETVAL
3642
3643 int
3644 GFXAapolygonColor ( dst, vx, vy, n, color )
3645         SDL_Surface* dst
3646         Sint16* vx
3647         Sint16* vy
3648         int n
3649         Uint32 color
3650         CODE:
3651                 RETVAL = aapolygonColor( dst, vx, vy, n, color );
3652         OUTPUT:
3653                 RETVAL
3654
3655 int
3656 GFXAapolygonRGBA ( dst, vx, vy, n, r, g, b, a )
3657         SDL_Surface* dst
3658         Sint16* vx
3659         Sint16* vy
3660         int n
3661         Uint8 r
3662         Uint8 g
3663         Uint8 b
3664         Uint8 a
3665         CODE:
3666                 RETVAL = aapolygonRGBA( dst, vx, vy, n, r, g, b, a );
3667         OUTPUT:
3668                 RETVAL
3669
3670 int
3671 GFXFilledPolygonColor ( dst, vx, vy, n, color )
3672         SDL_Surface* dst
3673         Sint16* vx
3674         Sint16* vy
3675         int n
3676         int color
3677         CODE:
3678                 RETVAL = filledPolygonColor( dst, vx, vy, n, color );
3679         OUTPUT:
3680                 RETVAL
3681
3682 int
3683 GFXFilledPolygonRGBA ( dst, vx, vy, n, r, g, b, a )
3684         SDL_Surface* dst
3685         Sint16* vx
3686         Sint16* vy
3687         int n
3688         Uint8 r
3689         Uint8 g
3690         Uint8 b
3691         Uint8 a
3692         CODE:
3693                 RETVAL = filledPolygonRGBA( dst, vx, vy, n, r, g, b, a );
3694         OUTPUT:
3695                 RETVAL
3696
3697 int
3698 GFXCharacterColor ( dst, x, y, c, color )
3699         SDL_Surface* dst
3700         Sint16 x
3701         Sint16 y
3702         char c
3703         Uint32 color
3704         CODE:
3705                 RETVAL = characterColor( dst, x, y, c, color );
3706         OUTPUT:
3707                 RETVAL
3708
3709 int
3710 GFXCharacterRGBA ( dst, x, y, c, r, g, b, a )
3711         SDL_Surface* dst
3712         Sint16 x
3713         Sint16 y
3714         char c
3715         Uint8 r
3716         Uint8 g
3717         Uint8 b
3718         Uint8 a
3719         CODE:
3720                 RETVAL = characterRGBA( dst, x, y, c, r, g, b, a );
3721         OUTPUT:
3722                 RETVAL
3723
3724 int
3725 GFXStringColor ( dst, x, y, c, color )
3726         SDL_Surface* dst
3727         Sint16 x
3728         Sint16 y
3729         char* c
3730         Uint32 color
3731         CODE:
3732                 RETVAL = stringColor( dst, x, y, c, color );
3733         OUTPUT:
3734                 RETVAL
3735
3736 int
3737 GFXStringRGBA ( dst, x, y, c, r, g, b, a )
3738         SDL_Surface* dst
3739         Sint16 x
3740         Sint16 y
3741         char* c
3742         Uint8 r
3743         Uint8 g
3744         Uint8 b
3745         Uint8 a
3746         CODE:
3747                 RETVAL = stringRGBA( dst, x, y, c, r, g, b, a );
3748         OUTPUT:
3749                 RETVAL
3750
3751 #endif
3752
3753
3754 #ifdef HAVE_SDL_SVG
3755
3756 SDL_svg_context *
3757 SVG_Load ( filename )
3758         char* filename
3759         CODE:
3760                 RETVAL = SVG_Load(filename);
3761         OUTPUT:
3762                 RETVAL
3763
3764 SDL_svg_context *
3765 SVG_LoadBuffer ( data, len )
3766         char* data
3767         int len
3768         CODE:
3769                 RETVAL = SVG_LoadBuffer(data,len);
3770         OUTPUT:
3771                 RETVAL
3772
3773 int
3774 SVG_SetOffset ( source, xoff, yoff )
3775         SDL_svg_context* source
3776         double xoff
3777         double yoff
3778         CODE:
3779                 RETVAL = SVG_SetOffset(source,xoff,yoff);
3780         OUTPUT:
3781                 RETVAL
3782
3783 int
3784 SVG_SetScale ( source, xscale, yscale )
3785         SDL_svg_context* source
3786         double xscale
3787         double yscale
3788         CODE:
3789                 RETVAL = SVG_SetScale(source,xscale,yscale);
3790         OUTPUT:
3791                 RETVAL
3792
3793 int
3794 SVG_RenderToSurface ( source, x, y, dest )
3795         SDL_svg_context* source
3796         int x
3797         int y
3798         SDL_Surface* dest;
3799         CODE:
3800                 RETVAL = SVG_RenderToSurface(source,x,y,dest);
3801         OUTPUT:
3802                 RETVAL
3803
3804 void
3805 SVG_Free ( source )
3806         SDL_svg_context* source
3807         CODE:
3808                 SVG_Free(source);       
3809
3810 void
3811 SVG_Set_Flags ( source, flags )
3812         SDL_svg_context* source
3813         Uint32 flags
3814         CODE:
3815                 SVG_Set_Flags(source,flags);
3816
3817 float
3818 SVG_Width ( source )
3819         SDL_svg_context* source
3820         CODE:
3821                 RETVAL = SVG_Width(source);
3822         OUTPUT:
3823                 RETVAL
3824
3825 float
3826 SVG_HEIGHT ( source )
3827         SDL_svg_context* source
3828         CODE:
3829                 RETVAL = SVG_Height(source);
3830         OUTPUT:
3831                 RETVAL
3832
3833 void
3834 SVG_SetClipping ( source, minx, miny, maxx, maxy )
3835         SDL_svg_context* source
3836         int minx
3837         int miny
3838         int maxx
3839         int maxy
3840         CODE:
3841                 SVG_SetClipping(source,minx,miny,maxx,maxy);
3842
3843 int
3844 SVG_Version ( )
3845         CODE:
3846                 RETVAL = SVG_Version();
3847         OUTPUT:
3848                 RETVAL
3849
3850
3851 #endif
3852
3853 #ifdef HAVE_SDL_SOUND
3854
3855 Uint16
3856 SoundAudioInfoFormat ( audioinfo )
3857         Sound_AudioInfo* audioinfo
3858         CODE:
3859                 RETVAL = audioinfo->format;
3860         OUTPUT:
3861                 RETVAL
3862
3863 Uint8
3864 SoundAudioInfoChannels ( audioinfo )
3865         Sound_AudioInfo* audioinfo
3866         CODE:
3867                 RETVAL = audioinfo->channels;
3868         OUTPUT:
3869                 RETVAL
3870
3871 Uint32
3872 SoundAudioInforate ( audioinfo )
3873         Sound_AudioInfo* audioinfo
3874         CODE:
3875                 RETVAL = audioinfo->rate;
3876         OUTPUT:
3877                 RETVAL
3878
3879 AV*
3880 SoundDecoderInfoExtensions ( decoderinfo )
3881         Sound_DecoderInfo* decoderinfo
3882         CODE:
3883                 const char **ext;
3884                 for ( ext = decoderinfo->extensions; *ext != NULL; ext++ ){
3885                         av_push(RETVAL,newSVpv(*ext,0));
3886                 }
3887         OUTPUT:
3888                 RETVAL
3889
3890 const char*
3891 SoundDecoderInfoDescription ( decoderinfo )
3892         Sound_DecoderInfo* decoderinfo
3893         CODE:
3894                 RETVAL = decoderinfo->description;
3895         OUTPUT:
3896                 RETVAL
3897
3898 const char*
3899 SoundDecoderInfoAuthor ( decoderinfo )
3900         Sound_DecoderInfo* decoderinfo
3901         CODE:
3902                 RETVAL = decoderinfo->author;
3903         OUTPUT:
3904                 RETVAL
3905
3906 const char*
3907 SoundDecoderInfoUrl ( decoderinfo )
3908         Sound_DecoderInfo* decoderinfo
3909         CODE:
3910                 RETVAL = decoderinfo->url;
3911         OUTPUT:
3912                 RETVAL
3913
3914 const Sound_DecoderInfo*
3915 SoundSampleDecoder ( sample ) 
3916         Sound_Sample* sample
3917         CODE:
3918                 RETVAL = sample->decoder;
3919         OUTPUT:
3920                 RETVAL
3921
3922 Sound_AudioInfo* 
3923 SoundSampleDesired ( sample )
3924         Sound_Sample* sample
3925         CODE:
3926                 RETVAL = &sample->desired;
3927         OUTPUT:
3928                 RETVAL
3929
3930 Sound_AudioInfo*
3931 SoundSampleAcutal ( sample )
3932         Sound_Sample* sample
3933         CODE:
3934                 RETVAL = &sample->actual;
3935         OUTPUT:
3936                 RETVAL
3937
3938 char*
3939 SoundSampleBuffer ( sample )
3940         Sound_Sample* sample
3941         CODE:
3942                 RETVAL = sample->buffer;
3943         OUTPUT:
3944                 RETVAL
3945
3946 Uint32
3947 SoundSampleBufferSize ( sample )
3948         Sound_Sample* sample
3949         CODE:
3950                 RETVAL = sample->buffer_size;
3951         OUTPUT:
3952                 RETVAL
3953
3954 Uint32
3955 SoundSampleFlags ( sample )
3956         Sound_Sample* sample
3957         CODE:
3958                 RETVAL = (Uint32)sample->flags;
3959         OUTPUT:
3960                 RETVAL
3961
3962 int
3963 Sound_Init ( )
3964         CODE:
3965                 RETVAL = Sound_Init();
3966         OUTPUT:
3967                 RETVAL
3968
3969 int
3970 Sound_Quit ( )
3971         CODE:
3972                 RETVAL = Sound_Quit();
3973         OUTPUT:
3974                 RETVAL
3975
3976 AV*
3977 Sound_AvailableDecoders ( )
3978         CODE:
3979                 RETVAL = newAV();
3980                 const Sound_DecoderInfo** sdi;
3981                 sdi = Sound_AvailableDecoders();
3982                 if (sdi != NULL)  {
3983                         for (;*sdi != NULL; ++sdi) {
3984                                 av_push(RETVAL,sv_2mortal(newSViv(PTR2IV(*sdi))));
3985                         }
3986                 }
3987         OUTPUT:
3988                 RETVAL
3989
3990 const char*
3991 Sound_GetError ( )
3992         CODE:
3993                 RETVAL = Sound_GetError();
3994         OUTPUT:
3995                 RETVAL
3996
3997 void
3998 Sound_ClearError ( )
3999         CODE:
4000                 Sound_ClearError();
4001
4002 Sound_Sample*
4003 Sound_NewSample ( rw, ext, desired, buffsize )
4004         SDL_RWops* rw
4005         const char* ext
4006         Sound_AudioInfo* desired
4007         Uint32 buffsize
4008         CODE:
4009                 RETVAL = Sound_NewSample(rw,ext,desired,buffsize);
4010         OUTPUT:
4011                 RETVAL
4012
4013 Sound_Sample*
4014 Sound_NewSampleFromMem ( data, size, ext, desired, buffsize )
4015         const Uint8 *data
4016         Uint32 size
4017         const char* ext
4018         Sound_AudioInfo* desired
4019         Uint32 buffsize
4020         CODE:
4021                 RETVAL = Sound_NewSampleFromMem(data,size,ext,desired,buffsize);
4022         OUTPUT:
4023                 RETVAL
4024
4025 Sound_Sample*
4026 Sound_NewSampleFromFile ( fname, desired, buffsize )
4027         const char* fname
4028         Sound_AudioInfo* desired
4029         Uint32 buffsize
4030         CODE:
4031                 RETVAL = Sound_NewSampleFromFile(fname,desired,buffsize);
4032         OUTPUT:
4033                 RETVAL
4034
4035 void
4036 Sound_FreeSample ( sample )
4037         Sound_Sample* sample
4038         CODE:
4039                 Sound_FreeSample(sample);
4040
4041 Sint32
4042 Sound_GetDuration ( sample )
4043         Sound_Sample* sample
4044         CODE:
4045                 RETVAL = Sound_GetDuration(sample);
4046         OUTPUT:
4047                 RETVAL
4048
4049 int
4050 Sound_SetBufferSize ( sample, size )
4051         Sound_Sample* sample
4052         Uint32 size
4053         CODE:
4054                 RETVAL = Sound_SetBufferSize(sample,size);
4055         OUTPUT:
4056                 RETVAL
4057
4058 Uint32
4059 Sound_Decode ( sample )
4060         Sound_Sample* sample
4061         CODE:
4062                 RETVAL = Sound_Decode(sample);
4063         OUTPUT:
4064                 RETVAL
4065
4066 Uint32
4067 Sound_DecodeAll ( sample ) 
4068         Sound_Sample* sample
4069         CODE:
4070                 RETVAL = Sound_DecodeAll(sample);
4071         OUTPUT:
4072                 RETVAL
4073
4074 int
4075 Sound_Rewind ( sample )
4076         Sound_Sample* sample
4077         CODE:
4078                 RETVAL = Sound_Rewind(sample);
4079         OUTPUT:
4080                 RETVAL
4081
4082 int
4083 Sound_Seek ( sample, ms )
4084         Sound_Sample* sample
4085         Uint32 ms
4086         CODE:
4087                 RETVAL = Sound_Seek(sample,ms);
4088         OUTPUT:
4089                 RETVAL
4090
4091 #endif
4092
4093 #ifdef HAVE_SDL_TTF
4094
4095 int
4096 TTF_Init ()
4097         CODE:
4098                 RETVAL = TTF_Init();
4099         OUTPUT:
4100                 RETVAL
4101
4102 void
4103 TTF_Quit ()
4104         CODE:
4105                 TTF_Quit();
4106
4107 TTF_Font*
4108 TTF_OpenFont ( file, ptsize )
4109         char *file
4110         int ptsize
4111         CODE:
4112                 char* CLASS = "SDL::TTF_Font";
4113                 RETVAL = TTF_OpenFont(file,ptsize);
4114         OUTPUT:
4115                 RETVAL
4116
4117 AV*
4118 TTF_SizeText ( font, text )
4119         TTF_Font *font
4120         char *text
4121         CODE:
4122                 int w,h;
4123                 RETVAL = newAV();
4124                 if(TTF_SizeText(font,text,&w,&h))
4125                 {
4126                         printf("TTF error at TTFSizeText: %s \n", TTF_GetError());
4127                         Perl_croak (aTHX_ "TTF error \n");
4128                 }
4129                 else
4130                 {
4131                         av_push(RETVAL,newSViv(w));
4132                         av_push(RETVAL,newSViv(h));
4133                         sv_2mortal((SV*)RETVAL);
4134                 }
4135         OUTPUT:
4136                 RETVAL
4137
4138 SDL_Surface*
4139 TTF_RenderText_Blended ( font, text, fg )
4140         TTF_Font *font
4141         char *text
4142         SDL_Color *fg
4143         CODE:
4144                 char* CLASS = "SDL::Surface";
4145                 RETVAL = TTF_RenderText_Blended(font,text,*fg);
4146         OUTPUT:
4147                 RETVAL
4148
4149 #endif
4150
4151 MODULE = SDL            PACKAGE = SDL
4152 PROTOTYPES : DISABLE
4153
4154