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