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