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