Windows super hack
[sdlgit/SDL_perl.git] / src / SDL.xs
1 //
2 // SDL.xs
3 //
4 // Copyright (C) 2005 David J. Goehrig <dgoehrig@cpan.org>
5 //
6 // ------------------------------------------------------------------------------
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // 
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // Lesser General Public License for more details.
17 // 
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21 //
22 // ------------------------------------------------------------------------------
23 //
24 // Please feel free to send questions, suggestions or improvements to:
25 //
26 //      David J. Goehrig
27 //      dgoehrig@cpan.org
28 //
29
30 #include "EXTERN.h"
31 #include "perl.h"
32 #include "XSUB.h"
33
34 #ifndef aTHX_
35 #define aTHX_
36 #endif
37
38 #include <SDL.h>
39
40 #ifdef HAVE_GL
41 #include <gl.h>
42 #endif
43
44 #ifdef HAVE_GLU
45 #include <glu.h>
46 #endif
47
48 #ifdef HAVE_SDL_IMAGE
49 #include <SDL_image.h>
50 #endif 
51
52 #ifdef HAVE_SDL_MIXER
53 #include <SDL_mixer.h>
54 void (*mix_music_finished_cv)();
55 #endif
56
57 #ifdef HAVE_SDL_SOUND
58 #include <SDL_sound.h>
59 #endif
60
61 #ifdef HAVE_SDL_NET
62 #include <SDL_net.h>
63 #endif
64
65 #ifdef HAVE_SDL_TTF
66 #include <SDL_ttf.h>
67 #define TEXT_SOLID      1
68 #define TEXT_SHADED     2
69 #define TEXT_BLENDED    4
70 #define UTF8_SOLID      8
71 #define UTF8_SHADED     16      
72 #define UTF8_BLENDED    32
73 #define UNICODE_SOLID   64
74 #define UNICODE_SHADED  128
75 #define UNICODE_BLENDED 256
76 #endif
77
78 #ifdef HAVE_SMPEG
79 #include <smpeg/smpeg.h>
80 #ifdef HAVE_SDL_MIXER
81 static int sdl_perl_use_smpeg_audio = 0;
82 #endif
83 #endif
84
85 #ifdef HAVE_SDL_GFX
86 #include <SDL_rotozoom.h>
87 #include <SDL_gfxPrimitives.h>
88 #include <SDL_framerate.h>
89 #include <SDL_imageFilter.h>
90 #endif
91
92 #ifdef HAVE_SDL_SVG
93 #include <SDL_svg.h>
94 #endif
95
96 #ifdef USE_THREADS
97 #define HAVE_TLS_CONTEXT
98 #endif
99
100 /* For windows  */
101 #ifndef SDL_PERL_DEFINES_H
102 #define SDL_PERL_DEFINES_H
103
104 #ifdef HAVE_TLS_CONTEXT
105 PerlInterpreter *parent_perl = NULL;
106 extern PerlInterpreter *parent_perl;
107 #define GET_TLS_CONTEXT parent_perl =  PERL_GET_CONTEXT;
108 #define ENTER_TLS_CONTEXT \
109         PerlInterpreter *current_perl = PERL_GET_CONTEXT; \
110                 PERL_SET_CONTEXT(parent_perl); { \
111                                         PerlInterpreter *my_perl = parent_perl;
112 #define LEAVE_TLS_CONTEXT \
113                                                 } PERL_SET_CONTEXT(current_perl);
114 #else
115 #define GET_TLS_CONTEXT         /* TLS context not enabled */
116 #define ENTER_TLS_CONTEXT       /* TLS context not enabled */
117 #define LEAVE_TLS_CONTEXT       /* TLS context not enabled */
118 #endif
119
120 #endif
121
122 Uint32 
123 sdl_perl_timer_callback ( Uint32 interval, void* param )
124 {
125         Uint32 retval;
126         int back;
127         SV* cmd;
128         ENTER_TLS_CONTEXT
129         dSP;
130
131         cmd = (SV*)param;
132
133         ENTER;
134         SAVETMPS;
135         PUSHMARK(SP);
136         XPUSHs(sv_2mortal(newSViv(interval)));
137         PUTBACK;
138
139         if (0 != (back = call_sv(cmd,G_SCALAR))) {
140                 SPAGAIN;
141                 if (back != 1 ) Perl_croak (aTHX_ "Timer Callback failed!");
142                 retval = POPi;  
143         } else {
144                 Perl_croak(aTHX_ "Timer Callback failed!");
145         }
146
147         FREETMPS;
148         LEAVE;
149
150         LEAVE_TLS_CONTEXT
151         
152         return retval;
153 }
154
155 void
156 sdl_perl_audio_callback ( void* data, Uint8 *stream, int len )
157 {
158         SV *cmd;
159         ENTER_TLS_CONTEXT
160         dSP;
161
162         cmd = (SV*)data;
163
164         ENTER;
165         SAVETMPS;
166         PUSHMARK(SP);
167         XPUSHs(sv_2mortal(newSViv(PTR2IV(stream))));
168         XPUSHs(sv_2mortal(newSViv(len)));
169         PUTBACK;
170
171         call_sv(cmd,G_VOID|G_DISCARD);
172         
173         PUTBACK;
174         FREETMPS;
175         LEAVE;
176
177         LEAVE_TLS_CONTEXT       
178 }
179
180 #ifdef HAVE_SDL_MIXER
181
182 void
183 sdl_perl_music_callback ( void ) 
184 {
185         SV *cmd;
186         ENTER_TLS_CONTEXT
187         dSP;
188
189         cmd = (SV*)Mix_GetMusicHookData();
190
191         ENTER;
192         SAVETMPS;
193         PUSHMARK(SP);
194         PUTBACK;
195         
196         call_sv(cmd,G_VOID|G_DISCARD);
197
198         PUTBACK;
199         FREETMPS;
200         LEAVE;
201
202         LEAVE_TLS_CONTEXT
203 }
204
205 void
206 sdl_perl_music_finished_callback ( void )
207 {
208         SV *cmd;
209         ENTER_TLS_CONTEXT
210         dSP;
211
212         cmd = (SV*)mix_music_finished_cv;
213         if ( cmd == NULL ) return;
214
215         ENTER;
216         SAVETMPS;
217         PUSHMARK(SP);
218         PUTBACK;
219         
220         call_sv(cmd,G_VOID|G_DISCARD);
221         
222         PUTBACK;
223         FREETMPS;
224         LEAVE;
225
226         LEAVE_TLS_CONTEXT
227 }
228
229 #endif
230
231 #define INIT_NS_APPLICATION
232 #define QUIT_NS_APPLICATION
233
234
235 void
236 sdl_perl_atexit (void)
237 {
238         QUIT_NS_APPLICATION     
239         SDL_Quit();
240 }
241
242 void boot_SDL();
243 void boot_SDL__OpenGL();
244
245 XS(boot_SDL_perl)
246 {
247         GET_TLS_CONTEXT
248         boot_SDL();
249 }
250
251 MODULE = SDL_perl       PACKAGE = SDL
252 PROTOTYPES : DISABLE
253
254 char *
255 GetError ()
256         CODE:
257                 RETVAL = SDL_GetError();
258         OUTPUT:
259                 RETVAL
260
261 int
262 Init ( flags )
263         Uint32 flags
264         CODE:
265                 INIT_NS_APPLICATION
266                 RETVAL = SDL_Init(flags);
267 #ifdef HAVE_TLS_CONTEXT
268                 Perl_call_atexit(PERL_GET_CONTEXT, (void*)sdl_perl_atexit,0);
269 #else
270                 atexit(sdl_perl_atexit);
271 #endif
272         OUTPUT:
273                 RETVAL
274
275 int
276 InitSubSystem ( flags )
277         Uint32 flags
278         CODE:
279                 RETVAL = SDL_InitSubSystem(flags);
280         OUTPUT:
281                 RETVAL
282
283 void
284 QuitSubSystem ( flags )
285         Uint32 flags
286         CODE:
287                 SDL_QuitSubSystem(flags);
288
289 void
290 Quit ()
291         CODE:
292                 QUIT_NS_APPLICATION
293                 SDL_Quit();
294
295 int
296 WasInit ( flags )
297         Uint32 flags
298         CODE:
299                 RETVAL = SDL_WasInit(flags);
300         OUTPUT:
301                 RETVAL
302
303 void
304 Delay ( ms )
305         int ms
306         CODE:
307                 SDL_Delay(ms);
308
309 Uint32
310 GetTicks ()
311         CODE:
312                 RETVAL = SDL_GetTicks();
313         OUTPUT:
314                 RETVAL
315
316 int
317 SetTimer ( interval, callback )
318         Uint32 interval
319         SDL_TimerCallback callback
320         CODE:
321                 RETVAL = SDL_SetTimer(interval,callback);
322         OUTPUT:
323                 RETVAL
324
325 SDL_TimerID
326 AddTimer ( interval, callback, param )
327         Uint32 interval
328         SDL_NewTimerCallback callback
329         void *param
330         CODE:
331                 RETVAL = SDL_AddTimer(interval,callback,param);
332         OUTPUT:
333                 RETVAL
334
335 SDL_NewTimerCallback
336 PerlTimerCallback ()
337         CODE:
338                 RETVAL = sdl_perl_timer_callback;
339         OUTPUT:
340                 RETVAL  
341
342 SDL_TimerID
343 NewTimer ( interval, cmd )
344         Uint32 interval
345         void *cmd
346         CODE:
347                 RETVAL = SDL_AddTimer(interval,sdl_perl_timer_callback,cmd);
348         OUTPUT:
349                 RETVAL
350
351 Uint32
352 RemoveTimer ( id )
353         SDL_TimerID id
354         CODE:
355                 RETVAL = SDL_RemoveTimer(id);
356         OUTPUT:
357                 RETVAL
358
359 SDL_RWops*
360 RWFromFile ( file, mode )
361         char* file
362         char * mode
363         CODE:
364                 RETVAL = SDL_RWFromFile(file,mode);
365         OUTPUT:
366                 RETVAL
367
368 SDL_RWops*
369 RWFromFP ( fp, autoclose )
370         FILE* fp
371         int autoclose
372         CODE:
373                 RETVAL = SDL_RWFromFP(fp,autoclose);
374         OUTPUT:
375                 RETVAL
376
377 SDL_RWops*
378 RWFromMem ( mem, size )
379         char* mem
380         int size
381         CODE:
382                 RETVAL = SDL_RWFromMem((void*)mem,size);
383         OUTPUT:
384                 RETVAL
385
386 SDL_RWops*
387 RWFromConstMem ( mem, size )
388         const char* mem
389         int size
390         CODE:
391                 RETVAL = SDL_RWFromConstMem((const void*)mem,size);
392         OUTPUT:
393                 RETVAL
394
395 SDL_RWops*
396 AllocRW ()
397         CODE:
398                 RETVAL = SDL_AllocRW();
399         OUTPUT:
400                 RETVAL
401
402 void
403 FreeRW ( rw )
404         SDL_RWops* rw
405         CODE:
406                 SDL_FreeRW(rw);
407
408 int
409 RWseek ( rw, off, whence )
410         SDL_RWops* rw
411         int off
412         int whence
413         CODE:
414                 RETVAL = SDL_RWseek(rw,off,whence);
415         OUTPUT:
416                 RETVAL
417
418 int
419 RWtell ( rw )
420         SDL_RWops* rw
421         CODE:
422                 RETVAL = SDL_RWtell(rw);
423         OUTPUT:
424                 RETVAL
425
426 int
427 RWread ( rw, mem, size, n )
428         SDL_RWops* rw
429         char* mem
430         int size
431         int n
432         CODE:
433                 RETVAL = SDL_RWread(rw,mem,size,n);
434         OUTPUT:
435                 RETVAL
436
437 int
438 RWwrite ( rw, mem, size, n )
439         SDL_RWops* rw
440         char* mem
441         int size
442         int n
443         CODE:
444                 RETVAL = SDL_RWwrite(rw,mem,size,n);
445         OUTPUT:
446                 RETVAL
447
448 int
449 RWclose ( rw )
450         SDL_RWops* rw
451         CODE:
452                 RETVAL = SDL_RWclose(rw);
453         OUTPUT:
454                 RETVAL
455
456 int
457 CDNumDrives ()
458         CODE:
459                 RETVAL = SDL_CDNumDrives();
460         OUTPUT:
461                 RETVAL
462
463 char *
464 CDName ( drive )
465         int drive
466         CODE:
467                 RETVAL = strdup(SDL_CDName(drive));
468         OUTPUT:
469                 RETVAL
470
471 SDL_CD *
472 CDOpen ( drive )
473         int drive
474         CODE:
475                 RETVAL = SDL_CDOpen(drive);
476         OUTPUT:
477                 RETVAL
478
479 Uint8
480 CDTrackId ( track )
481         SDL_CDtrack *track
482         CODE:
483                 RETVAL = track->id;
484         OUTPUT:
485                 RETVAL
486
487 Uint8
488 CDTrackType ( track )
489         SDL_CDtrack *track
490         CODE:
491                 RETVAL = track->type;
492         OUTPUT:
493                 RETVAL
494
495 Uint16
496 CDTrackLength ( track )
497         SDL_CDtrack *track
498         CODE:
499                 RETVAL = track->length;
500         OUTPUT:
501                 RETVAL
502
503 Uint32
504 CDTrackOffset ( track )
505         SDL_CDtrack *track
506         CODE:
507                 RETVAL = track->offset;
508         OUTPUT: 
509                 RETVAL
510
511 Uint32
512 CDStatus ( cd )
513         SDL_CD *cd 
514         CODE:
515                 RETVAL = SDL_CDStatus(cd);
516         OUTPUT:
517                 RETVAL
518
519 int
520 CDPlayTracks ( cd, start_track, ntracks, start_frame, nframes )
521         SDL_CD *cd
522         int start_track
523         int ntracks
524         int start_frame
525         int nframes
526         CODE:
527                 RETVAL = SDL_CDPlayTracks(cd,start_track,start_frame,ntracks,nframes);
528         OUTPUT:
529                 RETVAL
530
531 int
532 CDPlay ( cd, start, length )
533         SDL_CD *cd
534         int start
535         int length
536         CODE:
537                 RETVAL = SDL_CDPlay(cd,start,length);
538         OUTPUT:
539                 RETVAL
540
541 int
542 CDPause ( cd )
543         SDL_CD *cd
544         CODE:
545                 RETVAL = SDL_CDPause(cd);
546         OUTPUT:
547                 RETVAL
548
549 int
550 CDResume ( cd )
551         SDL_CD *cd
552         CODE:
553                 RETVAL = SDL_CDResume(cd);
554         OUTPUT:
555                 RETVAL
556
557 int
558 CDStop ( cd )
559         SDL_CD *cd
560         CODE:
561                 RETVAL = SDL_CDStop(cd);
562         OUTPUT:
563                 RETVAL
564
565 int
566 CDEject ( cd )
567         SDL_CD *cd
568         CODE:
569                 RETVAL = SDL_CDEject(cd);
570         OUTPUT:
571                 RETVAL
572
573 void
574 CDClose ( cd )
575         SDL_CD *cd
576         CODE:
577                 SDL_CDClose(cd);
578         
579 int
580 CDId ( cd )
581         SDL_CD *cd
582         CODE:
583                 RETVAL = cd->id;
584         OUTPUT: 
585                 RETVAL
586
587 int
588 CDNumTracks ( cd )
589         SDL_CD *cd
590         CODE:
591                 RETVAL = cd->numtracks;
592         OUTPUT:
593                 RETVAL
594
595 int
596 CDCurTrack ( cd )
597         SDL_CD *cd
598         CODE:
599                 RETVAL = cd->cur_track;
600         OUTPUT:
601                 RETVAL
602
603 int
604 CDCurFrame ( cd )
605         SDL_CD *cd
606         CODE:
607                 RETVAL = cd->cur_frame;
608         OUTPUT:
609                 RETVAL
610
611 SDL_CDtrack *
612 CDTrack ( cd, number )
613         SDL_CD *cd
614         int number
615         CODE:
616                 RETVAL = (SDL_CDtrack *)(cd->track + number);
617         OUTPUT:
618                 RETVAL
619
620 void
621 PumpEvents ()
622         CODE:
623                 SDL_PumpEvents();
624
625 int
626 PushEvent( e )
627         SDL_Event *e
628         CODE:
629                 RETVAL = SDL_PushEvent( e );
630         OUTPUT:
631                 RETVAL
632
633 SDL_Event *
634 NewEvent ()
635         CODE:   
636                 RETVAL = (SDL_Event *) safemalloc (sizeof(SDL_Event));
637         OUTPUT:
638                 RETVAL
639
640 void
641 FreeEvent ( e )
642         SDL_Event *e
643         CODE:
644                 safefree(e);
645
646 int
647 PollEvent ( e )
648         SDL_Event *e
649         CODE:
650                 RETVAL = SDL_PollEvent(e);
651         OUTPUT:
652                 RETVAL
653
654 int
655 WaitEvent ( e )
656         SDL_Event *e
657         CODE:
658                 RETVAL = SDL_WaitEvent(e);
659         OUTPUT:
660                 RETVAL
661
662 Uint8
663 EventState ( type, state )
664         Uint8 type
665         int state
666         CODE:
667                 RETVAL = SDL_EventState(type,state);
668         OUTPUT:
669                 RETVAL 
670
671 Uint8
672 EventType ( e )
673         SDL_Event *e
674         CODE:
675                 RETVAL = e->type;
676         OUTPUT:
677                 RETVAL
678
679 Uint8
680 SetEventType ( e, type )
681         SDL_Event *e
682         Uint8 type
683         CODE:
684                 RETVAL = e->type;
685                 e->type = type;
686         OUTPUT:
687                 RETVAL
688
689 Uint8
690 ActiveEventGain ( e )
691         SDL_Event *e
692         CODE:
693                 RETVAL = e->active.gain;
694         OUTPUT: 
695                 RETVAL
696
697 Uint8
698 ActiveEventState ( e )
699         SDL_Event *e
700         CODE:
701                 RETVAL = e->active.state;
702         OUTPUT:
703                 RETVAL
704
705 Uint8
706 KeyEventState( e )
707         SDL_Event *e
708         CODE:
709                 RETVAL = e->key.state;
710         OUTPUT:
711                 RETVAL
712
713 int
714 KeyEventSym ( e )
715         SDL_Event *e
716         CODE:
717                 RETVAL = e->key.keysym.sym;
718         OUTPUT:
719                 RETVAL
720
721 int 
722 KeyEventMod ( e )
723         SDL_Event *e
724         CODE:
725                 RETVAL = e->key.keysym.mod;
726         OUTPUT:
727                 RETVAL
728
729 Uint16
730 KeyEventUnicode ( e )
731         SDL_Event *e
732         CODE:
733                 RETVAL = e->key.keysym.unicode;
734         OUTPUT:
735                 RETVAL
736
737 Uint8
738 KeyEventScanCode ( e )
739         SDL_Event *e
740         CODE:
741                 RETVAL = e->key.keysym.scancode;
742         OUTPUT:
743                 RETVAL
744
745 Uint8
746 MouseMotionState ( e )
747         SDL_Event *e
748         CODE:
749                 RETVAL = e->motion.state;
750         OUTPUT: 
751                 RETVAL
752
753 Uint16
754 MouseMotionX ( e )
755         SDL_Event *e
756         CODE:
757                 RETVAL = e->motion.x;
758         OUTPUT:
759                 RETVAL
760
761 Uint16
762 MouseMotionY ( e )
763         SDL_Event *e
764         CODE:
765                 RETVAL = e->motion.y;
766         OUTPUT:
767                 RETVAL
768
769 Sint16
770 MouseMotionXrel( e )
771         SDL_Event *e
772         CODE:
773                 RETVAL = e->motion.xrel;
774         OUTPUT:
775                 RETVAL
776
777 Sint16
778 MouseMotionYrel ( e )
779         SDL_Event *e
780         CODE:
781                 RETVAL = e->motion.yrel;
782         OUTPUT:
783                 RETVAL
784
785 Uint8
786 MouseButtonState ( e )
787         SDL_Event *e
788         CODE:
789                 RETVAL = e->button.state;
790         OUTPUT:
791                 RETVAL
792
793 Uint8
794 MouseButton ( e )
795         SDL_Event *e
796         CODE:
797                 RETVAL = e->button.button;
798         OUTPUT:
799                 RETVAL
800
801 Uint16
802 MouseButtonX ( e )
803         SDL_Event *e
804         CODE:
805                 RETVAL = e->button.x;
806         OUTPUT:
807                 RETVAL
808
809 Uint16
810 MouseButtonY ( e )
811         SDL_Event *e
812         CODE:
813                 RETVAL = e->button.y;
814         OUTPUT:
815                 RETVAL
816
817 SDL_SysWMmsg *
818 SysWMEventMsg ( e )
819         SDL_Event *e
820         CODE:
821                 RETVAL = e->syswm.msg;
822         OUTPUT:
823                 RETVAL
824
825 int
826 EnableUnicode ( enable )
827         int enable
828         CODE:
829                 RETVAL = SDL_EnableUNICODE(enable);
830         OUTPUT:
831                 RETVAL
832
833 void
834 EnableKeyRepeat ( delay, interval )
835         int delay
836         int interval
837         CODE:
838                 SDL_EnableKeyRepeat(delay,interval);
839
840 Uint32
841 GetModState ()
842         CODE:
843                 RETVAL = SDL_GetModState();
844         OUTPUT:
845                 RETVAL
846
847 void
848 SetModState ( state )
849         Uint32 state
850         CODE:
851                 SDL_SetModState(state);
852
853 char *
854 GetKeyName ( sym )
855         int sym
856         CODE:
857                 RETVAL = SDL_GetKeyName(sym);
858         OUTPUT:
859                 RETVAL
860
861 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 void
1327 FreeColor ( color )
1328         SDL_Color *color
1329         CODE:
1330                 return; safefree(color);
1331
1332 SDL_Palette *
1333 NewPalette ( number )
1334         int number
1335         CODE:
1336                 RETVAL = (SDL_Palette *)safemalloc(sizeof(SDL_Palette));
1337                 RETVAL->colors = (SDL_Color *)safemalloc(number * 
1338                                                 sizeof(SDL_Color));
1339                 RETVAL->ncolors = number;
1340         OUTPUT:
1341                 RETVAL
1342
1343 int
1344 PaletteNColors ( palette, ... )
1345         SDL_Palette *palette
1346         CODE:
1347                 if ( items > 1 ) palette->ncolors = SvIV(ST(1));
1348                 RETVAL = palette->ncolors;
1349         OUTPUT:
1350                 RETVAL
1351
1352 SDL_Color *
1353 PaletteColors ( palette, index, ... )
1354         SDL_Palette *palette
1355         int index
1356         CODE:
1357                 if ( items > 2 ) {
1358                         palette->colors[index].r = SvUV(ST(2)); 
1359                         palette->colors[index].g = SvUV(ST(3)); 
1360                         palette->colors[index].b = SvUV(ST(4)); 
1361                 }
1362                 RETVAL = (SDL_Color *)(palette->colors + index);
1363         OUTPUT:
1364                 RETVAL
1365
1366 int
1367 VideoModeOK ( width, height, bpp, flags )
1368         int width
1369         int height
1370         int bpp
1371         Uint32 flags
1372         CODE:
1373                 RETVAL = SDL_VideoModeOK(width,height,bpp,flags);
1374         OUTPUT:
1375                 RETVAL
1376
1377 SDL_Surface *
1378 SetVideoMode ( width, height, bpp, flags )
1379         int width
1380         int height
1381         int bpp
1382         Uint32 flags
1383         CODE:
1384                 RETVAL = SDL_SetVideoMode(width,height,bpp,flags);
1385         OUTPUT:
1386                 RETVAL
1387
1388 void
1389 UpdateRect ( surface, x, y, w ,h )
1390         SDL_Surface *surface
1391         int x
1392         int y
1393         int w
1394         int h
1395         CODE:
1396                 SDL_UpdateRect(surface,x,y,w,h);
1397
1398 void
1399 UpdateRects ( surface, ... )
1400         SDL_Surface *surface
1401         CODE:
1402                 SDL_Rect *rects, *temp;
1403                 int num_rects,i;
1404                 if ( items < 2 ) return;
1405                 num_rects = items - 1;  
1406                 rects = (SDL_Rect *)safemalloc(sizeof(SDL_Rect)*items);
1407                 for(i=0;i<num_rects;i++) {
1408                         temp = (SDL_Rect *)SvIV(ST(i+1));
1409                         rects[i].x = temp->x;
1410                         rects[i].y = temp->y;
1411                         rects[i].w = temp->w;
1412                         rects[i].h = temp->h;
1413                 } 
1414                 SDL_UpdateRects(surface,num_rects,rects);
1415                 safefree(rects);
1416
1417 int
1418 Flip ( surface )
1419         SDL_Surface *surface
1420         CODE:
1421                 RETVAL = SDL_Flip(surface);
1422         OUTPUT:
1423                 RETVAL
1424
1425 int
1426 SetColors ( surface, start, ... )
1427         SDL_Surface *surface
1428         int start
1429         CODE:
1430                 SDL_Color *colors,*temp;
1431                 int i, length;
1432                 if ( items < 3 ) { RETVAL = 0;  goto all_done; }
1433                 length = items - 2;
1434                 colors = (SDL_Color *)safemalloc(sizeof(SDL_Color)*(length+1));
1435                 for ( i = 0; i < length ; i++ ) {
1436                         temp = (SDL_Color *)SvIV(ST(i+2));
1437                         colors[i].r = temp->r;
1438                         colors[i].g = temp->g;
1439                         colors[i].b = temp->b;
1440                 }
1441                 RETVAL = SDL_SetColors(surface, colors, start, length );
1442                 safefree(colors);
1443 all_done:
1444         OUTPUT: 
1445                 RETVAL
1446
1447 Uint32
1448 MapRGB ( surface, r, g, b )
1449         SDL_Surface *surface
1450         Uint8 r
1451         Uint8 g
1452         Uint8 b
1453         CODE:
1454                 RETVAL = SDL_MapRGB(surface->format,r,g,b);
1455         OUTPUT:
1456                 RETVAL
1457
1458 Uint32
1459 MapRGBA ( surface, r, g, b, a )
1460         SDL_Surface *surface
1461         Uint8 r
1462         Uint8 g
1463         Uint8 b
1464         Uint8 a
1465         CODE:
1466                 RETVAL = SDL_MapRGBA(surface->format,r,g,b,a);
1467         OUTPUT:
1468                 RETVAL
1469
1470 AV *
1471 GetRGB ( surface, pixel )
1472         SDL_Surface *surface
1473         Uint32 pixel
1474         CODE:
1475                 Uint8 r,g,b;
1476                 SDL_GetRGB(pixel,surface->format,&r,&g,&b);
1477                 RETVAL = newAV();
1478                 av_push(RETVAL,newSViv(r));
1479                 av_push(RETVAL,newSViv(g));
1480                 av_push(RETVAL,newSViv(b));
1481         OUTPUT:
1482                 RETVAL
1483
1484 AV *
1485 GetRGBA ( surface, pixel )
1486         SDL_Surface *surface
1487         Uint32 pixel
1488         CODE:
1489                 Uint8 r,g,b,a;
1490                 SDL_GetRGBA(pixel,surface->format,&r,&g,&b,&a);
1491                 RETVAL = newAV();
1492                 av_push(RETVAL,newSViv(r));
1493                 av_push(RETVAL,newSViv(g));
1494                 av_push(RETVAL,newSViv(b));
1495                 av_push(RETVAL,newSViv(a));
1496         OUTPUT:
1497                 RETVAL
1498
1499 int
1500 SaveBMP ( surface, filename )
1501         SDL_Surface *surface
1502         char *filename
1503         CODE:
1504                 RETVAL = SDL_SaveBMP(surface,filename);
1505         OUTPUT:
1506                 RETVAL  
1507
1508 int
1509 SetColorKey ( surface, flag, key )
1510         SDL_Surface *surface
1511         Uint32 flag
1512         SDL_Color *key
1513         CODE:
1514                 Uint32 pixel = SDL_MapRGB(surface->format,key->r,key->g,key->b);
1515                 RETVAL = SDL_SetColorKey(surface,flag,pixel);
1516         OUTPUT:
1517                 RETVAL
1518
1519 int
1520 SetAlpha ( surface, flag, alpha )
1521         SDL_Surface *surface
1522         Uint32 flag
1523         Uint8 alpha
1524         CODE:
1525                 RETVAL = SDL_SetAlpha(surface,flag,alpha);
1526         OUTPUT:
1527                 RETVAL
1528
1529 SDL_Surface *
1530 DisplayFormat ( surface )
1531         SDL_Surface *surface
1532         CODE:
1533                 RETVAL = SDL_DisplayFormat(surface);
1534         OUTPUT:
1535                 RETVAL
1536
1537 SDL_Surface*
1538 DisplayFormatAlpha ( surface )
1539         SDL_Surface *surface
1540         CODE:
1541                 RETVAL = SDL_DisplayFormatAlpha(surface);
1542         OUTPUT:
1543                 RETVAL
1544
1545 SDL_Surface*
1546 ConvertRGB ( surface )
1547         SDL_Surface * surface
1548         CODE:
1549                 SDL_PixelFormat fmt;
1550                 fmt.palette = NULL;
1551                 fmt.BitsPerPixel = 24;
1552                 fmt.BytesPerPixel = 3;
1553                 fmt.Rmask = 0x000000ff;
1554                 fmt.Gmask = 0x0000ff00;
1555                 fmt.Bmask = 0x00ff0000;
1556                 fmt.Amask = 0x00000000;
1557                 fmt.Rloss = 0;
1558                 fmt.Gloss = 0;
1559                 fmt.Bloss = 0;
1560                 fmt.Aloss = 0;
1561                 fmt.Rshift = 0;
1562                 fmt.Gshift = 8;
1563                 fmt.Bshift = 16;
1564                 fmt.Ashift = 24;
1565                 fmt.colorkey = 0;
1566                 fmt.alpha = 0;
1567                 RETVAL = SDL_ConvertSurface(surface,&fmt,surface->flags);
1568         OUTPUT:
1569                 RETVAL
1570
1571 SDL_Surface* 
1572 ConvertRGBA ( surface )
1573         SDL_Surface * surface
1574         CODE:
1575                 SDL_PixelFormat fmt;
1576                 fmt.palette = NULL;
1577                 fmt.BitsPerPixel = 32;
1578                 fmt.BytesPerPixel = 4;
1579                 fmt.Rmask = 0x000000ff;
1580                 fmt.Gmask = 0x0000ff00;
1581                 fmt.Bmask = 0x00ff0000;
1582                 fmt.Amask = 0xff000000;
1583                 fmt.Rloss = 0;
1584                 fmt.Gloss = 0;
1585                 fmt.Bloss = 0;
1586                 fmt.Aloss = 0;
1587                 fmt.Rshift = 0;
1588                 fmt.Gshift = 8;
1589                 fmt.Bshift = 16;
1590                 fmt.Ashift = 24;
1591                 fmt.colorkey = 0;
1592                 fmt.alpha = 0;
1593                 RETVAL = SDL_ConvertSurface(surface,&fmt,surface->flags);
1594         OUTPUT:
1595                 RETVAL
1596
1597 int
1598 BlitSurface ( src, src_rect, dest, dest_rect )
1599         SDL_Surface *src
1600         SDL_Rect *src_rect
1601         SDL_Surface *dest
1602         SDL_Rect *dest_rect
1603         CODE:
1604                 RETVAL = SDL_BlitSurface(src,src_rect,dest,dest_rect);
1605         OUTPUT:
1606                 RETVAL
1607
1608 int
1609 FillRect ( dest, dest_rect, color )
1610         SDL_Surface *dest
1611         SDL_Rect *dest_rect
1612         SDL_Color *color
1613         CODE:
1614                 Uint32 pixel = SDL_MapRGB(dest->format,color->r,color->g,color->b);
1615                 RETVAL = SDL_FillRect(dest,dest_rect,pixel);
1616         OUTPUT:
1617                 RETVAL
1618
1619 Uint8
1620 GetAppState ()
1621         CODE:
1622                 RETVAL = SDL_GetAppState();
1623         OUTPUT:
1624                 RETVAL
1625
1626
1627 void
1628 WMSetCaption ( title, icon )
1629         char *title
1630         char *icon
1631         CODE:
1632                 SDL_WM_SetCaption(title,icon);
1633
1634 AV *
1635 WMGetCaption ()
1636         CODE:
1637                 char *title,*icon;
1638                 SDL_WM_GetCaption(&title,&icon);
1639                 RETVAL = newAV();
1640                 av_push(RETVAL,newSVpv(title,0));
1641                 av_push(RETVAL,newSVpv(icon,0));
1642         OUTPUT:
1643                 RETVAL
1644
1645 void
1646 WMSetIcon ( icon )
1647         SDL_Surface *icon
1648         CODE:
1649                 SDL_WM_SetIcon(icon,NULL);
1650
1651 void
1652 WarpMouse ( x, y )
1653         Uint16 x
1654         Uint16 y
1655         CODE:
1656                 SDL_WarpMouse(x,y);
1657
1658 AV*
1659 GetMouseState ()
1660         CODE:
1661                 Uint8 mask;
1662                 int x;
1663                 int y;
1664                 mask = SDL_GetMouseState(&x,&y);
1665                 RETVAL = newAV();
1666                 av_push(RETVAL,newSViv(mask));
1667                 av_push(RETVAL,newSViv(x));
1668                 av_push(RETVAL,newSViv(y));
1669         OUTPUT:
1670                 RETVAL  
1671
1672 AV*
1673 GetRelativeMouseState ()
1674         CODE:
1675                 Uint8 mask;
1676                 int x;
1677                 int y;
1678                 mask = SDL_GetRelativeMouseState(&x,&y);
1679                 RETVAL = newAV();
1680                 av_push(RETVAL,newSViv(mask));
1681                 av_push(RETVAL,newSViv(x));
1682                 av_push(RETVAL,newSViv(y));
1683         OUTPUT:
1684                 RETVAL  
1685
1686 SDL_Cursor *
1687 NewCursor ( data, mask, x ,y )
1688         SDL_Surface *data
1689         SDL_Surface *mask
1690         int x
1691         int y
1692         CODE:
1693                 RETVAL = SDL_CreateCursor((Uint8*)data->pixels,
1694                                 (Uint8*)mask->pixels,data->w,data->h,x,y);
1695         OUTPUT:
1696                 RETVAL
1697
1698 void
1699 FreeCursor ( cursor )
1700         SDL_Cursor *cursor
1701         CODE:
1702                 SDL_FreeCursor(cursor);
1703
1704 void
1705 SetCursor ( cursor )
1706         SDL_Cursor *cursor
1707         CODE:
1708                 SDL_SetCursor(cursor);
1709
1710 SDL_Cursor *
1711 GetCursor ()
1712         CODE:
1713                 RETVAL = SDL_GetCursor();
1714         OUTPUT:
1715                 RETVAL
1716
1717 int
1718 ShowCursor ( toggle )
1719         int toggle
1720         CODE:
1721                 RETVAL = SDL_ShowCursor(toggle);
1722         OUTPUT: 
1723                 RETVAL
1724
1725 SDL_AudioSpec *
1726 NewAudioSpec ( freq, format, channels, samples )
1727         int freq
1728         Uint16 format
1729         Uint8 channels
1730         Uint16 samples
1731         CODE:
1732                 RETVAL = (SDL_AudioSpec *)safemalloc(sizeof(SDL_AudioSpec));
1733                 RETVAL->freq = freq;
1734                 RETVAL->format = format;
1735                 RETVAL->channels = channels;
1736                 RETVAL->samples = samples;
1737         OUTPUT:
1738                 RETVAL
1739
1740 void
1741 FreeAudioSpec ( spec )
1742         SDL_AudioSpec *spec
1743         CODE:
1744                 safefree(spec);
1745
1746 SDL_AudioCVT *
1747 NewAudioCVT ( src_format, src_channels, src_rate, dst_format, dst_channels, dst_rate)
1748         Uint16 src_format
1749         Uint8 src_channels
1750         int src_rate
1751         Uint16 dst_format
1752         Uint8 dst_channels
1753         int dst_rate
1754         CODE:
1755                 RETVAL = (SDL_AudioCVT *)safemalloc(sizeof(SDL_AudioCVT));
1756                 if (SDL_BuildAudioCVT(RETVAL,src_format, src_channels, src_rate,
1757                         dst_format, dst_channels, dst_rate)) { 
1758                         safefree(RETVAL); RETVAL = NULL; }
1759         OUTPUT:
1760                 RETVAL
1761
1762 void
1763 FreeAudioCVT ( cvt )
1764         SDL_AudioCVT *cvt
1765         CODE:
1766                 safefree(cvt);
1767
1768 int
1769 ConvertAudioData ( cvt, data, len )
1770         SDL_AudioCVT *cvt
1771         Uint8 *data
1772         int len
1773         CODE:
1774                 cvt->len = len;
1775                 cvt->buf = (Uint8*) safemalloc(cvt->len*cvt->len_mult);
1776                 memcpy(cvt->buf,data,cvt->len);
1777                 RETVAL = SDL_ConvertAudio(cvt);
1778         OUTPUT:
1779                 RETVAL                  
1780
1781 int
1782 OpenAudio ( spec, callback )
1783         SDL_AudioSpec *spec
1784         SV* callback
1785         CODE:
1786                 spec->userdata = (void*)callback;
1787                 spec->callback = sdl_perl_audio_callback;
1788                 RETVAL = SDL_OpenAudio(spec,NULL);
1789         OUTPUT:
1790                 RETVAL
1791
1792 Uint32
1793 GetAudioStatus ()
1794         CODE:
1795                 RETVAL = SDL_GetAudioStatus ();
1796         OUTPUT:
1797                 RETVAL
1798
1799 void
1800 PauseAudio ( p_on )
1801         int p_on
1802         CODE:
1803                 SDL_PauseAudio(p_on);
1804         
1805 void
1806 LockAudio ()
1807         CODE:
1808                 SDL_LockAudio();
1809
1810 void
1811 UnlockAudio ()
1812         CODE:
1813                 SDL_UnlockAudio();
1814
1815 void
1816 CloseAudio ()
1817         CODE:
1818                 SDL_CloseAudio();
1819
1820 void
1821 FreeWAV ( buf )
1822         Uint8 *buf
1823         CODE:
1824                 SDL_FreeWAV(buf);
1825
1826 AV *
1827 LoadWAV ( filename, spec )
1828         char *filename
1829         SDL_AudioSpec *spec
1830         CODE:
1831                 SDL_AudioSpec *temp;
1832                 Uint8 *buf;
1833                 Uint32 len;
1834
1835                 RETVAL = newAV();
1836                 temp = SDL_LoadWAV(filename,spec,&buf,&len);
1837                 if ( ! temp ) goto error;
1838                 av_push(RETVAL,newSViv(PTR2IV(temp)));
1839                 av_push(RETVAL,newSViv(PTR2IV(buf)));
1840                 av_push(RETVAL,newSViv(len));
1841 error:
1842         OUTPUT:
1843                 RETVAL
1844         
1845 #ifdef HAVE_SDL_MIXER
1846
1847 void
1848 MixAudio ( dst, src, len, volume )
1849         Uint8 *dst
1850         Uint8 *src
1851         Uint32 len
1852         int volume
1853         CODE:
1854                 SDL_MixAudio(dst,src,len,volume);
1855
1856 int
1857 MixOpenAudio ( frequency, format, channels, chunksize )
1858         int frequency
1859         Uint16 format
1860         int channels
1861         int chunksize   
1862         CODE:
1863                 RETVAL = Mix_OpenAudio(frequency, format, channels, chunksize);
1864         OUTPUT:
1865                 RETVAL
1866
1867 int
1868 MixAllocateChannels ( number )
1869         int number
1870         CODE:
1871                 RETVAL = Mix_AllocateChannels(number);
1872         OUTPUT:
1873                 RETVAL
1874
1875 AV *
1876 MixQuerySpec ()
1877         CODE:
1878                 int freq, channels, status;
1879                 Uint16 format;
1880                 status = Mix_QuerySpec(&freq,&format,&channels);
1881                 RETVAL = newAV();
1882                 av_push(RETVAL,newSViv(status));
1883                 av_push(RETVAL,newSViv(freq));
1884                 av_push(RETVAL,newSViv(format));
1885                 av_push(RETVAL,newSViv(channels));
1886         OUTPUT:
1887                 RETVAL
1888
1889 Mix_Chunk *
1890 MixLoadWAV ( filename )
1891         char *filename
1892         CODE:
1893                 RETVAL = Mix_LoadWAV(filename);
1894         OUTPUT:
1895                 RETVAL
1896
1897 Mix_Music *
1898 MixLoadMusic ( filename )
1899         char *filename
1900         CODE:
1901                 RETVAL = Mix_LoadMUS(filename);
1902         OUTPUT:
1903                 RETVAL
1904
1905 Mix_Chunk *
1906 MixQuickLoadWAV ( buf )
1907         Uint8 *buf
1908         CODE:
1909                 RETVAL = Mix_QuickLoad_WAV(buf);
1910         OUTPUT:
1911                 RETVAL
1912
1913 void
1914 MixFreeChunk( chunk )
1915         Mix_Chunk *chunk
1916         CODE:
1917                 Mix_FreeChunk(chunk);
1918
1919 void
1920 MixFreeMusic ( music )
1921         Mix_Music *music
1922         CODE:
1923                 Mix_FreeMusic(music);
1924
1925 void
1926 MixSetPostMixCallback ( func, arg )
1927         void *func
1928         void *arg
1929         CODE:
1930                 Mix_SetPostMix(func,arg);
1931
1932 void*
1933 PerlMixMusicHook ()
1934         CODE:
1935                 RETVAL = sdl_perl_music_callback;
1936         OUTPUT:
1937                 RETVAL
1938
1939 void
1940 MixSetMusicHook ( func, arg )
1941         void *func
1942         void *arg
1943         CODE:
1944                 Mix_HookMusic(func,arg);
1945
1946 void
1947 MixSetMusicFinishedHook ( func )
1948         void *func
1949         CODE:
1950                 mix_music_finished_cv = func;
1951                 Mix_HookMusicFinished(sdl_perl_music_finished_callback);
1952
1953 void *
1954 MixGetMusicHookData ()
1955         CODE:
1956                 RETVAL = Mix_GetMusicHookData();
1957         OUTPUT:
1958                 RETVAL
1959
1960 int
1961 MixReverseChannels ( number )
1962         int number
1963         CODE:
1964                 RETVAL = Mix_ReserveChannels ( number );
1965         OUTPUT:
1966                 RETVAL
1967
1968 int
1969 MixGroupChannel ( which, tag )
1970         int which
1971         int tag
1972         CODE:
1973                 RETVAL = Mix_GroupChannel(which,tag);
1974         OUTPUT:
1975                 RETVAL
1976
1977 int
1978 MixGroupChannels ( from, to, tag )
1979         int from
1980         int to
1981         int tag
1982         CODE:
1983                 RETVAL = Mix_GroupChannels(from,to,tag);
1984         OUTPUT:
1985                 RETVAL
1986
1987 int
1988 MixGroupAvailable ( tag )
1989         int tag
1990         CODE:
1991                 RETVAL = Mix_GroupAvailable(tag);
1992         OUTPUT:
1993                 RETVAL
1994
1995 int
1996 MixGroupCount ( tag )
1997         int tag
1998         CODE:
1999                 RETVAL = Mix_GroupCount(tag);
2000         OUTPUT:
2001                 RETVAL
2002
2003 int
2004 MixGroupOldest ( tag )
2005         int tag
2006         CODE:
2007                 RETVAL = Mix_GroupOldest(tag);
2008         OUTPUT:
2009                 RETVAL
2010
2011 int
2012 MixGroupNewer ( tag )
2013         int tag
2014         CODE:
2015                 RETVAL = Mix_GroupNewer(tag);
2016         OUTPUT:
2017                 RETVAL
2018
2019 int
2020 MixPlayChannel ( channel, chunk, loops )
2021         int channel
2022         Mix_Chunk *chunk
2023         int loops
2024         CODE:
2025                 RETVAL = Mix_PlayChannel(channel,chunk,loops);
2026         OUTPUT:
2027                 RETVAL
2028
2029 int
2030 MixPlayChannelTimed ( channel, chunk, loops, ticks )
2031         int channel
2032         Mix_Chunk *chunk
2033         int loops
2034         int ticks
2035         CODE:
2036                 RETVAL = Mix_PlayChannelTimed(channel,chunk,loops,ticks);
2037         OUTPUT:
2038                 RETVAL
2039
2040 int
2041 MixPlayMusic ( music, loops )
2042         Mix_Music *music
2043         int loops
2044         CODE:
2045                 RETVAL = Mix_PlayMusic(music,loops);
2046         OUTPUT:
2047                 RETVAL
2048
2049 int
2050 MixFadeInChannel ( channel, chunk, loops, ms )
2051         int channel
2052         Mix_Chunk *chunk
2053         int loops
2054         int ms
2055         CODE:
2056                 RETVAL = Mix_FadeInChannel(channel,chunk,loops,ms);
2057         OUTPUT:
2058                 RETVAL
2059
2060 int
2061 MixFadeInChannelTimed ( channel, chunk, loops, ms, ticks )
2062         int channel
2063         Mix_Chunk *chunk
2064         int loops
2065         int ticks
2066         int ms
2067         CODE:
2068                 RETVAL = Mix_FadeInChannelTimed(channel,chunk,loops,ms,ticks);
2069         OUTPUT:
2070                 RETVAL
2071
2072 int
2073 MixFadeInMusic ( music, loops, ms )
2074         Mix_Music *music
2075         int loops
2076         int ms
2077         CODE:
2078                 RETVAL = Mix_FadeInMusic(music,loops,ms);
2079         OUTPUT:
2080                 RETVAL
2081
2082 int
2083 MixVolume ( channel, volume )
2084         int channel
2085         int volume
2086         CODE:   
2087                 RETVAL = Mix_Volume(channel,volume);
2088         OUTPUT:
2089                 RETVAL
2090
2091 int
2092 MixVolumeChunk ( chunk, volume )
2093         Mix_Chunk *chunk
2094         int volume
2095         CODE:
2096                 RETVAL = Mix_VolumeChunk(chunk,volume);
2097         OUTPUT:
2098                 RETVAL
2099
2100 int
2101 MixVolumeMusic ( volume )
2102         int volume
2103         CODE:
2104                 RETVAL = Mix_VolumeMusic(volume);
2105         OUTPUT:
2106                 RETVAL
2107
2108 int
2109 MixHaltChannel ( channel )
2110         int channel
2111         CODE:
2112                 RETVAL = Mix_HaltChannel(channel);
2113         OUTPUT:
2114                 RETVAL
2115
2116 int
2117 MixHaltGroup ( tag )
2118         int tag
2119         CODE:
2120                 RETVAL = Mix_HaltGroup(tag);
2121         OUTPUT:
2122                 RETVAL
2123
2124 int
2125 MixHaltMusic ()
2126         CODE:
2127                 RETVAL = Mix_HaltMusic();
2128         OUTPUT:
2129                 RETVAL
2130
2131 int
2132 MixExpireChannel ( channel, ticks )
2133         int channel
2134         int ticks
2135         CODE:
2136                 RETVAL = Mix_ExpireChannel ( channel,ticks);
2137         OUTPUT:
2138                 RETVAL
2139
2140 int
2141 MixFadeOutChannel ( which, ms )
2142         int which
2143         int ms
2144         CODE:
2145                 RETVAL = Mix_FadeOutChannel(which,ms);
2146         OUTPUT:
2147                 RETVAL
2148
2149 int
2150 MixFadeOutGroup ( which, ms )
2151         int which
2152         int ms
2153         CODE:
2154                 RETVAL = Mix_FadeOutGroup(which,ms);
2155         OUTPUT:
2156                 RETVAL
2157
2158 int
2159 MixFadeOutMusic ( ms )
2160         int ms
2161         CODE:
2162                 RETVAL = Mix_FadeOutMusic(ms);
2163         OUTPUT:
2164                 RETVAL
2165
2166 Mix_Fading
2167 MixFadingMusic()
2168         CODE:
2169                 RETVAL = Mix_FadingMusic();
2170         OUTPUT:
2171                 RETVAL
2172
2173 Mix_Fading
2174 MixFadingChannel( which )
2175         int which
2176         CODE:
2177                 RETVAL = Mix_FadingChannel(which);
2178         OUTPUT:
2179                 RETVAL
2180
2181 void
2182 MixPause ( channel )
2183         int channel
2184         CODE:
2185                 Mix_Pause(channel);
2186
2187 void
2188 MixResume ( channel )
2189         int channel
2190         CODE:
2191                 Mix_Resume(channel);
2192
2193 int
2194 MixPaused ( channel )
2195         int channel
2196         CODE:
2197                 RETVAL = Mix_Paused(channel);
2198         OUTPUT:
2199                 RETVAL
2200
2201 void
2202 MixPauseMusic ()
2203         CODE:
2204                 Mix_PauseMusic();
2205
2206 void
2207 MixResumeMusic ()
2208         CODE:
2209                 Mix_ResumeMusic();
2210
2211 void
2212 MixRewindMusic ()
2213         CODE:
2214                 Mix_RewindMusic();
2215
2216 int
2217 MixPausedMusic ()
2218         CODE:
2219                 RETVAL = Mix_PausedMusic();
2220         OUTPUT:
2221                 RETVAL
2222
2223 int
2224 MixPlaying( channel )
2225         int channel     
2226         CODE:
2227                 RETVAL = Mix_Playing(channel);
2228         OUTPUT:
2229                 RETVAL
2230
2231 int
2232 MixPlayingMusic()
2233         CODE:
2234                 RETVAL = Mix_PlayingMusic();
2235         OUTPUT:
2236                 RETVAL
2237
2238
2239 void
2240 MixCloseAudio ()
2241         CODE:
2242                 Mix_CloseAudio();
2243
2244 #endif
2245
2246 int
2247 GLLoadLibrary ( path )
2248         char *path
2249         CODE:
2250                 RETVAL = SDL_GL_LoadLibrary(path);
2251         OUTPUT:
2252                 RETVAL
2253
2254 void*
2255 GLGetProcAddress ( proc )
2256         char *proc
2257         CODE:
2258                 RETVAL = SDL_GL_GetProcAddress(proc);
2259         OUTPUT:
2260                 RETVAL
2261
2262 int
2263 GLSetAttribute ( attr,  value )
2264         int        attr
2265         int        value
2266         CODE:
2267                 RETVAL = SDL_GL_SetAttribute(attr, value);
2268         OUTPUT:
2269                 RETVAL
2270
2271 AV *
2272 GLGetAttribute ( attr )
2273         int        attr
2274         CODE:
2275                 int value;
2276                 RETVAL = newAV();
2277                 av_push(RETVAL,newSViv(SDL_GL_GetAttribute(attr, &value)));
2278                 av_push(RETVAL,newSViv(value));
2279         OUTPUT:
2280                 RETVAL
2281
2282 void
2283 GLSwapBuffers ()
2284         CODE:
2285                 SDL_GL_SwapBuffers ();
2286
2287
2288 int
2289 BigEndian ()
2290         CODE:
2291                 RETVAL = (SDL_BYTEORDER == SDL_BIG_ENDIAN);
2292         OUTPUT:
2293                 RETVAL
2294
2295 int
2296 NumJoysticks ()
2297         CODE:
2298                 RETVAL = SDL_NumJoysticks();
2299         OUTPUT:
2300                 RETVAL
2301
2302 char *
2303 JoystickName ( index )
2304         int index
2305         CODE:
2306                 RETVAL = (char*)SDL_JoystickName(index);
2307         OUTPUT:
2308                 RETVAL
2309
2310 SDL_Joystick *
2311 JoystickOpen ( index ) 
2312         int index
2313         CODE:
2314                 RETVAL = SDL_JoystickOpen(index);
2315         OUTPUT:
2316                 RETVAL
2317
2318 int
2319 JoystickOpened ( index )
2320         int index
2321         CODE:
2322                 RETVAL = SDL_JoystickOpened(index);
2323         OUTPUT:
2324                 RETVAL
2325
2326 int
2327 JoystickIndex ( joystick )
2328         SDL_Joystick *joystick
2329         CODE:
2330                 RETVAL = SDL_JoystickIndex(joystick);
2331         OUTPUT:
2332                 RETVAL
2333
2334 int
2335 JoystickNumAxes ( joystick )
2336         SDL_Joystick *joystick
2337         CODE:
2338                 RETVAL = SDL_JoystickNumAxes(joystick);
2339         OUTPUT:
2340                 RETVAL
2341
2342 int
2343 JoystickNumBalls ( joystick )
2344         SDL_Joystick *joystick
2345         CODE:
2346                 RETVAL = SDL_JoystickNumBalls(joystick);
2347         OUTPUT:
2348                 RETVAL
2349
2350 int
2351 JoystickNumHats ( joystick )
2352         SDL_Joystick *joystick
2353         CODE:
2354                 RETVAL = SDL_JoystickNumHats(joystick);
2355         OUTPUT:
2356                 RETVAL
2357
2358 int
2359 JoystickNumButtons ( joystick )
2360         SDL_Joystick *joystick
2361         CODE:
2362                 RETVAL = SDL_JoystickNumButtons(joystick);
2363         OUTPUT:
2364                 RETVAL
2365
2366 void
2367 JoystickUpdate ()
2368         CODE:
2369                 SDL_JoystickUpdate();
2370
2371 Sint16
2372 JoystickGetAxis ( joystick, axis )
2373         SDL_Joystick *joystick
2374         int axis
2375         CODE:
2376                 RETVAL = SDL_JoystickGetAxis(joystick,axis);
2377         OUTPUT:
2378                 RETVAL
2379
2380 Uint8
2381 JoystickGetHat ( joystick, hat )
2382         SDL_Joystick *joystick
2383         int hat 
2384         CODE:
2385                 RETVAL = SDL_JoystickGetHat(joystick,hat);
2386         OUTPUT:
2387                 RETVAL
2388
2389 Uint8
2390 JoystickGetButton ( joystick, button)
2391         SDL_Joystick *joystick
2392         int button 
2393         CODE:
2394                 RETVAL = SDL_JoystickGetButton(joystick,button);
2395         OUTPUT:
2396                 RETVAL
2397
2398 AV *
2399 JoystickGetBall ( joystick, ball )
2400         SDL_Joystick *joystick
2401         int ball 
2402         CODE:
2403                 int success,dx,dy;
2404                 success = SDL_JoystickGetBall(joystick,ball,&dx,&dy);
2405                 RETVAL = newAV();
2406                 av_push(RETVAL,newSViv(success));
2407                 av_push(RETVAL,newSViv(dx));
2408                 av_push(RETVAL,newSViv(dy));
2409         OUTPUT:
2410                 RETVAL  
2411
2412 void
2413 JoystickClose ( joystick )
2414         SDL_Joystick *joystick
2415         CODE:
2416                 SDL_JoystickClose(joystick);
2417
2418 Sint16
2419 JoyAxisEventWhich ( e )
2420         SDL_Event *e
2421         CODE:
2422                 RETVAL = e->jaxis.which;
2423         OUTPUT:
2424                 RETVAL
2425
2426 Uint8
2427 JoyAxisEventAxis ( e )
2428         SDL_Event *e
2429         CODE:
2430                 RETVAL = e->jaxis.axis;
2431         OUTPUT:
2432                 RETVAL
2433
2434 Sint16
2435 JoyAxisEventValue ( e )
2436         SDL_Event *e
2437         CODE:
2438                 RETVAL = e->jaxis.value;
2439         OUTPUT:
2440                 RETVAL
2441
2442 Uint8
2443 JoyButtonEventWhich ( e )
2444         SDL_Event *e
2445         CODE:
2446                 RETVAL = e->jbutton.which;
2447         OUTPUT:
2448                 RETVAL
2449
2450 Uint8
2451 JoyButtonEventButton ( e )
2452         SDL_Event *e
2453         CODE:
2454                 RETVAL = e->jbutton.button;
2455         OUTPUT:
2456                 RETVAL
2457
2458 Uint8
2459 JoyButtonEventState ( e )
2460         SDL_Event *e
2461         CODE:
2462                 RETVAL = e->jbutton.state;
2463         OUTPUT:
2464                 RETVAL
2465         
2466 Uint8
2467 JoyHatEventWhich ( e )
2468         SDL_Event *e
2469         CODE:
2470                 RETVAL = e->jhat.which;
2471         OUTPUT:
2472                 RETVAL
2473
2474 Uint8
2475 JoyHatEventHat ( e )
2476         SDL_Event *e
2477         CODE:
2478                 RETVAL = e->jhat.hat;
2479         OUTPUT:
2480                 RETVAL
2481
2482 Uint8
2483 JoyHatEventValue ( e )
2484         SDL_Event *e
2485         CODE:
2486                 RETVAL = e->jhat.value;
2487         OUTPUT:
2488                 RETVAL
2489
2490 Uint8
2491 JoyBallEventWhich ( e )
2492         SDL_Event *e
2493         CODE: 
2494                 RETVAL = e->jball.which;
2495         OUTPUT:
2496                 RETVAL
2497
2498 Uint8
2499 JoyBallEventBall ( e )
2500         SDL_Event *e
2501         CODE:
2502                 RETVAL = e->jball.ball;
2503         OUTPUT:
2504                 RETVAL
2505
2506 Sint16
2507 JoyBallEventXrel ( e )
2508         SDL_Event *e
2509         CODE:
2510                 RETVAL = e->jball.xrel;
2511         OUTPUT:
2512                 RETVAL
2513
2514 Sint16
2515 JoyBallEventYrel ( e )
2516         SDL_Event *e
2517         CODE:
2518                 RETVAL = e->jball.yrel;
2519         OUTPUT:
2520                 RETVAL
2521
2522 void
2523 SetClipRect ( surface, rect )
2524         SDL_Surface *surface
2525         SDL_Rect *rect
2526         CODE:
2527                 SDL_SetClipRect(surface,rect);
2528         
2529 SDL_Rect*
2530 GetClipRect ( surface )
2531         SDL_Surface *surface
2532         CODE:
2533                 RETVAL = (SDL_Rect*) safemalloc(sizeof(SDL_Rect));
2534                 SDL_GetClipRect(surface,RETVAL);
2535         OUTPUT:
2536                 RETVAL
2537
2538
2539 #ifdef HAVE_SDL_NET
2540
2541 int
2542 NetInit ()
2543         CODE:
2544                 RETVAL = SDLNet_Init();
2545         OUTPUT:
2546                 RETVAL
2547
2548 void
2549 NetQuit ()
2550         CODE:
2551                 SDLNet_Quit();
2552
2553 IPaddress*
2554 NetNewIPaddress ( host, port )
2555         Uint32 host
2556         Uint16 port
2557         CODE:
2558                 RETVAL = (IPaddress*) safemalloc(sizeof(IPaddress));
2559                 RETVAL->host = host;
2560                 RETVAL->port = port;
2561         OUTPUT:
2562                 RETVAL
2563
2564 Uint32
2565 NetIPaddressHost ( ip )
2566         IPaddress *ip
2567         CODE:
2568                 RETVAL = ip->host;
2569         OUTPUT:
2570                 RETVAL
2571
2572 Uint16
2573 NetIPaddressPort ( ip )
2574         IPaddress *ip
2575         CODE:
2576                 RETVAL = ip->port;
2577         OUTPUT:
2578                 RETVAL
2579
2580 void
2581 NetFreeIPaddress ( ip )
2582         IPaddress *ip
2583         CODE:
2584                 safefree(ip);
2585
2586 const char*
2587 NetResolveIP ( address )
2588         IPaddress *address
2589         CODE:
2590                 RETVAL = SDLNet_ResolveIP(address);
2591         OUTPUT:
2592                 RETVAL
2593
2594 int
2595 NetResolveHost ( address, host, port )
2596         IPaddress *address
2597         const char *host
2598         Uint16 port
2599         CODE:
2600                 RETVAL = SDLNet_ResolveHost(address,host,port);
2601         OUTPUT:
2602                 RETVAL
2603         
2604 TCPsocket
2605 NetTCPOpen ( ip )
2606         IPaddress *ip
2607         CODE:
2608                 RETVAL = SDLNet_TCP_Open(ip);
2609         OUTPUT:
2610                 RETVAL
2611
2612 TCPsocket
2613 NetTCPAccept ( server )
2614         TCPsocket server
2615         CODE:
2616                 RETVAL = SDLNet_TCP_Accept(server);
2617         OUTPUT:
2618                 RETVAL
2619
2620 IPaddress*
2621 NetTCPGetPeerAddress ( sock )
2622         TCPsocket sock
2623         CODE:
2624                 RETVAL = SDLNet_TCP_GetPeerAddress(sock);
2625         OUTPUT:
2626                 RETVAL
2627
2628 int
2629 NetTCPSend ( sock, data, len  )
2630         TCPsocket sock
2631         void *data
2632         int len
2633         CODE:
2634                 RETVAL = SDLNet_TCP_Send(sock,data,len);
2635         OUTPUT:
2636                 RETVAL
2637
2638 AV*
2639 NetTCPRecv ( sock, maxlen )
2640         TCPsocket sock
2641         int maxlen
2642         CODE:
2643                 int status;
2644                 void *buffer;
2645                 buffer = safemalloc(maxlen);
2646                 RETVAL = newAV();
2647                 status = SDLNet_TCP_Recv(sock,buffer,maxlen);
2648                 av_push(RETVAL,newSViv(status));
2649                 av_push(RETVAL,newSVpvn((char*)buffer,maxlen));
2650         OUTPUT:
2651                 RETVAL  
2652         
2653 void
2654 NetTCPClose ( sock )
2655         TCPsocket sock
2656         CODE:
2657                 SDLNet_TCP_Close(sock);
2658
2659 UDPpacket*
2660 NetAllocPacket ( size )
2661         int size
2662         CODE:
2663                 RETVAL = SDLNet_AllocPacket(size);
2664         OUTPUT:
2665                 RETVAL
2666
2667 UDPpacket**
2668 NetAllocPacketV ( howmany, size )
2669         int howmany
2670         int size
2671         CODE:
2672                 RETVAL = SDLNet_AllocPacketV(howmany,size);
2673         OUTPUT:
2674                 RETVAL
2675
2676 int
2677 NetResizePacket ( packet, newsize )
2678         UDPpacket *packet
2679         int newsize
2680         CODE:
2681                 RETVAL = SDLNet_ResizePacket(packet,newsize);
2682         OUTPUT:
2683                 RETVAL
2684
2685 void
2686 NetFreePacket ( packet )
2687         UDPpacket *packet
2688         CODE:
2689                 SDLNet_FreePacket(packet);
2690
2691 void
2692 NetFreePacketV ( packet )
2693         UDPpacket **packet
2694         CODE:
2695                 SDLNet_FreePacketV(packet);
2696
2697 UDPsocket
2698 NetUDPOpen ( port )
2699         Uint16 port
2700         CODE:
2701                 RETVAL = SDLNet_UDP_Open(port);
2702         OUTPUT:
2703                 RETVAL
2704
2705 int
2706 NetUDPBind ( sock, channel, address )
2707         UDPsocket sock
2708         int channel
2709         IPaddress *address
2710         CODE:
2711                 RETVAL = SDLNet_UDP_Bind(sock,channel,address);
2712         OUTPUT:
2713                 RETVAL
2714
2715 void
2716 NetUDPUnbind ( sock, channel )
2717         UDPsocket sock
2718         int channel
2719         CODE:
2720                 SDLNet_UDP_Unbind(sock,channel);
2721
2722 IPaddress*
2723 NetUDPGetPeerAddress ( sock, channel )
2724         UDPsocket sock
2725         int channel
2726         CODE:
2727                 RETVAL = SDLNet_UDP_GetPeerAddress(sock,channel);
2728         OUTPUT:
2729                 RETVAL
2730
2731 int
2732 NetUDPSendV ( sock, packets, npackets )
2733         UDPsocket sock
2734         UDPpacket **packets
2735         int npackets
2736         CODE:
2737                 RETVAL = SDLNet_UDP_SendV(sock,packets,npackets);
2738         OUTPUT:
2739                 RETVAL
2740
2741 int
2742 NetUDPSend ( sock, channel, packet )
2743         UDPsocket sock
2744         int channel
2745         UDPpacket *packet 
2746         CODE:
2747                 RETVAL = SDLNet_UDP_Send(sock,channel,packet);
2748         OUTPUT:
2749                 RETVAL
2750
2751 int
2752 NetUDPRecvV ( sock, packets )
2753         UDPsocket sock
2754         UDPpacket **packets
2755         CODE:
2756                 RETVAL = SDLNet_UDP_RecvV(sock,packets);
2757         OUTPUT:
2758                 RETVAL
2759
2760 int
2761 NetUDPRecv ( sock, packet )
2762         UDPsocket sock
2763         UDPpacket *packet
2764         CODE:
2765                 RETVAL = SDLNet_UDP_Recv(sock,packet);
2766         OUTPUT:
2767                 RETVAL
2768
2769 void
2770 NetUDPClose ( sock )
2771         UDPsocket sock
2772         CODE:
2773                 SDLNet_UDP_Close(sock);
2774
2775 SDLNet_SocketSet
2776 NetAllocSocketSet ( maxsockets )
2777         int maxsockets
2778         CODE:
2779                 RETVAL = SDLNet_AllocSocketSet(maxsockets);
2780         OUTPUT:
2781                 RETVAL
2782
2783 int
2784 NetTCP_AddSocket ( set, sock )
2785         SDLNet_SocketSet set
2786         TCPsocket sock
2787         CODE:
2788                 RETVAL = SDLNet_TCP_AddSocket(set,sock);
2789         OUTPUT:
2790                 RETVAL
2791
2792 int
2793 NetUDP_AddSocket ( set, sock )
2794         SDLNet_SocketSet set
2795         UDPsocket sock
2796         CODE:
2797                 RETVAL = SDLNet_UDP_AddSocket(set,sock);
2798         OUTPUT:
2799                 RETVAL
2800
2801 int
2802 NetTCP_DelSocket ( set, sock )
2803         SDLNet_SocketSet set
2804         TCPsocket sock
2805         CODE:
2806                 RETVAL = SDLNet_TCP_DelSocket(set,sock);
2807         OUTPUT:
2808                 RETVAL
2809
2810 int
2811 NetUDP_DelSocket ( set, sock )
2812         SDLNet_SocketSet set
2813         UDPsocket sock
2814         CODE:
2815                 RETVAL = SDLNet_UDP_DelSocket(set,sock);
2816         OUTPUT:
2817                 RETVAL
2818
2819 int
2820 NetCheckSockets ( set, timeout )
2821         SDLNet_SocketSet set
2822         Uint32 timeout
2823         CODE:
2824                 RETVAL = SDLNet_CheckSockets(set,timeout);
2825         OUTPUT:
2826                 RETVAL
2827
2828 int
2829 NetSocketReady ( sock )
2830         SDLNet_GenericSocket sock
2831         CODE:
2832                 RETVAL = SDLNet_SocketReady(sock);
2833         OUTPUT:
2834                 RETVAL
2835
2836 void
2837 NetFreeSocketSet ( set )
2838         SDLNet_SocketSet set
2839         CODE:
2840                 SDLNet_FreeSocketSet(set);
2841
2842 void
2843 NetWrite16 ( value, area )
2844         Uint16 value
2845         void *area
2846         CODE:
2847                 SDLNet_Write16(value,area);
2848
2849 void
2850 NetWrite32 ( value, area )
2851         Uint32 value
2852         void *area
2853         CODE:
2854                 SDLNet_Write32(value,area);
2855         
2856 Uint16
2857 NetRead16 ( area )
2858         void *area
2859         CODE:
2860                 RETVAL = SDLNet_Read16(area);
2861         OUTPUT:
2862                 RETVAL
2863
2864 Uint32
2865 NetRead32 ( area )
2866         void *area
2867         CODE:
2868                 RETVAL = SDLNet_Read32(area);
2869         OUTPUT:
2870                 RETVAL
2871
2872 #endif 
2873
2874 #ifdef HAVE_SDL_TTF
2875
2876 int
2877 TTFInit ()
2878         CODE:
2879                 RETVAL = TTF_Init();
2880         OUTPUT:
2881                 RETVAL
2882
2883 void
2884 TTFQuit ()
2885         CODE:
2886                 TTF_Quit();
2887
2888 TTF_Font*
2889 TTFOpenFont ( file, ptsize )
2890         char *file
2891         int ptsize
2892         CODE:
2893                 RETVAL = TTF_OpenFont(file,ptsize);
2894         OUTPUT:
2895                 RETVAL
2896
2897 int
2898 TTFGetFontStyle ( font )
2899         TTF_Font *font
2900         CODE:
2901                 RETVAL = TTF_GetFontStyle(font);
2902         OUTPUT:
2903                 RETVAL
2904
2905 void
2906 TTFSetFontStyle ( font, style )
2907         TTF_Font *font
2908         int style
2909         CODE:
2910                 TTF_SetFontStyle(font,style);
2911         
2912 int
2913 TTFFontHeight ( font )
2914         TTF_Font *font
2915         CODE:
2916                 RETVAL = TTF_FontHeight(font);
2917         OUTPUT:
2918                 RETVAL
2919
2920 int
2921 TTFFontAscent ( font )
2922         TTF_Font *font
2923         CODE:
2924                 RETVAL = TTF_FontAscent(font);
2925         OUTPUT:
2926                 RETVAL
2927
2928 int
2929 TTFFontDescent ( font )
2930         TTF_Font *font
2931         CODE:
2932                 RETVAL = TTF_FontDescent(font);
2933         OUTPUT:
2934                 RETVAL
2935
2936 int
2937 TTFFontLineSkip ( font )
2938         TTF_Font *font
2939         CODE:
2940                 RETVAL = TTF_FontLineSkip(font);
2941         OUTPUT:
2942                 RETVAL
2943
2944 AV*
2945 TTFGlyphMetrics ( font, ch )
2946         TTF_Font *font
2947         Uint16 ch
2948         CODE:
2949                 int minx, miny, maxx, maxy, advance;
2950                 RETVAL = newAV();
2951                 TTF_GlyphMetrics(font, ch, &minx, &miny, &maxx, &maxy, &advance);
2952                 av_push(RETVAL,newSViv(minx));
2953                 av_push(RETVAL,newSViv(miny));
2954                 av_push(RETVAL,newSViv(maxx));
2955                 av_push(RETVAL,newSViv(maxy));
2956                 av_push(RETVAL,newSViv(advance));
2957         OUTPUT:
2958                 RETVAL
2959
2960 AV*
2961 TTFSizeText ( font, text )
2962         TTF_Font *font
2963         char *text
2964         CODE:
2965                 int w,h;
2966                 RETVAL = newAV();
2967                 TTF_SizeText(font,text,&w,&h);
2968                 av_push(RETVAL,newSViv(w));
2969                 av_push(RETVAL,newSViv(h));
2970         OUTPUT:
2971                 RETVAL
2972
2973 AV*
2974 TTFSizeUTF8 ( font, text )
2975         TTF_Font *font
2976         char *text
2977         CODE:
2978                 int w,h;
2979                 RETVAL = newAV();
2980                 TTF_SizeUTF8(font,text,&w,&h);
2981                 av_push(RETVAL,newSViv(w));
2982                 av_push(RETVAL,newSViv(h));
2983         OUTPUT:
2984                 RETVAL
2985
2986 AV*
2987 TTFSizeUNICODE ( font, text )
2988         TTF_Font *font
2989         const Uint16 *text
2990         CODE:
2991                 int w,h;
2992                 RETVAL = newAV();
2993                 TTF_SizeUNICODE(font,text,&w,&h);
2994                 av_push(RETVAL,newSViv(w));
2995                 av_push(RETVAL,newSViv(h));
2996         OUTPUT:
2997                 RETVAL
2998
2999 SDL_Surface*
3000 TTFRenderTextSolid ( font, text, fg )
3001         TTF_Font *font
3002         char *text
3003         SDL_Color *fg
3004         CODE:
3005                 RETVAL = TTF_RenderText_Solid(font,text,*fg);
3006         OUTPUT:
3007                 RETVAL
3008
3009 SDL_Surface*
3010 TTFRenderUTF8Solid ( font, text, fg )
3011         TTF_Font *font
3012         char *text
3013         SDL_Color *fg
3014         CODE:
3015                 RETVAL = TTF_RenderUTF8_Solid(font,text,*fg);
3016         OUTPUT:
3017                 RETVAL
3018
3019 SDL_Surface*
3020 TTFRenderUNICODESolid ( font, text, fg )
3021         TTF_Font *font
3022         const Uint16 *text
3023         SDL_Color *fg
3024         CODE:
3025                 RETVAL = TTF_RenderUNICODE_Solid(font,text,*fg);
3026         OUTPUT:
3027                 RETVAL
3028
3029 SDL_Surface*
3030 TTFRenderGlyphSolid ( font, ch, fg )
3031         TTF_Font *font
3032         Uint16 ch
3033         SDL_Color *fg
3034         CODE:
3035                 RETVAL = TTF_RenderGlyph_Solid(font,ch,*fg);
3036         OUTPUT:
3037                 RETVAL
3038
3039 SDL_Surface*
3040 TTFRenderTextShaded ( font, text, fg, bg )
3041         TTF_Font *font
3042         char *text
3043         SDL_Color *fg
3044         SDL_Color *bg
3045         CODE:
3046                 RETVAL = TTF_RenderText_Shaded(font,text,*fg,*bg);
3047         OUTPUT:
3048                 RETVAL
3049
3050 SDL_Surface*
3051 TTFRenderUTF8Shaded( font, text, fg, bg )
3052         TTF_Font *font
3053         char *text
3054         SDL_Color *fg
3055         SDL_Color *bg
3056         CODE:
3057                 RETVAL = TTF_RenderUTF8_Shaded(font,text,*fg,*bg);
3058         OUTPUT:
3059                 RETVAL
3060
3061 SDL_Surface*
3062 TTFRenderUNICODEShaded( font, text, fg, bg )
3063         TTF_Font *font
3064         const Uint16 *text
3065         SDL_Color *fg
3066         SDL_Color *bg
3067         CODE:
3068                 RETVAL = TTF_RenderUNICODE_Shaded(font,text,*fg,*bg);
3069         OUTPUT:
3070                 RETVAL
3071
3072 SDL_Surface*
3073 TTFRenderGlyphShaded ( font, ch, fg, bg )
3074         TTF_Font *font
3075         Uint16 ch
3076         SDL_Color *fg
3077         SDL_Color *bg
3078         CODE:
3079                 RETVAL = TTF_RenderGlyph_Shaded(font,ch,*fg,*bg);
3080         OUTPUT:
3081                 RETVAL
3082
3083 SDL_Surface*
3084 TTFRenderTextBlended( font, text, fg )
3085         TTF_Font *font
3086         char *text
3087         SDL_Color *fg
3088         CODE:
3089                 RETVAL = TTF_RenderText_Blended(font,text,*fg);
3090         OUTPUT:
3091                 RETVAL
3092
3093 SDL_Surface*
3094 TTFRenderUTF8Blended( font, text, fg )
3095         TTF_Font *font
3096         char *text
3097         SDL_Color *fg
3098         CODE:
3099                 RETVAL = TTF_RenderUTF8_Blended(font,text,*fg);
3100         OUTPUT:
3101                 RETVAL
3102
3103 SDL_Surface*
3104 TTFRenderUNICODEBlended( font, text, fg )
3105         TTF_Font *font
3106         const Uint16 *text
3107         SDL_Color *fg
3108         CODE:
3109                 RETVAL = TTF_RenderUNICODE_Blended(font,text,*fg);
3110         OUTPUT:
3111                 RETVAL
3112
3113 SDL_Surface*
3114 TTFRenderGlyphBlended( font, ch, fg )
3115         TTF_Font *font
3116         Uint16 ch
3117         SDL_Color *fg
3118         CODE:
3119                 RETVAL = TTF_RenderGlyph_Blended(font,ch,*fg);
3120         OUTPUT:
3121                 RETVAL
3122
3123 void
3124 TTFCloseFont ( font )
3125         TTF_Font *font
3126         CODE:
3127                 TTF_CloseFont(font);
3128                 font=NULL; //to be safe http://sdl.beuc.net/sdl.wiki/SDL_ttf_copy_Functions_Management_TTF_CloseFont
3129
3130 SDL_Surface*
3131 TTFPutString ( font, mode, surface, x, y, fg, bg, text )
3132         TTF_Font *font
3133         int mode
3134         SDL_Surface *surface
3135         int x
3136         int y
3137         SDL_Color *fg
3138         SDL_Color *bg
3139         char *text
3140         CODE:
3141                 SDL_Surface *img;
3142                 SDL_Rect dest;
3143                 int w,h;
3144                 dest.x = x;
3145                 dest.y = y;
3146                 RETVAL = NULL;
3147                 switch (mode) {
3148                         case TEXT_SOLID:
3149                                 img = TTF_RenderText_Solid(font,text,*fg);
3150                                 TTF_SizeText(font,text,&w,&h);
3151                                 dest.w = w;
3152                                 dest.h = h;
3153                                 break;
3154                         case TEXT_SHADED:
3155                                 img = TTF_RenderText_Shaded(font,text,*fg,*bg);
3156                                 TTF_SizeText(font,text,&w,&h);
3157                                 dest.w = w;
3158                                 dest.h = h;
3159                                 break;
3160                         case TEXT_BLENDED:
3161                                 img = TTF_RenderText_Blended(font,text,*fg);
3162                                 TTF_SizeText(font,text,&w,&h);
3163                                 dest.w = w;
3164                                 dest.h = h;
3165                                 break;
3166                         case UTF8_SOLID:
3167                                 img = TTF_RenderUTF8_Solid(font,text,*fg);
3168                                 TTF_SizeUTF8(font,text,&w,&h);
3169                                 dest.w = w;
3170                                 dest.h = h;
3171                                 break;
3172                         case UTF8_SHADED:
3173                                 img = TTF_RenderUTF8_Shaded(font,text,*fg,*bg);
3174                                 TTF_SizeUTF8(font,text,&w,&h);
3175                                 dest.w = w;
3176                                 dest.h = h;
3177                                 break;
3178                         case UTF8_BLENDED:
3179                                 img = TTF_RenderUTF8_Blended(font,text,*fg);
3180                                 TTF_SizeUTF8(font,text,&w,&h);
3181                                 dest.w = w;
3182                                 dest.h = h;
3183                                 break;
3184                         case UNICODE_SOLID:
3185                                 img = TTF_RenderUNICODE_Solid(font,(Uint16*)text,*fg);
3186                                 TTF_SizeUNICODE(font,(Uint16*)text,&w,&h);
3187                                 dest.w = w;
3188                                 dest.h = h;
3189                                 break;
3190                         case UNICODE_SHADED:
3191                                 img = TTF_RenderUNICODE_Shaded(font,(Uint16*)text,*fg,*bg);
3192                                 TTF_SizeUNICODE(font,(Uint16*)text,&w,&h);
3193                                 dest.w = w;
3194                                 dest.h = h;
3195                                 break;
3196                         case UNICODE_BLENDED:
3197                                 img = TTF_RenderUNICODE_Blended(font,(Uint16*)text,*fg);
3198                                 TTF_SizeUNICODE(font,(Uint16*)text,&w,&h);
3199                                 dest.w = w;
3200                                 dest.h = h;
3201                                 break;
3202                         default:
3203                                 img = TTF_RenderText_Shaded(font,text,*fg,*bg);
3204                                 TTF_SizeText(font,text,&w,&h);
3205                                 dest.w = w;
3206                                 dest.h = h;
3207                 }
3208                 if ( img && img->format && img->format->palette ) {
3209                         SDL_Color *c = &img->format->palette->colors[0];
3210                         Uint32 key = SDL_MapRGB( img->format, c->r, c->g, c->b );
3211                         SDL_SetColorKey(img,SDL_SRCCOLORKEY,key );
3212                         if (0 > SDL_BlitSurface(img,NULL,surface,&dest)) {
3213                                 SDL_FreeSurface(img);
3214                                 RETVAL = NULL;  
3215                         } else {
3216                                 RETVAL = img;
3217                         }
3218                 }
3219         OUTPUT:
3220                 RETVAL
3221
3222 #endif
3223
3224 SDL_Overlay*
3225 CreateYUVOverlay ( width, height, format, display )
3226         int width
3227         int height
3228         Uint32 format
3229         SDL_Surface *display
3230         CODE:
3231                 RETVAL = SDL_CreateYUVOverlay ( width, height, format, display );
3232         OUTPUT:
3233                 RETVAL
3234
3235 int
3236 LockYUVOverlay ( overlay )
3237         SDL_Overlay *overlay
3238         CODE:
3239                 RETVAL = SDL_LockYUVOverlay(overlay);
3240         OUTPUT:
3241                 RETVAL
3242
3243 void
3244 UnlockYUVOverlay ( overlay )
3245         SDL_Overlay *overlay
3246         CODE:
3247                 SDL_UnlockYUVOverlay(overlay);
3248
3249 int
3250 DisplayYUVOverlay ( overlay, dstrect )
3251         SDL_Overlay *overlay
3252         SDL_Rect *dstrect
3253         CODE:
3254                 RETVAL = SDL_DisplayYUVOverlay ( overlay, dstrect );
3255         OUTPUT:
3256                 RETVAL
3257
3258 void
3259 FreeYUVOverlay ( overlay )
3260         SDL_Overlay *overlay
3261         CODE:
3262                 SDL_FreeYUVOverlay ( overlay );
3263
3264 Uint32
3265 OverlayFormat ( overlay, ... )
3266         SDL_Overlay *overlay
3267         CODE:
3268                 if ( items > 1 ) 
3269                         overlay->format = SvIV(ST(1));
3270                 RETVAL = overlay->format;
3271         OUTPUT:
3272                 RETVAL
3273
3274 int 
3275 OverlayW ( overlay, ... )
3276         SDL_Overlay *overlay
3277         CODE:
3278                 if ( items > 1 ) 
3279                         overlay->w = SvIV(ST(1));
3280                 RETVAL = overlay->w;
3281         OUTPUT:
3282                 RETVAL
3283
3284 int
3285 OverlayH ( overlay, ... )
3286         SDL_Overlay *overlay
3287         CODE:
3288                 if ( items > 1 )
3289                         overlay->h = SvIV(ST(1));
3290                 RETVAL = overlay->h;
3291         OUTPUT:
3292                 RETVAL 
3293
3294 int
3295 OverlayPlanes ( overlay, ... )
3296         SDL_Overlay *overlay
3297         CODE:
3298                 if ( items > 1 )
3299                         overlay->planes = SvIV(ST(1));
3300                 RETVAL = overlay->planes;
3301         OUTPUT:
3302                 RETVAL
3303
3304 Uint32
3305 OverlayHW ( overlay )
3306         SDL_Overlay *overlay
3307         CODE:
3308                 RETVAL = overlay->hw_overlay;
3309         OUTPUT:
3310                 RETVAL
3311
3312 Uint16*
3313 OverlayPitches ( overlay )
3314         SDL_Overlay *overlay
3315         CODE:
3316                 RETVAL = overlay->pitches;
3317         OUTPUT:
3318                 RETVAL
3319
3320 Uint8**
3321 OverlayPixels ( overlay )
3322         SDL_Overlay *overlay
3323         CODE:
3324                 RETVAL = overlay->pixels;
3325         OUTPUT:
3326                 RETVAL
3327
3328 int
3329 WMToggleFullScreen ( surface )
3330         SDL_Surface *surface
3331         CODE:
3332                 RETVAL = SDL_WM_ToggleFullScreen(surface);
3333         OUTPUT:
3334                 RETVAL
3335
3336 Uint32
3337 WMGrabInput ( mode )
3338         Uint32 mode
3339         CODE:
3340                 RETVAL = SDL_WM_GrabInput(mode);
3341         OUTPUT:
3342                 RETVAL
3343
3344 int
3345 WMIconifyWindow ()
3346         CODE:
3347                 RETVAL = SDL_WM_IconifyWindow();
3348         OUTPUT:
3349                 RETVAL
3350
3351 int
3352 ResizeEventW ( e )
3353         SDL_Event *e
3354         CODE:
3355                 RETVAL = e->resize.w;
3356         OUTPUT:
3357                 RETVAL
3358
3359 int
3360 ResizeEventH ( e )
3361         SDL_Event *e
3362         CODE:
3363                 RETVAL = e->resize.h;
3364         OUTPUT:
3365                 RETVAL
3366
3367 char*
3368 AudioDriverName ()
3369         CODE:
3370                 char name[32];
3371                 RETVAL = SDL_AudioDriverName(name,32);
3372         OUTPUT:
3373                 RETVAL
3374
3375 Uint32
3376 GetKeyState ( k )
3377         SDLKey k
3378         CODE:
3379                 if (k >= SDLK_LAST) Perl_croak (aTHX_ "Key out of range");      
3380                 RETVAL = SDL_GetKeyState(NULL)[k];
3381         OUTPUT:
3382                 RETVAL
3383
3384 #ifdef HAVE_SMPEG
3385
3386 SMPEG_Info *
3387 NewSMPEGInfo()
3388         CODE:   
3389                 RETVAL = (SMPEG_Info *) safemalloc (sizeof(SMPEG_Info));
3390         OUTPUT:
3391                 RETVAL
3392
3393 void
3394 FreeSMPEGInfo ( info )
3395         SMPEG_Info *info
3396         CODE:   
3397                 safefree(info);
3398
3399 int
3400 SMPEGInfoHasAudio ( info )
3401         SMPEG_Info* info
3402         CODE:
3403                 RETVAL = info->has_audio;
3404         OUTPUT:
3405                 RETVAL
3406
3407 int
3408 SMPEGInfoHasVideo ( info )
3409         SMPEG_Info* info
3410         CODE:
3411                 RETVAL = info->has_video;
3412         OUTPUT:
3413                 RETVAL
3414
3415 int
3416 SMPEGInfoWidth ( info )
3417         SMPEG_Info* info
3418         CODE:
3419                 RETVAL = info->width;
3420         OUTPUT:
3421                 RETVAL
3422
3423 int
3424 SMPEGInfoHeight ( info )
3425         SMPEG_Info* info
3426         CODE:
3427                 RETVAL = info->height;
3428         OUTPUT:
3429                 RETVAL
3430
3431 int
3432 SMPEGInfoCurrentFrame ( info )
3433         SMPEG_Info* info
3434         CODE:
3435                 RETVAL = info->current_frame;
3436         OUTPUT:
3437                 RETVAL
3438
3439 double
3440 SMPEGInfoCurrentFPS ( info )
3441         SMPEG_Info* info
3442         CODE:
3443                 RETVAL = info->current_fps;
3444         OUTPUT:
3445                 RETVAL
3446
3447 int
3448 SMPEGInfoCurrentAudioFrame ( info )
3449         SMPEG_Info* info
3450         CODE:
3451                 RETVAL = info->audio_current_frame;
3452         OUTPUT:
3453                 RETVAL
3454
3455 int
3456 SMPEGInfoCurrentOffset ( info )
3457         SMPEG_Info* info
3458         CODE:
3459                 RETVAL = info->current_offset;
3460         OUTPUT:
3461                 RETVAL
3462
3463 int
3464 SMPEGInfoTotalSize ( info )
3465         SMPEG_Info* info
3466         CODE:
3467                 RETVAL = info->total_size;
3468         OUTPUT:
3469                 RETVAL
3470
3471 double
3472 SMPEGInfoCurrentTime ( info )
3473         SMPEG_Info* info
3474         CODE:
3475                 RETVAL = info->current_time;
3476         OUTPUT:
3477                 RETVAL
3478
3479 double
3480 SMPEGInfoTotalTime ( info )
3481         SMPEG_Info* info
3482         CODE:
3483                 RETVAL = info->total_time;
3484         OUTPUT:
3485                 RETVAL
3486
3487 char *
3488 SMPEGError ( mpeg )
3489         SMPEG* mpeg
3490         CODE:   
3491                 RETVAL = SMPEG_error(mpeg);
3492         OUTPUT:
3493                 RETVAL
3494
3495 SMPEG*
3496 NewSMPEG ( filename, info, use_audio )
3497         char* filename
3498         SMPEG_Info* info
3499         int use_audio
3500         CODE:   
3501 #ifdef HAVE_SDL_MIXER
3502                 RETVAL = SMPEG_new(filename,info,0);
3503 #else
3504                 RETVAL = SMPEG_new(filename,info,use_audio);
3505 #endif
3506         OUTPUT:
3507                 RETVAL
3508
3509 void
3510 FreeSMPEG ( mpeg )
3511         SMPEG* mpeg
3512         CODE:
3513                 SMPEG_delete(mpeg);
3514
3515 void
3516 SMPEGEnableAudio ( mpeg , flag )
3517         SMPEG* mpeg
3518         int flag
3519         CODE:   
3520                 SMPEG_enableaudio(mpeg,flag);
3521 #ifdef HAVE_SDL_MIXER
3522                 sdl_perl_use_smpeg_audio = flag;
3523 #endif
3524
3525 void
3526 SMPEGEnableVideo ( mpeg , flag )
3527         SMPEG* mpeg
3528         int flag
3529         CODE:   
3530                 SMPEG_enablevideo(mpeg,flag);
3531
3532 void
3533 SMPEGSetVolume ( mpeg , volume )
3534         SMPEG* mpeg
3535         int volume
3536         CODE:   
3537                 SMPEG_setvolume(mpeg,volume);
3538
3539 void
3540 SMPEGSetDisplay ( mpeg, dest, surfLock )
3541         SMPEG* mpeg
3542         SDL_Surface* dest
3543         SDL_mutex*  surfLock
3544         CODE:
3545                 SMPEG_setdisplay(mpeg,dest,surfLock,NULL);
3546
3547 void
3548 SMPEGScaleXY ( mpeg, w, h)
3549         SMPEG* mpeg
3550         int w
3551         int h
3552         CODE:
3553                 SMPEG_scaleXY(mpeg,w,h);
3554
3555 void
3556 SMPEGScale ( mpeg, scale )
3557         SMPEG* mpeg
3558         int scale
3559         CODE:
3560                 SMPEG_scale(mpeg,scale);
3561
3562 void
3563 SMPEGPlay ( mpeg )
3564         SMPEG* mpeg
3565         CODE:
3566                 SDL_AudioSpec audiofmt;
3567                 Uint16 format;
3568                 int freq, channels;
3569 #ifdef HAVE_SDL_MIXER
3570                 if  (sdl_perl_use_smpeg_audio ) {
3571                         SMPEG_enableaudio(mpeg, 0);
3572                         Mix_QuerySpec(&freq, &format, &channels);
3573                         audiofmt.format = format;
3574                         audiofmt.freq = freq;
3575                         audiofmt.channels = channels;
3576                         SMPEG_actualSpec(mpeg, &audiofmt);
3577                         Mix_HookMusic(SMPEG_playAudioSDL, mpeg);
3578                         SMPEG_enableaudio(mpeg, 1);
3579                 }
3580 #endif
3581                 SMPEG_play(mpeg);
3582
3583 SMPEGstatus
3584 SMPEGStatus ( mpeg )
3585         SMPEG* mpeg
3586         CODE:
3587                 RETVAL = SMPEG_status(mpeg);
3588         OUTPUT:
3589                 RETVAL
3590
3591 void
3592 SMPEGPause ( mpeg )
3593         SMPEG* mpeg
3594         CODE:
3595                 SMPEG_pause(mpeg);
3596
3597 void
3598 SMPEGLoop ( mpeg, repeat )
3599         SMPEG* mpeg
3600         int repeat
3601         CODE:
3602                 SMPEG_loop(mpeg,repeat);
3603
3604 void
3605 SMPEGStop ( mpeg )
3606         SMPEG* mpeg
3607         CODE:
3608                 SMPEG_stop(mpeg);
3609 #ifdef HAVE_SDL_MIXER
3610                 Mix_HookMusic(NULL, NULL);
3611 #endif
3612
3613 void
3614 SMPEGRewind ( mpeg )
3615         SMPEG* mpeg
3616         CODE:
3617                 SMPEG_rewind(mpeg);
3618
3619 void
3620 SMPEGSeek ( mpeg, bytes )
3621         SMPEG* mpeg
3622         int bytes
3623         CODE:
3624                 SMPEG_seek(mpeg,bytes);
3625
3626 void
3627 SMPEGSkip ( mpeg, seconds )
3628         SMPEG* mpeg
3629         float seconds
3630         CODE:
3631                 SMPEG_skip(mpeg,seconds);
3632
3633 void
3634 SMPEGSetDisplayRegion ( mpeg, rect )
3635         SMPEG* mpeg
3636         SDL_Rect* rect
3637         CODE:
3638                 SMPEG_setdisplayregion(mpeg,rect->x,rect->y,rect->w,rect->h);
3639
3640 void
3641 SMPEGRenderFrame ( mpeg, frame )
3642         SMPEG* mpeg
3643         int frame
3644         CODE:
3645                 SMPEG_renderFrame(mpeg,frame);
3646
3647 SMPEG_Info *
3648 SMPEGGetInfo ( mpeg )
3649         SMPEG* mpeg
3650         CODE:
3651                 RETVAL = (SMPEG_Info *) safemalloc (sizeof(SMPEG_Info));
3652                 SMPEG_getinfo(mpeg,RETVAL);
3653         OUTPUT:
3654                 RETVAL
3655         
3656
3657 #endif
3658
3659 #ifdef HAVE_SDL_GFX
3660
3661 SDL_Surface *
3662 GFXRotoZoom ( src, angle, zoom, smooth)
3663         SDL_Surface * src
3664         double angle
3665         double zoom
3666         int smooth
3667         CODE:
3668                 RETVAL = rotozoomSurface( src, angle, zoom, smooth);
3669         OUTPUT:
3670                 RETVAL
3671
3672 SDL_Surface *
3673 GFXZoom ( src, zoomx, zoomy, smooth)
3674         SDL_Surface *src
3675         double zoomx
3676         double zoomy
3677         int smooth
3678         CODE:
3679                 RETVAL = zoomSurface( src, zoomx, zoomy, smooth);
3680         OUTPUT:
3681                 RETVAL
3682
3683 int
3684 GFXPixelColor ( dst, x, y, color )
3685         SDL_Surface* dst
3686         Sint16 x
3687         Sint16 y
3688         Uint32 color
3689         CODE:
3690                 RETVAL = pixelColor( dst, x, y, color);
3691         OUTPUT:
3692                 RETVAL
3693
3694 int
3695 GFXPixelRGBA ( dst, x, y, r, g, b, a )
3696         SDL_Surface* dst
3697         Sint16 x
3698         Sint16 y
3699         Uint8 r
3700         Uint8 g
3701         Uint8 b
3702         Uint8 a
3703         CODE:
3704                 RETVAL = pixelRGBA( dst, x, y, r, g, b, a );
3705         OUTPUT:
3706                 RETVAL
3707
3708 int
3709 GFXHlineColor ( dst, x1, x2, y, color )
3710         SDL_Surface* dst
3711         Sint16 x1
3712         Sint16 x2
3713         Sint16 y
3714         Uint32 color
3715         CODE:
3716                 RETVAL = hlineColor( dst, x1, x2, y, color );
3717         OUTPUT:
3718                 RETVAL
3719
3720 int
3721 GFXHlineRGBA ( dst, x1, x2, y, r, g, b, a )
3722         SDL_Surface* dst
3723         Sint16 x1
3724         Sint16 x2
3725         Sint16 y
3726         Uint8 r
3727         Uint8 g
3728         Uint8 b
3729         Uint8 a
3730         CODE:
3731                 RETVAL = hlineRGBA( dst, x1, x2, y, r, g, b, a );
3732         OUTPUT:
3733                 RETVAL
3734
3735 int
3736 GFXVlineColor ( dst, x, y1, y2, color )
3737         SDL_Surface* dst
3738         Sint16 x
3739         Sint16 y1
3740         Sint16 y2
3741         Uint32 color
3742         CODE:
3743                 RETVAL = vlineColor( dst, x, y1, y2, color );
3744         OUTPUT:
3745                 RETVAL
3746
3747 int
3748 GFXVlineRGBA ( dst, x, y1, y2, r, g, b, a )
3749         SDL_Surface* dst
3750         Sint16 x
3751         Sint16 y1
3752         Sint16 y2
3753         Uint8 r
3754         Uint8 g
3755         Uint8 b
3756         Uint8 a
3757         CODE:
3758                 RETVAL = vlineRGBA( dst, x, y1, y2, r, g, b, a );
3759         OUTPUT:
3760                 RETVAL
3761
3762 int
3763 GFXRectangleColor ( dst, x1, y1, x2, y2, color )
3764         SDL_Surface* dst
3765         Sint16 x1
3766         Sint16 y1
3767         Sint16 x2
3768         Sint16 y2
3769         Uint32 color
3770         CODE:
3771                 RETVAL = rectangleColor( dst, x1, y1, x2, y2, color );
3772         OUTPUT:
3773                 RETVAL
3774
3775 int
3776 GFXRectangleRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3777         SDL_Surface* dst
3778         Sint16 x1
3779         Sint16 y1
3780         Sint16 x2
3781         Sint16 y2
3782         Uint8 r
3783         Uint8 g
3784         Uint8 b
3785         Uint8 a
3786         CODE:
3787                 RETVAL = rectangleRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3788         OUTPUT:
3789                 RETVAL
3790
3791 int
3792 GFXBoxColor ( dst, x1, y1, x2, y2, color )
3793         SDL_Surface* dst
3794         Sint16 x1
3795         Sint16 y1
3796         Sint16 x2
3797         Sint16 y2
3798         Uint32 color
3799         CODE:
3800                 RETVAL = boxColor( dst, x1, y1, x2, y2, color );
3801         OUTPUT:
3802                 RETVAL
3803
3804 int
3805 GFXBoxRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3806         SDL_Surface* dst;
3807         Sint16 x1
3808         Sint16 y1
3809         Sint16 x2
3810         Sint16 y2
3811         Uint8 r
3812         Uint8 g
3813         Uint8 b
3814         Uint8 a
3815         CODE:
3816                 RETVAL = boxRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3817         OUTPUT:
3818                 RETVAL
3819
3820 int
3821 GFXLineColor ( dst, x1, y1, x2, y2, color )
3822         SDL_Surface* dst
3823         Sint16 x1
3824         Sint16 y1
3825         Sint16 x2
3826         Sint16 y2
3827         Uint32 color
3828         CODE:
3829                 RETVAL = lineColor( dst, x1, y1, x2, y2, color );
3830         OUTPUT:
3831                 RETVAL
3832
3833 int
3834 GFXLineRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3835         SDL_Surface* dst
3836         Sint16 x1
3837         Sint16 y1
3838         Sint16 x2
3839         Sint16 y2
3840         Uint8 r
3841         Uint8 g
3842         Uint8 b
3843         Uint8 a
3844         CODE:
3845                 RETVAL = lineRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3846         OUTPUT:
3847                 RETVAL
3848
3849 int
3850 GFXAalineColor ( dst, x1, y1, x2, y2, color )
3851         SDL_Surface* dst
3852         Sint16 x1
3853         Sint16 y1
3854         Sint16 x2
3855         Sint16 y2
3856         Uint32 color
3857         CODE:
3858                 RETVAL = aalineColor( dst, x1, y1, x2, y2, color );
3859         OUTPUT:
3860                 RETVAL
3861
3862 int
3863 GFXAalineRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3864         SDL_Surface* dst
3865         Sint16 x1
3866         Sint16 y1
3867         Sint16 x2
3868         Sint16 y2
3869         Uint8 r
3870         Uint8 g
3871         Uint8 b
3872         Uint8 a
3873         CODE:
3874                 RETVAL = aalineRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3875         OUTPUT:
3876                 RETVAL
3877
3878 int
3879 GFXCircleColor ( dst, x, y, r, color )
3880         SDL_Surface* dst
3881         Sint16 x
3882         Sint16 y
3883         Sint16 r
3884         Uint32 color
3885         CODE:
3886                 RETVAL = circleColor( dst, x, y, r, color );
3887         OUTPUT:
3888                 RETVAL
3889
3890 int
3891 GFXCircleRGBA ( dst, x, y, rad, r, g, b, a )
3892         SDL_Surface* dst
3893         Sint16 x
3894         Sint16 y
3895         Sint16 rad
3896         Uint8 r
3897         Uint8 g
3898         Uint8 b
3899         Uint8 a
3900         CODE:
3901                 RETVAL = circleRGBA( dst, x, y, rad, r, g, b, a );
3902         OUTPUT:
3903                 RETVAL
3904
3905 int
3906 GFXAacircleColor ( dst, x, y, r, color )
3907         SDL_Surface* dst
3908         Sint16 x
3909         Sint16 y
3910         Sint16 r
3911         Uint32 color
3912         CODE:
3913                 RETVAL = aacircleColor( dst, x, y, r, color );
3914         OUTPUT:
3915                 RETVAL
3916
3917 int
3918 GFXAacircleRGBA ( dst, x, y, rad, r, g, b, a )
3919         SDL_Surface* dst
3920         Sint16 x
3921         Sint16 y
3922         Sint16 rad
3923         Uint8 r
3924         Uint8 g
3925         Uint8 b
3926         Uint8 a
3927         CODE:
3928                 RETVAL = aacircleRGBA( dst, x, y, rad, r, g, b, a );
3929         OUTPUT:
3930                 RETVAL
3931
3932 int
3933 GFXFilledCircleColor ( dst, x, y, r, color )
3934         SDL_Surface* dst
3935         Sint16 x
3936         Sint16 y
3937         Sint16 r
3938         Uint32 color
3939         CODE:
3940                 RETVAL = filledCircleColor( dst, x, y, r, color );
3941         OUTPUT:
3942                 RETVAL
3943
3944 int
3945 GFXFilledCircleRGBA ( dst, x, y, rad, r, g, b, a )
3946         SDL_Surface* dst
3947         Sint16 x
3948         Sint16 y
3949         Sint16 rad
3950         Uint8 r
3951         Uint8 g
3952         Uint8 b
3953         Uint8 a
3954         CODE:
3955                 RETVAL = filledCircleRGBA( dst, x, y, rad, r, g, b, a );
3956         OUTPUT:
3957                 RETVAL
3958
3959 int
3960 GFXEllipseColor ( dst, x, y, rx, ry, color )
3961         SDL_Surface* dst
3962         Sint16 x
3963         Sint16 y
3964         Sint16 rx
3965         Sint16 ry
3966         Uint32 color
3967         CODE:
3968                 RETVAL = ellipseColor( dst, x, y, rx, ry, color );
3969         OUTPUT:
3970                 RETVAL
3971
3972 int
3973 GFXEllipseRGBA ( dst, x, y, rx, ry, r, g, b, a )
3974         SDL_Surface* dst
3975         Sint16 x
3976         Sint16 y
3977         Sint16  rx
3978         Sint16 ry
3979         Uint8 r
3980         Uint8 g
3981         Uint8 b
3982         Uint8 a
3983         CODE:
3984                 RETVAL = ellipseRGBA( dst, x, y, rx, ry, r, g, b, a );
3985         OUTPUT:
3986                 RETVAL
3987
3988 int
3989 GFXAaellipseColor ( dst, xc, yc, rx, ry, color )
3990         SDL_Surface* dst
3991         Sint16 xc
3992         Sint16 yc
3993         Sint16 rx
3994         Sint16 ry
3995         Uint32 color
3996         CODE:
3997                 RETVAL = aaellipseColor( dst, xc, yc, rx, ry, color );
3998         OUTPUT:
3999                 RETVAL
4000
4001 int
4002 GFXAaellipseRGBA ( dst, x, y, rx, ry, r, g, b, a )
4003         SDL_Surface* dst
4004         Sint16 x
4005         Sint16 y
4006         Sint16 rx
4007         Sint16 ry
4008         Uint8 r
4009         Uint8 g
4010         Uint8 b
4011         Uint8 a
4012         CODE:
4013                 RETVAL = aaellipseRGBA( dst, x, y, rx, ry, r, g, b, a );
4014         OUTPUT:
4015                 RETVAL
4016
4017 int
4018 GFXFilledEllipseColor ( dst, x, y, rx, ry, color )
4019         SDL_Surface* dst
4020         Sint16 x
4021         Sint16 y
4022         Sint16 rx
4023         Sint16 ry
4024         Uint32 color
4025         CODE:
4026                 RETVAL = filledEllipseColor( dst, x, y, rx, ry, color );
4027         OUTPUT:
4028                 RETVAL
4029
4030 int
4031 GFXFilledEllipseRGBA ( dst, x, y, rx, ry, r, g, b, a )
4032         SDL_Surface* dst
4033         Sint16 x
4034         Sint16 y
4035         Sint16 rx
4036         Sint16 ry
4037         Uint8 r
4038         Uint8 g
4039         Uint8 b
4040         Uint8 a
4041         CODE:
4042                 RETVAL = filledEllipseRGBA( dst, x, y, rx, ry, r, g, b, a );
4043         OUTPUT:
4044                 RETVAL
4045
4046 int
4047 GFXFilledPieColor ( dst, x, y, rad, start, end, color )
4048         SDL_Surface* dst
4049         Sint16 x
4050         Sint16 y
4051         Sint16 rad
4052         Sint16 start
4053         Sint16 end
4054         Uint32 color
4055         CODE:
4056                 RETVAL = filledPieColor( dst, x, y, rad, start, end, color );
4057         OUTPUT:
4058                 RETVAL
4059
4060 int
4061 GFXFilledPieRGBA ( dst, x, y, rad, start, end, r, g, b, a )
4062         SDL_Surface* dst
4063         Sint16 x
4064         Sint16 y
4065         Sint16 rad
4066         Sint16 start
4067         Sint16 end
4068         Uint8 r
4069         Uint8 g
4070         Uint8 b
4071         Uint8 a
4072         CODE:
4073                 RETVAL = filledPieRGBA( dst, x, y, rad, start, end, r, g, b, a );
4074         OUTPUT:
4075                 RETVAL
4076
4077 int
4078 GFXPolygonColor ( dst, vx, vy, n, color )
4079         SDL_Surface* dst
4080         Sint16* vx
4081         Sint16* vy
4082         int n
4083         Uint32 color;
4084         CODE:
4085                 RETVAL = polygonColor( dst, vx, vy, n, color );
4086         OUTPUT:
4087                 RETVAL
4088
4089 int
4090 GFXPolygonRGBA ( dst, vx, vy, n, r, g, b, a )
4091         SDL_Surface* dst
4092         Sint16* vx
4093         Sint16* vy
4094         int n
4095         Uint8 r
4096         Uint8 g
4097         Uint8 b
4098         Uint8 a
4099         CODE:
4100                 RETVAL = polygonRGBA( dst, vx, vy, n, r, g, b, a );
4101         OUTPUT:
4102                 RETVAL
4103
4104 int
4105 GFXAapolygonColor ( dst, vx, vy, n, color )
4106         SDL_Surface* dst
4107         Sint16* vx
4108         Sint16* vy
4109         int n
4110         Uint32 color
4111         CODE:
4112                 RETVAL = aapolygonColor( dst, vx, vy, n, color );
4113         OUTPUT:
4114                 RETVAL
4115
4116 int
4117 GFXAapolygonRGBA ( dst, vx, vy, n, r, g, b, a )
4118         SDL_Surface* dst
4119         Sint16* vx
4120         Sint16* vy
4121         int n
4122         Uint8 r
4123         Uint8 g
4124         Uint8 b
4125         Uint8 a
4126         CODE:
4127                 RETVAL = aapolygonRGBA( dst, vx, vy, n, r, g, b, a );
4128         OUTPUT:
4129                 RETVAL
4130
4131 int
4132 GFXFilledPolygonColor ( dst, vx, vy, n, color )
4133         SDL_Surface* dst
4134         Sint16* vx
4135         Sint16* vy
4136         int n
4137         int color
4138         CODE:
4139                 RETVAL = filledPolygonColor( dst, vx, vy, n, color );
4140         OUTPUT:
4141                 RETVAL
4142
4143 int
4144 GFXFilledPolygonRGBA ( dst, vx, vy, n, r, g, b, a )
4145         SDL_Surface* dst
4146         Sint16* vx
4147         Sint16* vy
4148         int n
4149         Uint8 r
4150         Uint8 g
4151         Uint8 b
4152         Uint8 a
4153         CODE:
4154                 RETVAL = filledPolygonRGBA( dst, vx, vy, n, r, g, b, a );
4155         OUTPUT:
4156                 RETVAL
4157
4158 int
4159 GFXCharacterColor ( dst, x, y, c, color )
4160         SDL_Surface* dst
4161         Sint16 x
4162         Sint16 y
4163         char c
4164         Uint32 color
4165         CODE:
4166                 RETVAL = characterColor( dst, x, y, c, color );
4167         OUTPUT:
4168                 RETVAL
4169
4170 int
4171 GFXCharacterRGBA ( dst, x, y, c, r, g, b, a )
4172         SDL_Surface* dst
4173         Sint16 x
4174         Sint16 y
4175         char c
4176         Uint8 r
4177         Uint8 g
4178         Uint8 b
4179         Uint8 a
4180         CODE:
4181                 RETVAL = characterRGBA( dst, x, y, c, r, g, b, a );
4182         OUTPUT:
4183                 RETVAL
4184
4185 int
4186 GFXStringColor ( dst, x, y, c, color )
4187         SDL_Surface* dst
4188         Sint16 x
4189         Sint16 y
4190         char* c
4191         Uint32 color
4192         CODE:
4193                 RETVAL = stringColor( dst, x, y, c, color );
4194         OUTPUT:
4195                 RETVAL
4196
4197 int
4198 GFXStringRGBA ( dst, x, y, c, r, g, b, a )
4199         SDL_Surface* dst
4200         Sint16 x
4201         Sint16 y
4202         char* c
4203         Uint8 r
4204         Uint8 g
4205         Uint8 b
4206         Uint8 a
4207         CODE:
4208                 RETVAL = stringRGBA( dst, x, y, c, r, g, b, a );
4209         OUTPUT:
4210                 RETVAL
4211
4212 #endif
4213
4214
4215 #ifdef HAVE_SDL_SVG
4216
4217 SDL_svg_context *
4218 SVG_Load ( filename )
4219         char* filename
4220         CODE:
4221                 RETVAL = SVG_Load(filename);
4222         OUTPUT:
4223                 RETVAL
4224
4225 SDL_svg_context *
4226 SVG_LoadBuffer ( data, len )
4227         char* data
4228         int len
4229         CODE:
4230                 RETVAL = SVG_LoadBuffer(data,len);
4231         OUTPUT:
4232                 RETVAL
4233
4234 int
4235 SVG_SetOffset ( source, xoff, yoff )
4236         SDL_svg_context* source
4237         double xoff
4238         double yoff
4239         CODE:
4240                 RETVAL = SVG_SetOffset(source,xoff,yoff);
4241         OUTPUT:
4242                 RETVAL
4243
4244 int
4245 SVG_SetScale ( source, xscale, yscale )
4246         SDL_svg_context* source
4247         double xscale
4248         double yscale
4249         CODE:
4250                 RETVAL = SVG_SetScale(source,xscale,yscale);
4251         OUTPUT:
4252                 RETVAL
4253
4254 int
4255 SVG_RenderToSurface ( source, x, y, dest )
4256         SDL_svg_context* source
4257         int x
4258         int y
4259         SDL_Surface* dest;
4260         CODE:
4261                 RETVAL = SVG_RenderToSurface(source,x,y,dest);
4262         OUTPUT:
4263                 RETVAL
4264
4265 void
4266 SVG_Free ( source )
4267         SDL_svg_context* source
4268         CODE:
4269                 SVG_Free(source);       
4270
4271 void
4272 SVG_Set_Flags ( source, flags )
4273         SDL_svg_context* source
4274         Uint32 flags
4275         CODE:
4276                 SVG_Set_Flags(source,flags);
4277
4278 float
4279 SVG_Width ( source )
4280         SDL_svg_context* source
4281         CODE:
4282                 RETVAL = SVG_Width(source);
4283         OUTPUT:
4284                 RETVAL
4285
4286 float
4287 SVG_HEIGHT ( source )
4288         SDL_svg_context* source
4289         CODE:
4290                 RETVAL = SVG_Height(source);
4291         OUTPUT:
4292                 RETVAL
4293
4294 void
4295 SVG_SetClipping ( source, minx, miny, maxx, maxy )
4296         SDL_svg_context* source
4297         int minx
4298         int miny
4299         int maxx
4300         int maxy
4301         CODE:
4302                 SVG_SetClipping(source,minx,miny,maxx,maxy);
4303
4304 int
4305 SVG_Version ( )
4306         CODE:
4307                 RETVAL = SVG_Version();
4308         OUTPUT:
4309                 RETVAL
4310
4311
4312 #endif
4313
4314 #ifdef HAVE_SDL_SOUND
4315
4316 Uint16
4317 SoundAudioInfoFormat ( audioinfo )
4318         Sound_AudioInfo* audioinfo
4319         CODE:
4320                 RETVAL = audioinfo->format;
4321         OUTPUT:
4322                 RETVAL
4323
4324 Uint8
4325 SoundAudioInfoChannels ( audioinfo )
4326         Sound_AudioInfo* audioinfo
4327         CODE:
4328                 RETVAL = audioinfo->channels;
4329         OUTPUT:
4330                 RETVAL
4331
4332 Uint32
4333 SoundAudioInforate ( audioinfo )
4334         Sound_AudioInfo* audioinfo
4335         CODE:
4336                 RETVAL = audioinfo->rate;
4337         OUTPUT:
4338                 RETVAL
4339
4340 AV*
4341 SoundDecoderInfoExtensions ( decoderinfo )
4342         Sound_DecoderInfo* decoderinfo
4343         CODE:
4344                 const char **ext;
4345                 for ( ext = decoderinfo->extensions; *ext != NULL; ext++ ){
4346                         av_push(RETVAL,newSVpv(*ext,0));
4347                 }
4348         OUTPUT:
4349                 RETVAL
4350
4351 const char*
4352 SoundDecoderInfoDescription ( decoderinfo )
4353         Sound_DecoderInfo* decoderinfo
4354         CODE:
4355                 RETVAL = decoderinfo->description;
4356         OUTPUT:
4357                 RETVAL
4358
4359 const char*
4360 SoundDecoderInfoAuthor ( decoderinfo )
4361         Sound_DecoderInfo* decoderinfo
4362         CODE:
4363                 RETVAL = decoderinfo->author;
4364         OUTPUT:
4365                 RETVAL
4366
4367 const char*
4368 SoundDecoderInfoUrl ( decoderinfo )
4369         Sound_DecoderInfo* decoderinfo
4370         CODE:
4371                 RETVAL = decoderinfo->url;
4372         OUTPUT:
4373                 RETVAL
4374
4375 const Sound_DecoderInfo*
4376 SoundSampleDecoder ( sample ) 
4377         Sound_Sample* sample
4378         CODE:
4379                 RETVAL = sample->decoder;
4380         OUTPUT:
4381                 RETVAL
4382
4383 Sound_AudioInfo* 
4384 SoundSampleDesired ( sample )
4385         Sound_Sample* sample
4386         CODE:
4387                 RETVAL = &sample->desired;
4388         OUTPUT:
4389                 RETVAL
4390
4391 Sound_AudioInfo*
4392 SoundSampleAcutal ( sample )
4393         Sound_Sample* sample
4394         CODE:
4395                 RETVAL = &sample->actual;
4396         OUTPUT:
4397                 RETVAL
4398
4399 char*
4400 SoundSampleBuffer ( sample )
4401         Sound_Sample* sample
4402         CODE:
4403                 RETVAL = sample->buffer;
4404         OUTPUT:
4405                 RETVAL
4406
4407 Uint32
4408 SoundSampleBufferSize ( sample )
4409         Sound_Sample* sample
4410         CODE:
4411                 RETVAL = sample->buffer_size;
4412         OUTPUT:
4413                 RETVAL
4414
4415 Uint32
4416 SoundSampleFlags ( sample )
4417         Sound_Sample* sample
4418         CODE:
4419                 RETVAL = (Uint32)sample->flags;
4420         OUTPUT:
4421                 RETVAL
4422
4423 int
4424 Sound_Init ( )
4425         CODE:
4426                 RETVAL = Sound_Init();
4427         OUTPUT:
4428                 RETVAL
4429
4430 int
4431 Sound_Quit ( )
4432         CODE:
4433                 RETVAL = Sound_Quit();
4434         OUTPUT:
4435                 RETVAL
4436
4437 AV*
4438 Sound_AvailableDecoders ( )
4439         CODE:
4440                 RETVAL = newAV();
4441                 const Sound_DecoderInfo** sdi;
4442                 sdi = Sound_AvailableDecoders();
4443                 if (sdi != NULL)  {
4444                         for (;*sdi != NULL; ++sdi) {
4445                                 av_push(RETVAL,sv_2mortal(newSViv(PTR2IV(*sdi))));
4446                         }
4447                 }
4448         OUTPUT:
4449                 RETVAL
4450
4451 const char*
4452 Sound_GetError ( )
4453         CODE:
4454                 RETVAL = Sound_GetError();
4455         OUTPUT:
4456                 RETVAL
4457
4458 void
4459 Sound_ClearError ( )
4460         CODE:
4461                 Sound_ClearError();
4462
4463 Sound_Sample*
4464 Sound_NewSample ( rw, ext, desired, buffsize )
4465         SDL_RWops* rw
4466         const char* ext
4467         Sound_AudioInfo* desired
4468         Uint32 buffsize
4469         CODE:
4470                 RETVAL = Sound_NewSample(rw,ext,desired,buffsize);
4471         OUTPUT:
4472                 RETVAL
4473
4474 Sound_Sample*
4475 Sound_NewSampleFromMem ( data, size, ext, desired, buffsize )
4476         const Uint8 *data
4477         Uint32 size
4478         const char* ext
4479         Sound_AudioInfo* desired
4480         Uint32 buffsize
4481         CODE:
4482                 RETVAL = Sound_NewSampleFromMem(data,size,ext,desired,buffsize);
4483         OUTPUT:
4484                 RETVAL
4485
4486 Sound_Sample*
4487 Sound_NewSampleFromFile ( fname, desired, buffsize )
4488         const char* fname
4489         Sound_AudioInfo* desired
4490         Uint32 buffsize
4491         CODE:
4492                 RETVAL = Sound_NewSampleFromFile(fname,desired,buffsize);
4493         OUTPUT:
4494                 RETVAL
4495
4496 void
4497 Sound_FreeSample ( sample )
4498         Sound_Sample* sample
4499         CODE:
4500                 Sound_FreeSample(sample);
4501
4502 Sint32
4503 Sound_GetDuration ( sample )
4504         Sound_Sample* sample
4505         CODE:
4506                 RETVAL = Sound_GetDuration(sample);
4507         OUTPUT:
4508                 RETVAL
4509
4510 int
4511 Sound_SetBufferSize ( sample, size )
4512         Sound_Sample* sample
4513         Uint32 size
4514         CODE:
4515                 RETVAL = Sound_SetBufferSize(sample,size);
4516         OUTPUT:
4517                 RETVAL
4518
4519 Uint32
4520 Sound_Decode ( sample )
4521         Sound_Sample* sample
4522         CODE:
4523                 RETVAL = Sound_Decode(sample);
4524         OUTPUT:
4525                 RETVAL
4526
4527 Uint32
4528 Sound_DecodeAll ( sample ) 
4529         Sound_Sample* sample
4530         CODE:
4531                 RETVAL = Sound_DecodeAll(sample);
4532         OUTPUT:
4533                 RETVAL
4534
4535 int
4536 Sound_Rewind ( sample )
4537         Sound_Sample* sample
4538         CODE:
4539                 RETVAL = Sound_Rewind(sample);
4540         OUTPUT:
4541                 RETVAL
4542
4543 int
4544 Sound_Seek ( sample, ms )
4545         Sound_Sample* sample
4546         Uint32 ms
4547         CODE:
4548                 RETVAL = Sound_Seek(sample,ms);
4549         OUTPUT:
4550                 RETVAL
4551
4552 #endif
4553
4554 MODULE = SDL            PACKAGE = SDL
4555 PROTOTYPES : DISABLE
4556
4557