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