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