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