Added types for GLU and Tels Faster color function
[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                 TTF_SizeText(font,text,&w,&h);
2983                 av_push(RETVAL,newSViv(w));
2984                 av_push(RETVAL,newSViv(h));
2985         OUTPUT:
2986                 RETVAL
2987
2988 AV*
2989 TTFSizeUTF8 ( font, text )
2990         TTF_Font *font
2991         char *text
2992         CODE:
2993                 int w,h;
2994                 RETVAL = newAV();
2995                 TTF_SizeUTF8(font,text,&w,&h);
2996                 av_push(RETVAL,newSViv(w));
2997                 av_push(RETVAL,newSViv(h));
2998         OUTPUT:
2999                 RETVAL
3000
3001 AV*
3002 TTFSizeUNICODE ( font, text )
3003         TTF_Font *font
3004         const Uint16 *text
3005         CODE:
3006                 int w,h;
3007                 RETVAL = newAV();
3008                 TTF_SizeUNICODE(font,text,&w,&h);
3009                 av_push(RETVAL,newSViv(w));
3010                 av_push(RETVAL,newSViv(h));
3011         OUTPUT:
3012                 RETVAL
3013
3014 SDL_Surface*
3015 TTFRenderTextSolid ( font, text, fg )
3016         TTF_Font *font
3017         char *text
3018         SDL_Color *fg
3019         CODE:
3020                 RETVAL = TTF_RenderText_Solid(font,text,*fg);
3021         OUTPUT:
3022                 RETVAL
3023
3024 SDL_Surface*
3025 TTFRenderUTF8Solid ( font, text, fg )
3026         TTF_Font *font
3027         char *text
3028         SDL_Color *fg
3029         CODE:
3030                 RETVAL = TTF_RenderUTF8_Solid(font,text,*fg);
3031         OUTPUT:
3032                 RETVAL
3033
3034 SDL_Surface*
3035 TTFRenderUNICODESolid ( font, text, fg )
3036         TTF_Font *font
3037         const Uint16 *text
3038         SDL_Color *fg
3039         CODE:
3040                 RETVAL = TTF_RenderUNICODE_Solid(font,text,*fg);
3041         OUTPUT:
3042                 RETVAL
3043
3044 SDL_Surface*
3045 TTFRenderGlyphSolid ( font, ch, fg )
3046         TTF_Font *font
3047         Uint16 ch
3048         SDL_Color *fg
3049         CODE:
3050                 RETVAL = TTF_RenderGlyph_Solid(font,ch,*fg);
3051         OUTPUT:
3052                 RETVAL
3053
3054 SDL_Surface*
3055 TTFRenderTextShaded ( font, text, fg, bg )
3056         TTF_Font *font
3057         char *text
3058         SDL_Color *fg
3059         SDL_Color *bg
3060         CODE:
3061                 RETVAL = TTF_RenderText_Shaded(font,text,*fg,*bg);
3062         OUTPUT:
3063                 RETVAL
3064
3065 SDL_Surface*
3066 TTFRenderUTF8Shaded( font, text, fg, bg )
3067         TTF_Font *font
3068         char *text
3069         SDL_Color *fg
3070         SDL_Color *bg
3071         CODE:
3072                 RETVAL = TTF_RenderUTF8_Shaded(font,text,*fg,*bg);
3073         OUTPUT:
3074                 RETVAL
3075
3076 SDL_Surface*
3077 TTFRenderUNICODEShaded( font, text, fg, bg )
3078         TTF_Font *font
3079         const Uint16 *text
3080         SDL_Color *fg
3081         SDL_Color *bg
3082         CODE:
3083                 RETVAL = TTF_RenderUNICODE_Shaded(font,text,*fg,*bg);
3084         OUTPUT:
3085                 RETVAL
3086
3087 SDL_Surface*
3088 TTFRenderGlyphShaded ( font, ch, fg, bg )
3089         TTF_Font *font
3090         Uint16 ch
3091         SDL_Color *fg
3092         SDL_Color *bg
3093         CODE:
3094                 RETVAL = TTF_RenderGlyph_Shaded(font,ch,*fg,*bg);
3095         OUTPUT:
3096                 RETVAL
3097
3098 SDL_Surface*
3099 TTFRenderTextBlended( font, text, fg )
3100         TTF_Font *font
3101         char *text
3102         SDL_Color *fg
3103         CODE:
3104                 RETVAL = TTF_RenderText_Blended(font,text,*fg);
3105         OUTPUT:
3106                 RETVAL
3107
3108 SDL_Surface*
3109 TTFRenderUTF8Blended( font, text, fg )
3110         TTF_Font *font
3111         char *text
3112         SDL_Color *fg
3113         CODE:
3114                 RETVAL = TTF_RenderUTF8_Blended(font,text,*fg);
3115         OUTPUT:
3116                 RETVAL
3117
3118 SDL_Surface*
3119 TTFRenderUNICODEBlended( font, text, fg )
3120         TTF_Font *font
3121         const Uint16 *text
3122         SDL_Color *fg
3123         CODE:
3124                 RETVAL = TTF_RenderUNICODE_Blended(font,text,*fg);
3125         OUTPUT:
3126                 RETVAL
3127
3128 SDL_Surface*
3129 TTFRenderGlyphBlended( font, ch, fg )
3130         TTF_Font *font
3131         Uint16 ch
3132         SDL_Color *fg
3133         CODE:
3134                 RETVAL = TTF_RenderGlyph_Blended(font,ch,*fg);
3135         OUTPUT:
3136                 RETVAL
3137
3138 void
3139 TTFCloseFont ( font )
3140         TTF_Font *font
3141         CODE:
3142                 TTF_CloseFont(font);
3143                 font=NULL; //to be safe http://sdl.beuc.net/sdl.wiki/SDL_ttf_copy_Functions_Management_TTF_CloseFont
3144
3145 SDL_Surface*
3146 TTFPutString ( font, mode, surface, x, y, fg, bg, text )
3147         TTF_Font *font
3148         int mode
3149         SDL_Surface *surface
3150         int x
3151         int y
3152         SDL_Color *fg
3153         SDL_Color *bg
3154         char *text
3155         CODE:
3156                 SDL_Surface *img;
3157                 SDL_Rect dest;
3158                 int w,h;
3159                 dest.x = x;
3160                 dest.y = y;
3161                 RETVAL = NULL;
3162                 switch (mode) {
3163                         case TEXT_SOLID:
3164                                 img = TTF_RenderText_Solid(font,text,*fg);
3165                                 TTF_SizeText(font,text,&w,&h);
3166                                 dest.w = w;
3167                                 dest.h = h;
3168                                 break;
3169                         case TEXT_SHADED:
3170                                 img = TTF_RenderText_Shaded(font,text,*fg,*bg);
3171                                 TTF_SizeText(font,text,&w,&h);
3172                                 dest.w = w;
3173                                 dest.h = h;
3174                                 break;
3175                         case TEXT_BLENDED:
3176                                 img = TTF_RenderText_Blended(font,text,*fg);
3177                                 TTF_SizeText(font,text,&w,&h);
3178                                 dest.w = w;
3179                                 dest.h = h;
3180                                 break;
3181                         case UTF8_SOLID:
3182                                 img = TTF_RenderUTF8_Solid(font,text,*fg);
3183                                 TTF_SizeUTF8(font,text,&w,&h);
3184                                 dest.w = w;
3185                                 dest.h = h;
3186                                 break;
3187                         case UTF8_SHADED:
3188                                 img = TTF_RenderUTF8_Shaded(font,text,*fg,*bg);
3189                                 TTF_SizeUTF8(font,text,&w,&h);
3190                                 dest.w = w;
3191                                 dest.h = h;
3192                                 break;
3193                         case UTF8_BLENDED:
3194                                 img = TTF_RenderUTF8_Blended(font,text,*fg);
3195                                 TTF_SizeUTF8(font,text,&w,&h);
3196                                 dest.w = w;
3197                                 dest.h = h;
3198                                 break;
3199                         case UNICODE_SOLID:
3200                                 img = TTF_RenderUNICODE_Solid(font,(Uint16*)text,*fg);
3201                                 TTF_SizeUNICODE(font,(Uint16*)text,&w,&h);
3202                                 dest.w = w;
3203                                 dest.h = h;
3204                                 break;
3205                         case UNICODE_SHADED:
3206                                 img = TTF_RenderUNICODE_Shaded(font,(Uint16*)text,*fg,*bg);
3207                                 TTF_SizeUNICODE(font,(Uint16*)text,&w,&h);
3208                                 dest.w = w;
3209                                 dest.h = h;
3210                                 break;
3211                         case UNICODE_BLENDED:
3212                                 img = TTF_RenderUNICODE_Blended(font,(Uint16*)text,*fg);
3213                                 TTF_SizeUNICODE(font,(Uint16*)text,&w,&h);
3214                                 dest.w = w;
3215                                 dest.h = h;
3216                                 break;
3217                         default:
3218                                 img = TTF_RenderText_Shaded(font,text,*fg,*bg);
3219                                 TTF_SizeText(font,text,&w,&h);
3220                                 dest.w = w;
3221                                 dest.h = h;
3222                 }
3223                 if ( img && img->format && img->format->palette ) {
3224                         SDL_Color *c = &img->format->palette->colors[0];
3225                         Uint32 key = SDL_MapRGB( img->format, c->r, c->g, c->b );
3226                         SDL_SetColorKey(img,SDL_SRCCOLORKEY,key );
3227                         if (0 > SDL_BlitSurface(img,NULL,surface,&dest)) {
3228                                 SDL_FreeSurface(img);
3229                                 RETVAL = NULL;  
3230                         } else {
3231                                 RETVAL = img;
3232                         }
3233                 }
3234         OUTPUT:
3235                 RETVAL
3236
3237 #endif
3238
3239 SDL_Overlay*
3240 CreateYUVOverlay ( width, height, format, display )
3241         int width
3242         int height
3243         Uint32 format
3244         SDL_Surface *display
3245         CODE:
3246                 RETVAL = SDL_CreateYUVOverlay ( width, height, format, display );
3247         OUTPUT:
3248                 RETVAL
3249
3250 int
3251 LockYUVOverlay ( overlay )
3252         SDL_Overlay *overlay
3253         CODE:
3254                 RETVAL = SDL_LockYUVOverlay(overlay);
3255         OUTPUT:
3256                 RETVAL
3257
3258 void
3259 UnlockYUVOverlay ( overlay )
3260         SDL_Overlay *overlay
3261         CODE:
3262                 SDL_UnlockYUVOverlay(overlay);
3263
3264 int
3265 DisplayYUVOverlay ( overlay, dstrect )
3266         SDL_Overlay *overlay
3267         SDL_Rect *dstrect
3268         CODE:
3269                 RETVAL = SDL_DisplayYUVOverlay ( overlay, dstrect );
3270         OUTPUT:
3271                 RETVAL
3272
3273 void
3274 FreeYUVOverlay ( overlay )
3275         SDL_Overlay *overlay
3276         CODE:
3277                 SDL_FreeYUVOverlay ( overlay );
3278
3279 Uint32
3280 OverlayFormat ( overlay, ... )
3281         SDL_Overlay *overlay
3282         CODE:
3283                 if ( items > 1 ) 
3284                         overlay->format = SvIV(ST(1));
3285                 RETVAL = overlay->format;
3286         OUTPUT:
3287                 RETVAL
3288
3289 int 
3290 OverlayW ( overlay, ... )
3291         SDL_Overlay *overlay
3292         CODE:
3293                 if ( items > 1 ) 
3294                         overlay->w = SvIV(ST(1));
3295                 RETVAL = overlay->w;
3296         OUTPUT:
3297                 RETVAL
3298
3299 int
3300 OverlayH ( overlay, ... )
3301         SDL_Overlay *overlay
3302         CODE:
3303                 if ( items > 1 )
3304                         overlay->h = SvIV(ST(1));
3305                 RETVAL = overlay->h;
3306         OUTPUT:
3307                 RETVAL 
3308
3309 int
3310 OverlayPlanes ( overlay, ... )
3311         SDL_Overlay *overlay
3312         CODE:
3313                 if ( items > 1 )
3314                         overlay->planes = SvIV(ST(1));
3315                 RETVAL = overlay->planes;
3316         OUTPUT:
3317                 RETVAL
3318
3319 Uint32
3320 OverlayHW ( overlay )
3321         SDL_Overlay *overlay
3322         CODE:
3323                 RETVAL = overlay->hw_overlay;
3324         OUTPUT:
3325                 RETVAL
3326
3327 Uint16*
3328 OverlayPitches ( overlay )
3329         SDL_Overlay *overlay
3330         CODE:
3331                 RETVAL = overlay->pitches;
3332         OUTPUT:
3333                 RETVAL
3334
3335 Uint8**
3336 OverlayPixels ( overlay )
3337         SDL_Overlay *overlay
3338         CODE:
3339                 RETVAL = overlay->pixels;
3340         OUTPUT:
3341                 RETVAL
3342
3343 int
3344 WMToggleFullScreen ( surface )
3345         SDL_Surface *surface
3346         CODE:
3347                 RETVAL = SDL_WM_ToggleFullScreen(surface);
3348         OUTPUT:
3349                 RETVAL
3350
3351 Uint32
3352 WMGrabInput ( mode )
3353         Uint32 mode
3354         CODE:
3355                 RETVAL = SDL_WM_GrabInput(mode);
3356         OUTPUT:
3357                 RETVAL
3358
3359 int
3360 WMIconifyWindow ()
3361         CODE:
3362                 RETVAL = SDL_WM_IconifyWindow();
3363         OUTPUT:
3364                 RETVAL
3365
3366 int
3367 ResizeEventW ( e )
3368         SDL_Event *e
3369         CODE:
3370                 RETVAL = e->resize.w;
3371         OUTPUT:
3372                 RETVAL
3373
3374 int
3375 ResizeEventH ( e )
3376         SDL_Event *e
3377         CODE:
3378                 RETVAL = e->resize.h;
3379         OUTPUT:
3380                 RETVAL
3381
3382 char*
3383 AudioDriverName ()
3384         CODE:
3385                 char name[32];
3386                 RETVAL = SDL_AudioDriverName(name,32);
3387         OUTPUT:
3388                 RETVAL
3389
3390 Uint32
3391 GetKeyState ( k )
3392         SDLKey k
3393         CODE:
3394                 if (k >= SDLK_LAST) Perl_croak (aTHX_ "Key out of range");      
3395                 RETVAL = SDL_GetKeyState(NULL)[k];
3396         OUTPUT:
3397                 RETVAL
3398
3399 #ifdef HAVE_SMPEG
3400
3401 SMPEG_Info *
3402 NewSMPEGInfo()
3403         CODE:   
3404                 RETVAL = (SMPEG_Info *) safemalloc (sizeof(SMPEG_Info));
3405         OUTPUT:
3406                 RETVAL
3407
3408 void
3409 FreeSMPEGInfo ( info )
3410         SMPEG_Info *info
3411         CODE:   
3412                 safefree(info);
3413
3414 int
3415 SMPEGInfoHasAudio ( info )
3416         SMPEG_Info* info
3417         CODE:
3418                 RETVAL = info->has_audio;
3419         OUTPUT:
3420                 RETVAL
3421
3422 int
3423 SMPEGInfoHasVideo ( info )
3424         SMPEG_Info* info
3425         CODE:
3426                 RETVAL = info->has_video;
3427         OUTPUT:
3428                 RETVAL
3429
3430 int
3431 SMPEGInfoWidth ( info )
3432         SMPEG_Info* info
3433         CODE:
3434                 RETVAL = info->width;
3435         OUTPUT:
3436                 RETVAL
3437
3438 int
3439 SMPEGInfoHeight ( info )
3440         SMPEG_Info* info
3441         CODE:
3442                 RETVAL = info->height;
3443         OUTPUT:
3444                 RETVAL
3445
3446 int
3447 SMPEGInfoCurrentFrame ( info )
3448         SMPEG_Info* info
3449         CODE:
3450                 RETVAL = info->current_frame;
3451         OUTPUT:
3452                 RETVAL
3453
3454 double
3455 SMPEGInfoCurrentFPS ( info )
3456         SMPEG_Info* info
3457         CODE:
3458                 RETVAL = info->current_fps;
3459         OUTPUT:
3460                 RETVAL
3461
3462 int
3463 SMPEGInfoCurrentAudioFrame ( info )
3464         SMPEG_Info* info
3465         CODE:
3466                 RETVAL = info->audio_current_frame;
3467         OUTPUT:
3468                 RETVAL
3469
3470 int
3471 SMPEGInfoCurrentOffset ( info )
3472         SMPEG_Info* info
3473         CODE:
3474                 RETVAL = info->current_offset;
3475         OUTPUT:
3476                 RETVAL
3477
3478 int
3479 SMPEGInfoTotalSize ( info )
3480         SMPEG_Info* info
3481         CODE:
3482                 RETVAL = info->total_size;
3483         OUTPUT:
3484                 RETVAL
3485
3486 double
3487 SMPEGInfoCurrentTime ( info )
3488         SMPEG_Info* info
3489         CODE:
3490                 RETVAL = info->current_time;
3491         OUTPUT:
3492                 RETVAL
3493
3494 double
3495 SMPEGInfoTotalTime ( info )
3496         SMPEG_Info* info
3497         CODE:
3498                 RETVAL = info->total_time;
3499         OUTPUT:
3500                 RETVAL
3501
3502 char *
3503 SMPEGError ( mpeg )
3504         SMPEG* mpeg
3505         CODE:   
3506                 RETVAL = SMPEG_error(mpeg);
3507         OUTPUT:
3508                 RETVAL
3509
3510 SMPEG*
3511 NewSMPEG ( filename, info, use_audio )
3512         char* filename
3513         SMPEG_Info* info
3514         int use_audio
3515         CODE:   
3516 #ifdef HAVE_SDL_MIXER
3517                 RETVAL = SMPEG_new(filename,info,0);
3518 #else
3519                 RETVAL = SMPEG_new(filename,info,use_audio);
3520 #endif
3521         OUTPUT:
3522                 RETVAL
3523
3524 void
3525 FreeSMPEG ( mpeg )
3526         SMPEG* mpeg
3527         CODE:
3528                 SMPEG_delete(mpeg);
3529
3530 void
3531 SMPEGEnableAudio ( mpeg , flag )
3532         SMPEG* mpeg
3533         int flag
3534         CODE:   
3535                 SMPEG_enableaudio(mpeg,flag);
3536 #ifdef HAVE_SDL_MIXER
3537                 sdl_perl_use_smpeg_audio = flag;
3538 #endif
3539
3540 void
3541 SMPEGEnableVideo ( mpeg , flag )
3542         SMPEG* mpeg
3543         int flag
3544         CODE:   
3545                 SMPEG_enablevideo(mpeg,flag);
3546
3547 void
3548 SMPEGSetVolume ( mpeg , volume )
3549         SMPEG* mpeg
3550         int volume
3551         CODE:   
3552                 SMPEG_setvolume(mpeg,volume);
3553
3554 void
3555 SMPEGSetDisplay ( mpeg, dest, surfLock )
3556         SMPEG* mpeg
3557         SDL_Surface* dest
3558         SDL_mutex*  surfLock
3559         CODE:
3560                 SMPEG_setdisplay(mpeg,dest,surfLock,NULL);
3561
3562 void
3563 SMPEGScaleXY ( mpeg, w, h)
3564         SMPEG* mpeg
3565         int w
3566         int h
3567         CODE:
3568                 SMPEG_scaleXY(mpeg,w,h);
3569
3570 void
3571 SMPEGScale ( mpeg, scale )
3572         SMPEG* mpeg
3573         int scale
3574         CODE:
3575                 SMPEG_scale(mpeg,scale);
3576
3577 void
3578 SMPEGPlay ( mpeg )
3579         SMPEG* mpeg
3580         CODE:
3581                 SDL_AudioSpec audiofmt;
3582                 Uint16 format;
3583                 int freq, channels;
3584 #ifdef HAVE_SDL_MIXER
3585                 if  (sdl_perl_use_smpeg_audio ) {
3586                         SMPEG_enableaudio(mpeg, 0);
3587                         Mix_QuerySpec(&freq, &format, &channels);
3588                         audiofmt.format = format;
3589                         audiofmt.freq = freq;
3590                         audiofmt.channels = channels;
3591                         SMPEG_actualSpec(mpeg, &audiofmt);
3592                         Mix_HookMusic(SMPEG_playAudioSDL, mpeg);
3593                         SMPEG_enableaudio(mpeg, 1);
3594                 }
3595 #endif
3596                 SMPEG_play(mpeg);
3597
3598 SMPEGstatus
3599 SMPEGStatus ( mpeg )
3600         SMPEG* mpeg
3601         CODE:
3602                 RETVAL = SMPEG_status(mpeg);
3603         OUTPUT:
3604                 RETVAL
3605
3606 void
3607 SMPEGPause ( mpeg )
3608         SMPEG* mpeg
3609         CODE:
3610                 SMPEG_pause(mpeg);
3611
3612 void
3613 SMPEGLoop ( mpeg, repeat )
3614         SMPEG* mpeg
3615         int repeat
3616         CODE:
3617                 SMPEG_loop(mpeg,repeat);
3618
3619 void
3620 SMPEGStop ( mpeg )
3621         SMPEG* mpeg
3622         CODE:
3623                 SMPEG_stop(mpeg);
3624 #ifdef HAVE_SDL_MIXER
3625                 Mix_HookMusic(NULL, NULL);
3626 #endif
3627
3628 void
3629 SMPEGRewind ( mpeg )
3630         SMPEG* mpeg
3631         CODE:
3632                 SMPEG_rewind(mpeg);
3633
3634 void
3635 SMPEGSeek ( mpeg, bytes )
3636         SMPEG* mpeg
3637         int bytes
3638         CODE:
3639                 SMPEG_seek(mpeg,bytes);
3640
3641 void
3642 SMPEGSkip ( mpeg, seconds )
3643         SMPEG* mpeg
3644         float seconds
3645         CODE:
3646                 SMPEG_skip(mpeg,seconds);
3647
3648 void
3649 SMPEGSetDisplayRegion ( mpeg, rect )
3650         SMPEG* mpeg
3651         SDL_Rect* rect
3652         CODE:
3653                 SMPEG_setdisplayregion(mpeg,rect->x,rect->y,rect->w,rect->h);
3654
3655 void
3656 SMPEGRenderFrame ( mpeg, frame )
3657         SMPEG* mpeg
3658         int frame
3659         CODE:
3660                 SMPEG_renderFrame(mpeg,frame);
3661
3662 SMPEG_Info *
3663 SMPEGGetInfo ( mpeg )
3664         SMPEG* mpeg
3665         CODE:
3666                 RETVAL = (SMPEG_Info *) safemalloc (sizeof(SMPEG_Info));
3667                 SMPEG_getinfo(mpeg,RETVAL);
3668         OUTPUT:
3669                 RETVAL
3670         
3671
3672 #endif
3673
3674 #ifdef HAVE_SDL_GFX
3675
3676 SDL_Surface *
3677 GFXRotoZoom ( src, angle, zoom, smooth)
3678         SDL_Surface * src
3679         double angle
3680         double zoom
3681         int smooth
3682         CODE:
3683                 RETVAL = rotozoomSurface( src, angle, zoom, smooth);
3684         OUTPUT:
3685                 RETVAL
3686
3687 SDL_Surface *
3688 GFXZoom ( src, zoomx, zoomy, smooth)
3689         SDL_Surface *src
3690         double zoomx
3691         double zoomy
3692         int smooth
3693         CODE:
3694                 RETVAL = zoomSurface( src, zoomx, zoomy, smooth);
3695         OUTPUT:
3696                 RETVAL
3697
3698 int
3699 GFXPixelColor ( dst, x, y, color )
3700         SDL_Surface* dst
3701         Sint16 x
3702         Sint16 y
3703         Uint32 color
3704         CODE:
3705                 RETVAL = pixelColor( dst, x, y, color);
3706         OUTPUT:
3707                 RETVAL
3708
3709 int
3710 GFXPixelRGBA ( dst, x, y, r, g, b, a )
3711         SDL_Surface* dst
3712         Sint16 x
3713         Sint16 y
3714         Uint8 r
3715         Uint8 g
3716         Uint8 b
3717         Uint8 a
3718         CODE:
3719                 RETVAL = pixelRGBA( dst, x, y, r, g, b, a );
3720         OUTPUT:
3721                 RETVAL
3722
3723 int
3724 GFXHlineColor ( dst, x1, x2, y, color )
3725         SDL_Surface* dst
3726         Sint16 x1
3727         Sint16 x2
3728         Sint16 y
3729         Uint32 color
3730         CODE:
3731                 RETVAL = hlineColor( dst, x1, x2, y, color );
3732         OUTPUT:
3733                 RETVAL
3734
3735 int
3736 GFXHlineRGBA ( dst, x1, x2, y, r, g, b, a )
3737         SDL_Surface* dst
3738         Sint16 x1
3739         Sint16 x2
3740         Sint16 y
3741         Uint8 r
3742         Uint8 g
3743         Uint8 b
3744         Uint8 a
3745         CODE:
3746                 RETVAL = hlineRGBA( dst, x1, x2, y, r, g, b, a );
3747         OUTPUT:
3748                 RETVAL
3749
3750 int
3751 GFXVlineColor ( dst, x, y1, y2, color )
3752         SDL_Surface* dst
3753         Sint16 x
3754         Sint16 y1
3755         Sint16 y2
3756         Uint32 color
3757         CODE:
3758                 RETVAL = vlineColor( dst, x, y1, y2, color );
3759         OUTPUT:
3760                 RETVAL
3761
3762 int
3763 GFXVlineRGBA ( dst, x, y1, y2, r, g, b, a )
3764         SDL_Surface* dst
3765         Sint16 x
3766         Sint16 y1
3767         Sint16 y2
3768         Uint8 r
3769         Uint8 g
3770         Uint8 b
3771         Uint8 a
3772         CODE:
3773                 RETVAL = vlineRGBA( dst, x, y1, y2, r, g, b, a );
3774         OUTPUT:
3775                 RETVAL
3776
3777 int
3778 GFXRectangleColor ( dst, x1, y1, x2, y2, color )
3779         SDL_Surface* dst
3780         Sint16 x1
3781         Sint16 y1
3782         Sint16 x2
3783         Sint16 y2
3784         Uint32 color
3785         CODE:
3786                 RETVAL = rectangleColor( dst, x1, y1, x2, y2, color );
3787         OUTPUT:
3788                 RETVAL
3789
3790 int
3791 GFXRectangleRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3792         SDL_Surface* dst
3793         Sint16 x1
3794         Sint16 y1
3795         Sint16 x2
3796         Sint16 y2
3797         Uint8 r
3798         Uint8 g
3799         Uint8 b
3800         Uint8 a
3801         CODE:
3802                 RETVAL = rectangleRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3803         OUTPUT:
3804                 RETVAL
3805
3806 int
3807 GFXBoxColor ( dst, x1, y1, x2, y2, color )
3808         SDL_Surface* dst
3809         Sint16 x1
3810         Sint16 y1
3811         Sint16 x2
3812         Sint16 y2
3813         Uint32 color
3814         CODE:
3815                 RETVAL = boxColor( dst, x1, y1, x2, y2, color );
3816         OUTPUT:
3817                 RETVAL
3818
3819 int
3820 GFXBoxRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3821         SDL_Surface* dst;
3822         Sint16 x1
3823         Sint16 y1
3824         Sint16 x2
3825         Sint16 y2
3826         Uint8 r
3827         Uint8 g
3828         Uint8 b
3829         Uint8 a
3830         CODE:
3831                 RETVAL = boxRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3832         OUTPUT:
3833                 RETVAL
3834
3835 int
3836 GFXLineColor ( dst, x1, y1, x2, y2, color )
3837         SDL_Surface* dst
3838         Sint16 x1
3839         Sint16 y1
3840         Sint16 x2
3841         Sint16 y2
3842         Uint32 color
3843         CODE:
3844                 RETVAL = lineColor( dst, x1, y1, x2, y2, color );
3845         OUTPUT:
3846                 RETVAL
3847
3848 int
3849 GFXLineRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3850         SDL_Surface* dst
3851         Sint16 x1
3852         Sint16 y1
3853         Sint16 x2
3854         Sint16 y2
3855         Uint8 r
3856         Uint8 g
3857         Uint8 b
3858         Uint8 a
3859         CODE:
3860                 RETVAL = lineRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3861         OUTPUT:
3862                 RETVAL
3863
3864 int
3865 GFXAalineColor ( dst, x1, y1, x2, y2, color )
3866         SDL_Surface* dst
3867         Sint16 x1
3868         Sint16 y1
3869         Sint16 x2
3870         Sint16 y2
3871         Uint32 color
3872         CODE:
3873                 RETVAL = aalineColor( dst, x1, y1, x2, y2, color );
3874         OUTPUT:
3875                 RETVAL
3876
3877 int
3878 GFXAalineRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3879         SDL_Surface* dst
3880         Sint16 x1
3881         Sint16 y1
3882         Sint16 x2
3883         Sint16 y2
3884         Uint8 r
3885         Uint8 g
3886         Uint8 b
3887         Uint8 a
3888         CODE:
3889                 RETVAL = aalineRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3890         OUTPUT:
3891                 RETVAL
3892
3893 int
3894 GFXCircleColor ( dst, x, y, r, color )
3895         SDL_Surface* dst
3896         Sint16 x
3897         Sint16 y
3898         Sint16 r
3899         Uint32 color
3900         CODE:
3901                 RETVAL = circleColor( dst, x, y, r, color );
3902         OUTPUT:
3903                 RETVAL
3904
3905 int
3906 GFXCircleRGBA ( dst, x, y, rad, r, g, b, a )
3907         SDL_Surface* dst
3908         Sint16 x
3909         Sint16 y
3910         Sint16 rad
3911         Uint8 r
3912         Uint8 g
3913         Uint8 b
3914         Uint8 a
3915         CODE:
3916                 RETVAL = circleRGBA( dst, x, y, rad, r, g, b, a );
3917         OUTPUT:
3918                 RETVAL
3919
3920 int
3921 GFXAacircleColor ( dst, x, y, r, color )
3922         SDL_Surface* dst
3923         Sint16 x
3924         Sint16 y
3925         Sint16 r
3926         Uint32 color
3927         CODE:
3928                 RETVAL = aacircleColor( dst, x, y, r, color );
3929         OUTPUT:
3930                 RETVAL
3931
3932 int
3933 GFXAacircleRGBA ( dst, x, y, rad, r, g, b, a )
3934         SDL_Surface* dst
3935         Sint16 x
3936         Sint16 y
3937         Sint16 rad
3938         Uint8 r
3939         Uint8 g
3940         Uint8 b
3941         Uint8 a
3942         CODE:
3943                 RETVAL = aacircleRGBA( dst, x, y, rad, r, g, b, a );
3944         OUTPUT:
3945                 RETVAL
3946
3947 int
3948 GFXFilledCircleColor ( dst, x, y, r, color )
3949         SDL_Surface* dst
3950         Sint16 x
3951         Sint16 y
3952         Sint16 r
3953         Uint32 color
3954         CODE:
3955                 RETVAL = filledCircleColor( dst, x, y, r, color );
3956         OUTPUT:
3957                 RETVAL
3958
3959 int
3960 GFXFilledCircleRGBA ( dst, x, y, rad, r, g, b, a )
3961         SDL_Surface* dst
3962         Sint16 x
3963         Sint16 y
3964         Sint16 rad
3965         Uint8 r
3966         Uint8 g
3967         Uint8 b
3968         Uint8 a
3969         CODE:
3970                 RETVAL = filledCircleRGBA( dst, x, y, rad, r, g, b, a );
3971         OUTPUT:
3972                 RETVAL
3973
3974 int
3975 GFXEllipseColor ( dst, x, y, rx, ry, color )
3976         SDL_Surface* dst
3977         Sint16 x
3978         Sint16 y
3979         Sint16 rx
3980         Sint16 ry
3981         Uint32 color
3982         CODE:
3983                 RETVAL = ellipseColor( dst, x, y, rx, ry, color );
3984         OUTPUT:
3985                 RETVAL
3986
3987 int
3988 GFXEllipseRGBA ( dst, x, y, rx, ry, r, g, b, a )
3989         SDL_Surface* dst
3990         Sint16 x
3991         Sint16 y
3992         Sint16  rx
3993         Sint16 ry
3994         Uint8 r
3995         Uint8 g
3996         Uint8 b
3997         Uint8 a
3998         CODE:
3999                 RETVAL = ellipseRGBA( dst, x, y, rx, ry, r, g, b, a );
4000         OUTPUT:
4001                 RETVAL
4002
4003 int
4004 GFXAaellipseColor ( dst, xc, yc, rx, ry, color )
4005         SDL_Surface* dst
4006         Sint16 xc
4007         Sint16 yc
4008         Sint16 rx
4009         Sint16 ry
4010         Uint32 color
4011         CODE:
4012                 RETVAL = aaellipseColor( dst, xc, yc, rx, ry, color );
4013         OUTPUT:
4014                 RETVAL
4015
4016 int
4017 GFXAaellipseRGBA ( dst, x, y, rx, ry, r, g, b, a )
4018         SDL_Surface* dst
4019         Sint16 x
4020         Sint16 y
4021         Sint16 rx
4022         Sint16 ry
4023         Uint8 r
4024         Uint8 g
4025         Uint8 b
4026         Uint8 a
4027         CODE:
4028                 RETVAL = aaellipseRGBA( dst, x, y, rx, ry, r, g, b, a );
4029         OUTPUT:
4030                 RETVAL
4031
4032 int
4033 GFXFilledEllipseColor ( dst, x, y, rx, ry, color )
4034         SDL_Surface* dst
4035         Sint16 x
4036         Sint16 y
4037         Sint16 rx
4038         Sint16 ry
4039         Uint32 color
4040         CODE:
4041                 RETVAL = filledEllipseColor( dst, x, y, rx, ry, color );
4042         OUTPUT:
4043                 RETVAL
4044
4045 int
4046 GFXFilledEllipseRGBA ( dst, x, y, rx, ry, r, g, b, a )
4047         SDL_Surface* dst
4048         Sint16 x
4049         Sint16 y
4050         Sint16 rx
4051         Sint16 ry
4052         Uint8 r
4053         Uint8 g
4054         Uint8 b
4055         Uint8 a
4056         CODE:
4057                 RETVAL = filledEllipseRGBA( dst, x, y, rx, ry, r, g, b, a );
4058         OUTPUT:
4059                 RETVAL
4060
4061 int
4062 GFXFilledPieColor ( dst, x, y, rad, start, end, color )
4063         SDL_Surface* dst
4064         Sint16 x
4065         Sint16 y
4066         Sint16 rad
4067         Sint16 start
4068         Sint16 end
4069         Uint32 color
4070         CODE:
4071                 RETVAL = filledPieColor( dst, x, y, rad, start, end, color );
4072         OUTPUT:
4073                 RETVAL
4074
4075 int
4076 GFXFilledPieRGBA ( dst, x, y, rad, start, end, r, g, b, a )
4077         SDL_Surface* dst
4078         Sint16 x
4079         Sint16 y
4080         Sint16 rad
4081         Sint16 start
4082         Sint16 end
4083         Uint8 r
4084         Uint8 g
4085         Uint8 b
4086         Uint8 a
4087         CODE:
4088                 RETVAL = filledPieRGBA( dst, x, y, rad, start, end, r, g, b, a );
4089         OUTPUT:
4090                 RETVAL
4091
4092 int
4093 GFXPolygonColor ( dst, vx, vy, n, color )
4094         SDL_Surface* dst
4095         Sint16* vx
4096         Sint16* vy
4097         int n
4098         Uint32 color;
4099         CODE:
4100                 RETVAL = polygonColor( dst, vx, vy, n, color );
4101         OUTPUT:
4102                 RETVAL
4103
4104 int
4105 GFXPolygonRGBA ( dst, vx, vy, n, r, g, b, a )
4106         SDL_Surface* dst
4107         Sint16* vx
4108         Sint16* vy
4109         int n
4110         Uint8 r
4111         Uint8 g
4112         Uint8 b
4113         Uint8 a
4114         CODE:
4115                 RETVAL = polygonRGBA( dst, vx, vy, n, r, g, b, a );
4116         OUTPUT:
4117                 RETVAL
4118
4119 int
4120 GFXAapolygonColor ( dst, vx, vy, n, color )
4121         SDL_Surface* dst
4122         Sint16* vx
4123         Sint16* vy
4124         int n
4125         Uint32 color
4126         CODE:
4127                 RETVAL = aapolygonColor( dst, vx, vy, n, color );
4128         OUTPUT:
4129                 RETVAL
4130
4131 int
4132 GFXAapolygonRGBA ( dst, vx, vy, n, r, g, b, a )
4133         SDL_Surface* dst
4134         Sint16* vx
4135         Sint16* vy
4136         int n
4137         Uint8 r
4138         Uint8 g
4139         Uint8 b
4140         Uint8 a
4141         CODE:
4142                 RETVAL = aapolygonRGBA( dst, vx, vy, n, r, g, b, a );
4143         OUTPUT:
4144                 RETVAL
4145
4146 int
4147 GFXFilledPolygonColor ( dst, vx, vy, n, color )
4148         SDL_Surface* dst
4149         Sint16* vx
4150         Sint16* vy
4151         int n
4152         int color
4153         CODE:
4154                 RETVAL = filledPolygonColor( dst, vx, vy, n, color );
4155         OUTPUT:
4156                 RETVAL
4157
4158 int
4159 GFXFilledPolygonRGBA ( dst, vx, vy, n, r, g, b, a )
4160         SDL_Surface* dst
4161         Sint16* vx
4162         Sint16* vy
4163         int n
4164         Uint8 r
4165         Uint8 g
4166         Uint8 b
4167         Uint8 a
4168         CODE:
4169                 RETVAL = filledPolygonRGBA( dst, vx, vy, n, r, g, b, a );
4170         OUTPUT:
4171                 RETVAL
4172
4173 int
4174 GFXCharacterColor ( dst, x, y, c, color )
4175         SDL_Surface* dst
4176         Sint16 x
4177         Sint16 y
4178         char c
4179         Uint32 color
4180         CODE:
4181                 RETVAL = characterColor( dst, x, y, c, color );
4182         OUTPUT:
4183                 RETVAL
4184
4185 int
4186 GFXCharacterRGBA ( dst, x, y, c, r, g, b, a )
4187         SDL_Surface* dst
4188         Sint16 x
4189         Sint16 y
4190         char c
4191         Uint8 r
4192         Uint8 g
4193         Uint8 b
4194         Uint8 a
4195         CODE:
4196                 RETVAL = characterRGBA( dst, x, y, c, r, g, b, a );
4197         OUTPUT:
4198                 RETVAL
4199
4200 int
4201 GFXStringColor ( dst, x, y, c, color )
4202         SDL_Surface* dst
4203         Sint16 x
4204         Sint16 y
4205         char* c
4206         Uint32 color
4207         CODE:
4208                 RETVAL = stringColor( dst, x, y, c, color );
4209         OUTPUT:
4210                 RETVAL
4211
4212 int
4213 GFXStringRGBA ( dst, x, y, c, r, g, b, a )
4214         SDL_Surface* dst
4215         Sint16 x
4216         Sint16 y
4217         char* c
4218         Uint8 r
4219         Uint8 g
4220         Uint8 b
4221         Uint8 a
4222         CODE:
4223                 RETVAL = stringRGBA( dst, x, y, c, r, g, b, a );
4224         OUTPUT:
4225                 RETVAL
4226
4227 #endif
4228
4229
4230 #ifdef HAVE_SDL_SVG
4231
4232 SDL_svg_context *
4233 SVG_Load ( filename )
4234         char* filename
4235         CODE:
4236                 RETVAL = SVG_Load(filename);
4237         OUTPUT:
4238                 RETVAL
4239
4240 SDL_svg_context *
4241 SVG_LoadBuffer ( data, len )
4242         char* data
4243         int len
4244         CODE:
4245                 RETVAL = SVG_LoadBuffer(data,len);
4246         OUTPUT:
4247                 RETVAL
4248
4249 int
4250 SVG_SetOffset ( source, xoff, yoff )
4251         SDL_svg_context* source
4252         double xoff
4253         double yoff
4254         CODE:
4255                 RETVAL = SVG_SetOffset(source,xoff,yoff);
4256         OUTPUT:
4257                 RETVAL
4258
4259 int
4260 SVG_SetScale ( source, xscale, yscale )
4261         SDL_svg_context* source
4262         double xscale
4263         double yscale
4264         CODE:
4265                 RETVAL = SVG_SetScale(source,xscale,yscale);
4266         OUTPUT:
4267                 RETVAL
4268
4269 int
4270 SVG_RenderToSurface ( source, x, y, dest )
4271         SDL_svg_context* source
4272         int x
4273         int y
4274         SDL_Surface* dest;
4275         CODE:
4276                 RETVAL = SVG_RenderToSurface(source,x,y,dest);
4277         OUTPUT:
4278                 RETVAL
4279
4280 void
4281 SVG_Free ( source )
4282         SDL_svg_context* source
4283         CODE:
4284                 SVG_Free(source);       
4285
4286 void
4287 SVG_Set_Flags ( source, flags )
4288         SDL_svg_context* source
4289         Uint32 flags
4290         CODE:
4291                 SVG_Set_Flags(source,flags);
4292
4293 float
4294 SVG_Width ( source )
4295         SDL_svg_context* source
4296         CODE:
4297                 RETVAL = SVG_Width(source);
4298         OUTPUT:
4299                 RETVAL
4300
4301 float
4302 SVG_HEIGHT ( source )
4303         SDL_svg_context* source
4304         CODE:
4305                 RETVAL = SVG_Height(source);
4306         OUTPUT:
4307                 RETVAL
4308
4309 void
4310 SVG_SetClipping ( source, minx, miny, maxx, maxy )
4311         SDL_svg_context* source
4312         int minx
4313         int miny
4314         int maxx
4315         int maxy
4316         CODE:
4317                 SVG_SetClipping(source,minx,miny,maxx,maxy);
4318
4319 int
4320 SVG_Version ( )
4321         CODE:
4322                 RETVAL = SVG_Version();
4323         OUTPUT:
4324                 RETVAL
4325
4326
4327 #endif
4328
4329 #ifdef HAVE_SDL_SOUND
4330
4331 Uint16
4332 SoundAudioInfoFormat ( audioinfo )
4333         Sound_AudioInfo* audioinfo
4334         CODE:
4335                 RETVAL = audioinfo->format;
4336         OUTPUT:
4337                 RETVAL
4338
4339 Uint8
4340 SoundAudioInfoChannels ( audioinfo )
4341         Sound_AudioInfo* audioinfo
4342         CODE:
4343                 RETVAL = audioinfo->channels;
4344         OUTPUT:
4345                 RETVAL
4346
4347 Uint32
4348 SoundAudioInforate ( audioinfo )
4349         Sound_AudioInfo* audioinfo
4350         CODE:
4351                 RETVAL = audioinfo->rate;
4352         OUTPUT:
4353                 RETVAL
4354
4355 AV*
4356 SoundDecoderInfoExtensions ( decoderinfo )
4357         Sound_DecoderInfo* decoderinfo
4358         CODE:
4359                 const char **ext;
4360                 for ( ext = decoderinfo->extensions; *ext != NULL; ext++ ){
4361                         av_push(RETVAL,newSVpv(*ext,0));
4362                 }
4363         OUTPUT:
4364                 RETVAL
4365
4366 const char*
4367 SoundDecoderInfoDescription ( decoderinfo )
4368         Sound_DecoderInfo* decoderinfo
4369         CODE:
4370                 RETVAL = decoderinfo->description;
4371         OUTPUT:
4372                 RETVAL
4373
4374 const char*
4375 SoundDecoderInfoAuthor ( decoderinfo )
4376         Sound_DecoderInfo* decoderinfo
4377         CODE:
4378                 RETVAL = decoderinfo->author;
4379         OUTPUT:
4380                 RETVAL
4381
4382 const char*
4383 SoundDecoderInfoUrl ( decoderinfo )
4384         Sound_DecoderInfo* decoderinfo
4385         CODE:
4386                 RETVAL = decoderinfo->url;
4387         OUTPUT:
4388                 RETVAL
4389
4390 const Sound_DecoderInfo*
4391 SoundSampleDecoder ( sample ) 
4392         Sound_Sample* sample
4393         CODE:
4394                 RETVAL = sample->decoder;
4395         OUTPUT:
4396                 RETVAL
4397
4398 Sound_AudioInfo* 
4399 SoundSampleDesired ( sample )
4400         Sound_Sample* sample
4401         CODE:
4402                 RETVAL = &sample->desired;
4403         OUTPUT:
4404                 RETVAL
4405
4406 Sound_AudioInfo*
4407 SoundSampleAcutal ( sample )
4408         Sound_Sample* sample
4409         CODE:
4410                 RETVAL = &sample->actual;
4411         OUTPUT:
4412                 RETVAL
4413
4414 char*
4415 SoundSampleBuffer ( sample )
4416         Sound_Sample* sample
4417         CODE:
4418                 RETVAL = sample->buffer;
4419         OUTPUT:
4420                 RETVAL
4421
4422 Uint32
4423 SoundSampleBufferSize ( sample )
4424         Sound_Sample* sample
4425         CODE:
4426                 RETVAL = sample->buffer_size;
4427         OUTPUT:
4428                 RETVAL
4429
4430 Uint32
4431 SoundSampleFlags ( sample )
4432         Sound_Sample* sample
4433         CODE:
4434                 RETVAL = (Uint32)sample->flags;
4435         OUTPUT:
4436                 RETVAL
4437
4438 int
4439 Sound_Init ( )
4440         CODE:
4441                 RETVAL = Sound_Init();
4442         OUTPUT:
4443                 RETVAL
4444
4445 int
4446 Sound_Quit ( )
4447         CODE:
4448                 RETVAL = Sound_Quit();
4449         OUTPUT:
4450                 RETVAL
4451
4452 AV*
4453 Sound_AvailableDecoders ( )
4454         CODE:
4455                 RETVAL = newAV();
4456                 const Sound_DecoderInfo** sdi;
4457                 sdi = Sound_AvailableDecoders();
4458                 if (sdi != NULL)  {
4459                         for (;*sdi != NULL; ++sdi) {
4460                                 av_push(RETVAL,sv_2mortal(newSViv(PTR2IV(*sdi))));
4461                         }
4462                 }
4463         OUTPUT:
4464                 RETVAL
4465
4466 const char*
4467 Sound_GetError ( )
4468         CODE:
4469                 RETVAL = Sound_GetError();
4470         OUTPUT:
4471                 RETVAL
4472
4473 void
4474 Sound_ClearError ( )
4475         CODE:
4476                 Sound_ClearError();
4477
4478 Sound_Sample*
4479 Sound_NewSample ( rw, ext, desired, buffsize )
4480         SDL_RWops* rw
4481         const char* ext
4482         Sound_AudioInfo* desired
4483         Uint32 buffsize
4484         CODE:
4485                 RETVAL = Sound_NewSample(rw,ext,desired,buffsize);
4486         OUTPUT:
4487                 RETVAL
4488
4489 Sound_Sample*
4490 Sound_NewSampleFromMem ( data, size, ext, desired, buffsize )
4491         const Uint8 *data
4492         Uint32 size
4493         const char* ext
4494         Sound_AudioInfo* desired
4495         Uint32 buffsize
4496         CODE:
4497                 RETVAL = Sound_NewSampleFromMem(data,size,ext,desired,buffsize);
4498         OUTPUT:
4499                 RETVAL
4500
4501 Sound_Sample*
4502 Sound_NewSampleFromFile ( fname, desired, buffsize )
4503         const char* fname
4504         Sound_AudioInfo* desired
4505         Uint32 buffsize
4506         CODE:
4507                 RETVAL = Sound_NewSampleFromFile(fname,desired,buffsize);
4508         OUTPUT:
4509                 RETVAL
4510
4511 void
4512 Sound_FreeSample ( sample )
4513         Sound_Sample* sample
4514         CODE:
4515                 Sound_FreeSample(sample);
4516
4517 Sint32
4518 Sound_GetDuration ( sample )
4519         Sound_Sample* sample
4520         CODE:
4521                 RETVAL = Sound_GetDuration(sample);
4522         OUTPUT:
4523                 RETVAL
4524
4525 int
4526 Sound_SetBufferSize ( sample, size )
4527         Sound_Sample* sample
4528         Uint32 size
4529         CODE:
4530                 RETVAL = Sound_SetBufferSize(sample,size);
4531         OUTPUT:
4532                 RETVAL
4533
4534 Uint32
4535 Sound_Decode ( sample )
4536         Sound_Sample* sample
4537         CODE:
4538                 RETVAL = Sound_Decode(sample);
4539         OUTPUT:
4540                 RETVAL
4541
4542 Uint32
4543 Sound_DecodeAll ( sample ) 
4544         Sound_Sample* sample
4545         CODE:
4546                 RETVAL = Sound_DecodeAll(sample);
4547         OUTPUT:
4548                 RETVAL
4549
4550 int
4551 Sound_Rewind ( sample )
4552         Sound_Sample* sample
4553         CODE:
4554                 RETVAL = Sound_Rewind(sample);
4555         OUTPUT:
4556                 RETVAL
4557
4558 int
4559 Sound_Seek ( sample, ms )
4560         Sound_Sample* sample
4561         Uint32 ms
4562         CODE:
4563                 RETVAL = Sound_Seek(sample,ms);
4564         OUTPUT:
4565                 RETVAL
4566
4567 #endif
4568
4569 MODULE = SDL            PACKAGE = SDL
4570 PROTOTYPES : DISABLE
4571
4572