Trying workaround for directx forcing
[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_SMPEG
66 #include <smpeg/smpeg.h>
67 #ifdef HAVE_SDL_MIXER
68 static int sdl_perl_use_smpeg_audio = 0;
69 #endif
70 #endif
71
72 #ifdef HAVE_SDL_GFX
73 #include <SDL_rotozoom.h>
74 #include <SDL_gfxPrimitives.h>
75 #include <SDL_framerate.h>
76 #include <SDL_imageFilter.h>
77 #endif
78
79 #ifdef HAVE_SDL_SVG
80 #include <SDL_svg.h>
81 #endif
82
83 #ifdef HAVE_SDL_TTF
84 #include <SDL_ttf.h>
85 #endif
86
87 #ifdef USE_THREADS
88 #define HAVE_TLS_CONTEXT
89 #endif
90
91 /* For windows  */
92 #ifndef SDL_PERL_DEFINES_H
93 #define SDL_PERL_DEFINES_H
94
95 #ifdef HAVE_TLS_CONTEXT
96 PerlInterpreter *parent_perl = NULL;
97 extern PerlInterpreter *parent_perl;
98 #define GET_TLS_CONTEXT parent_perl =  PERL_GET_CONTEXT;
99 #define ENTER_TLS_CONTEXT \
100         PerlInterpreter *current_perl = PERL_GET_CONTEXT; \
101                 PERL_SET_CONTEXT(parent_perl); { \
102                                         PerlInterpreter *my_perl = parent_perl;
103 #define LEAVE_TLS_CONTEXT \
104                                                 } PERL_SET_CONTEXT(current_perl);
105 #else
106 #define GET_TLS_CONTEXT         /* TLS context not enabled */
107 #define ENTER_TLS_CONTEXT       /* TLS context not enabled */
108 #define LEAVE_TLS_CONTEXT       /* TLS context not enabled */
109 #endif
110
111 #endif
112
113 int
114 force_directx()
115 {
116 #if defined WIN32 || WINDOWS 
117         fprintf( stderr, "SDL Gamma is unsupported in Windows for windib. Forcing directx. \n" );
118         SDL_putenv("SDL_VIDEODRIVER=directx");
119 #endif
120         return 1;
121 }
122
123 Uint32 
124 sdl_perl_timer_callback ( Uint32 interval, void* param )
125 {
126         Uint32 retval;
127         int back;
128         SV* cmd;
129         ENTER_TLS_CONTEXT
130         dSP;
131
132         cmd = (SV*)param;
133
134         ENTER;
135         SAVETMPS;
136         PUSHMARK(SP);
137         XPUSHs(sv_2mortal(newSViv(interval)));
138         PUTBACK;
139
140         if (0 != (back = call_sv(cmd,G_SCALAR))) {
141                 SPAGAIN;
142                 if (back != 1 ) Perl_croak (aTHX_ "Timer Callback failed!");
143                 retval = POPi;  
144         } else {
145                 Perl_croak(aTHX_ "Timer Callback failed!");
146         }
147
148         FREETMPS;
149         LEAVE;
150
151         LEAVE_TLS_CONTEXT
152         
153         return retval;
154 }
155
156 void
157 sdl_perl_audio_callback ( void* data, Uint8 *stream, int len )
158 {
159         SV *cmd;
160         ENTER_TLS_CONTEXT
161         dSP;
162
163         cmd = (SV*)data;
164
165         ENTER;
166         SAVETMPS;
167         PUSHMARK(SP);
168         XPUSHs(sv_2mortal(newSViv(PTR2IV(stream))));
169         XPUSHs(sv_2mortal(newSViv(len)));
170         PUTBACK;
171
172         call_sv(cmd,G_VOID|G_DISCARD);
173         
174         PUTBACK;
175         FREETMPS;
176         LEAVE;
177
178         LEAVE_TLS_CONTEXT       
179 }
180
181 #ifdef HAVE_SDL_MIXER
182
183 void
184 sdl_perl_music_callback ( void ) 
185 {
186         SV *cmd;
187         ENTER_TLS_CONTEXT
188         dSP;
189
190         cmd = (SV*)Mix_GetMusicHookData();
191
192         ENTER;
193         SAVETMPS;
194         PUSHMARK(SP);
195         PUTBACK;
196         
197         call_sv(cmd,G_VOID|G_DISCARD);
198
199         PUTBACK;
200         FREETMPS;
201         LEAVE;
202
203         LEAVE_TLS_CONTEXT
204 }
205
206 void
207 sdl_perl_music_finished_callback ( void )
208 {
209         SV *cmd;
210         ENTER_TLS_CONTEXT
211         dSP;
212
213         cmd = (SV*)mix_music_finished_cv;
214         if ( cmd == NULL ) return;
215
216         ENTER;
217         SAVETMPS;
218         PUSHMARK(SP);
219         PUTBACK;
220         
221         call_sv(cmd,G_VOID|G_DISCARD);
222         
223         PUTBACK;
224         FREETMPS;
225         LEAVE;
226
227         LEAVE_TLS_CONTEXT
228 }
229
230 #endif
231
232 #define INIT_NS_APPLICATION
233 #define QUIT_NS_APPLICATION
234
235
236 void
237 sdl_perl_atexit (void)
238 {
239         QUIT_NS_APPLICATION     
240         SDL_Quit();
241 }
242
243 void boot_SDL();
244 void boot_SDL__OpenGL();
245
246 XS(boot_SDL_perl)
247 {
248         GET_TLS_CONTEXT
249         boot_SDL();
250 }
251
252 MODULE = SDL_perl       PACKAGE = SDL
253 PROTOTYPES : DISABLE
254
255 char *
256 geterror ()
257         CODE:
258                 RETVAL = SDL_GetError();
259         OUTPUT:
260                 RETVAL
261
262 int
263 init ( flags )
264         Uint32 flags
265         CODE:
266                 INIT_NS_APPLICATION
267                 force_directx();
268                 RETVAL = SDL_Init(flags);
269 #ifdef HAVE_TLS_CONTEXT
270                 Perl_call_atexit(PERL_GET_CONTEXT, (void*)sdl_perl_atexit,0);
271 #else
272                 atexit(sdl_perl_atexit);
273 #endif
274         OUTPUT:
275                 RETVAL
276
277 int
278 init_subsystem ( flags )
279         Uint32 flags
280         CODE:
281                 RETVAL = SDL_InitSubSystem(flags);
282         OUTPUT:
283                 RETVAL
284
285 void
286 quit_subsystem ( flags )
287         Uint32 flags
288         CODE:
289                 SDL_QuitSubSystem(flags);
290
291 void
292 quit ()
293         CODE:
294                 QUIT_NS_APPLICATION
295                 SDL_Quit();
296
297 int
298 was_init ( flags )
299         Uint32 flags
300         CODE:
301                 RETVAL = SDL_WasInit(flags);
302         OUTPUT:
303                 RETVAL
304
305 void
306 delay ( ms )
307         int ms
308         CODE:
309                 SDL_Delay(ms);
310
311 Uint32
312 GetTicks ()
313         CODE:
314                 RETVAL = SDL_GetTicks();
315         OUTPUT:
316                 RETVAL
317
318 int
319 SetTimer ( interval, callback )
320         Uint32 interval
321         SDL_TimerCallback callback
322         CODE:
323                 RETVAL = SDL_SetTimer(interval,callback);
324         OUTPUT:
325                 RETVAL
326
327 SDL_TimerID
328 AddTimer ( interval, callback, param )
329         Uint32 interval
330         SDL_NewTimerCallback callback
331         void *param
332         CODE:
333                 RETVAL = SDL_AddTimer(interval,callback,param);
334         OUTPUT:
335                 RETVAL
336
337 SDL_NewTimerCallback
338 PerlTimerCallback ()
339         CODE:
340                 RETVAL = sdl_perl_timer_callback;
341         OUTPUT:
342                 RETVAL  
343
344 SDL_TimerID
345 NewTimer ( interval, cmd )
346         Uint32 interval
347         void *cmd
348         CODE:
349                 RETVAL = SDL_AddTimer(interval,sdl_perl_timer_callback,cmd);
350         OUTPUT:
351                 RETVAL
352
353 Uint32
354 RemoveTimer ( id )
355         SDL_TimerID id
356         CODE:
357                 RETVAL = SDL_RemoveTimer(id);
358         OUTPUT:
359                 RETVAL
360
361 SDL_RWops*
362 RWFromFile ( file, mode )
363         char* file
364         char * mode
365         CODE:
366                 RETVAL = SDL_RWFromFile(file,mode);
367         OUTPUT:
368                 RETVAL
369
370 SDL_RWops*
371 RWFromFP ( fp, autoclose )
372         FILE* fp
373         int autoclose
374         CODE:
375                 RETVAL = SDL_RWFromFP(fp,autoclose);
376         OUTPUT:
377                 RETVAL
378
379 SDL_RWops*
380 RWFromMem ( mem, size )
381         char* mem
382         int size
383         CODE:
384                 RETVAL = SDL_RWFromMem((void*)mem,size);
385         OUTPUT:
386                 RETVAL
387
388 SDL_RWops*
389 RWFromConstMem ( mem, size )
390         const char* mem
391         int size
392         CODE:
393                 RETVAL = SDL_RWFromConstMem((const void*)mem,size);
394         OUTPUT:
395                 RETVAL
396
397 SDL_RWops*
398 AllocRW ()
399         CODE:
400                 RETVAL = SDL_AllocRW();
401         OUTPUT:
402                 RETVAL
403
404 void
405 FreeRW ( rw )
406         SDL_RWops* rw
407         CODE:
408                 SDL_FreeRW(rw);
409
410 int
411 RWseek ( rw, off, whence )
412         SDL_RWops* rw
413         int off
414         int whence
415         CODE:
416                 RETVAL = SDL_RWseek(rw,off,whence);
417         OUTPUT:
418                 RETVAL
419
420 int
421 RWtell ( rw )
422         SDL_RWops* rw
423         CODE:
424                 RETVAL = SDL_RWtell(rw);
425         OUTPUT:
426                 RETVAL
427
428 int
429 RWread ( rw, mem, size, n )
430         SDL_RWops* rw
431         char* mem
432         int size
433         int n
434         CODE:
435                 RETVAL = SDL_RWread(rw,mem,size,n);
436         OUTPUT:
437                 RETVAL
438
439 int
440 RWwrite ( rw, mem, size, n )
441         SDL_RWops* rw
442         char* mem
443         int size
444         int n
445         CODE:
446                 RETVAL = SDL_RWwrite(rw,mem,size,n);
447         OUTPUT:
448                 RETVAL
449
450 int
451 RWclose ( rw )
452         SDL_RWops* rw
453         CODE:
454                 RETVAL = SDL_RWclose(rw);
455         OUTPUT:
456                 RETVAL
457
458 int
459 CDNumDrives ()
460         CODE:
461                 RETVAL = SDL_CDNumDrives();
462         OUTPUT:
463                 RETVAL
464
465 char *
466 CDName ( drive )
467         int drive
468         CODE:
469                 RETVAL = strdup(SDL_CDName(drive));
470         OUTPUT:
471                 RETVAL
472
473 SDL_CD *
474 CDOpen ( drive )
475         int drive
476         CODE:
477                 RETVAL = SDL_CDOpen(drive);
478         OUTPUT:
479                 RETVAL
480
481 Uint8
482 CDTrackId ( track )
483         SDL_CDtrack *track
484         CODE:
485                 RETVAL = track->id;
486         OUTPUT:
487                 RETVAL
488
489 Uint8
490 CDTrackType ( track )
491         SDL_CDtrack *track
492         CODE:
493                 RETVAL = track->type;
494         OUTPUT:
495                 RETVAL
496
497 Uint16
498 CDTrackLength ( track )
499         SDL_CDtrack *track
500         CODE:
501                 RETVAL = track->length;
502         OUTPUT:
503                 RETVAL
504
505 Uint32
506 CDTrackOffset ( track )
507         SDL_CDtrack *track
508         CODE:
509                 RETVAL = track->offset;
510         OUTPUT: 
511                 RETVAL
512
513 Uint32
514 CDStatus ( cd )
515         SDL_CD *cd 
516         CODE:
517                 RETVAL = SDL_CDStatus(cd);
518         OUTPUT:
519                 RETVAL
520
521 int
522 CDPlayTracks ( cd, start_track, ntracks, start_frame, nframes )
523         SDL_CD *cd
524         int start_track
525         int ntracks
526         int start_frame
527         int nframes
528         CODE:
529                 RETVAL = SDL_CDPlayTracks(cd,start_track,start_frame,ntracks,nframes);
530         OUTPUT:
531                 RETVAL
532
533 int
534 CDPlay ( cd, start, length )
535         SDL_CD *cd
536         int start
537         int length
538         CODE:
539                 RETVAL = SDL_CDPlay(cd,start,length);
540         OUTPUT:
541                 RETVAL
542
543 int
544 CDPause ( cd )
545         SDL_CD *cd
546         CODE:
547                 RETVAL = SDL_CDPause(cd);
548         OUTPUT:
549                 RETVAL
550
551 int
552 CDResume ( cd )
553         SDL_CD *cd
554         CODE:
555                 RETVAL = SDL_CDResume(cd);
556         OUTPUT:
557                 RETVAL
558
559 int
560 CDStop ( cd )
561         SDL_CD *cd
562         CODE:
563                 RETVAL = SDL_CDStop(cd);
564         OUTPUT:
565                 RETVAL
566
567 int
568 CDEject ( cd )
569         SDL_CD *cd
570         CODE:
571                 RETVAL = SDL_CDEject(cd);
572         OUTPUT:
573                 RETVAL
574
575 void
576 CDClose ( cd )
577         SDL_CD *cd
578         CODE:
579                 SDL_CDClose(cd);
580         
581 int
582 CDId ( cd )
583         SDL_CD *cd
584         CODE:
585                 RETVAL = cd->id;
586         OUTPUT: 
587                 RETVAL
588
589 int
590 CDNumTracks ( cd )
591         SDL_CD *cd
592         CODE:
593                 RETVAL = cd->numtracks;
594         OUTPUT:
595                 RETVAL
596
597 int
598 CDCurTrack ( cd )
599         SDL_CD *cd
600         CODE:
601                 RETVAL = cd->cur_track;
602         OUTPUT:
603                 RETVAL
604
605 int
606 CDCurFrame ( cd )
607         SDL_CD *cd
608         CODE:
609                 RETVAL = cd->cur_frame;
610         OUTPUT:
611                 RETVAL
612
613 SDL_CDtrack *
614 CDTrack ( cd, number )
615         SDL_CD *cd
616         int number
617         CODE:
618                 RETVAL = (SDL_CDtrack *)(cd->track + number);
619         OUTPUT:
620                 RETVAL
621
622 void
623 PumpEvents ()
624         CODE:
625                 SDL_PumpEvents();
626
627 int
628 PushEvent( e )
629         SDL_Event *e
630         CODE:
631                 RETVAL = SDL_PushEvent( e );
632         OUTPUT:
633                 RETVAL
634
635 SDL_Event *
636 NewEvent ()
637         CODE:   
638                 RETVAL = (SDL_Event *) safemalloc (sizeof(SDL_Event));
639         OUTPUT:
640                 RETVAL
641
642 void
643 FreeEvent ( e )
644         SDL_Event *e
645         CODE:
646                 safefree(e);
647
648 int
649 PollEvent ( e )
650         SDL_Event *e
651         CODE:
652                 RETVAL = SDL_PollEvent(e);
653         OUTPUT:
654                 RETVAL
655
656 int
657 WaitEvent ( e )
658         SDL_Event *e
659         CODE:
660                 RETVAL = SDL_WaitEvent(e);
661         OUTPUT:
662                 RETVAL
663
664 Uint8
665 EventState ( type, state )
666         Uint8 type
667         int state
668         CODE:
669                 RETVAL = SDL_EventState(type,state);
670         OUTPUT:
671                 RETVAL 
672
673 Uint8
674 EventType ( e )
675         SDL_Event *e
676         CODE:
677                 RETVAL = e->type;
678         OUTPUT:
679                 RETVAL
680
681 Uint8
682 SetEventType ( e, type )
683         SDL_Event *e
684         Uint8 type
685         CODE:
686                 RETVAL = e->type;
687                 e->type = type;
688         OUTPUT:
689                 RETVAL
690
691 Uint8
692 ActiveEventGain ( e )
693         SDL_Event *e
694         CODE:
695                 RETVAL = e->active.gain;
696         OUTPUT: 
697                 RETVAL
698
699 Uint8
700 ActiveEventState ( e )
701         SDL_Event *e
702         CODE:
703                 RETVAL = e->active.state;
704         OUTPUT:
705                 RETVAL
706
707 Uint8
708 KeyEventState( e )
709         SDL_Event *e
710         CODE:
711                 RETVAL = e->key.state;
712         OUTPUT:
713                 RETVAL
714
715 int
716 KeyEventSym ( e )
717         SDL_Event *e
718         CODE:
719                 RETVAL = e->key.keysym.sym;
720         OUTPUT:
721                 RETVAL
722
723 int 
724 KeyEventMod ( e )
725         SDL_Event *e
726         CODE:
727                 RETVAL = e->key.keysym.mod;
728         OUTPUT:
729                 RETVAL
730
731 Uint16
732 KeyEventUnicode ( e )
733         SDL_Event *e
734         CODE:
735                 RETVAL = e->key.keysym.unicode;
736         OUTPUT:
737                 RETVAL
738
739 Uint8
740 key_scancode ( e )
741         SDL_Event *e
742         CODE:
743                 RETVAL = e->key.keysym.scancode;
744         OUTPUT:
745                 RETVAL
746
747 Uint8
748 MouseMotionState ( e )
749         SDL_Event *e
750         CODE:
751                 RETVAL = e->motion.state;
752         OUTPUT: 
753                 RETVAL
754
755 Uint16
756 MouseMotionX ( e )
757         SDL_Event *e
758         CODE:
759                 RETVAL = e->motion.x;
760         OUTPUT:
761                 RETVAL
762
763 Uint16
764 MouseMotionY ( e )
765         SDL_Event *e
766         CODE:
767                 RETVAL = e->motion.y;
768         OUTPUT:
769                 RETVAL
770
771 Sint16
772 MouseMotionXrel( e )
773         SDL_Event *e
774         CODE:
775                 RETVAL = e->motion.xrel;
776         OUTPUT:
777                 RETVAL
778
779 Sint16
780 MouseMotionYrel ( e )
781         SDL_Event *e
782         CODE:
783                 RETVAL = e->motion.yrel;
784         OUTPUT:
785                 RETVAL
786
787 Uint8
788 button_state ( e )
789         SDL_Event *e
790         CODE:
791                 RETVAL = e->button.state;
792         OUTPUT:
793                 RETVAL
794
795 Uint8
796 button ( e )
797         SDL_Event *e
798         CODE:
799                 RETVAL = e->button.button;
800         OUTPUT:
801                 RETVAL
802
803 Uint16
804 button_x ( e )
805         SDL_Event *e
806         CODE:
807                 RETVAL = e->button.x;
808         OUTPUT:
809                 RETVAL
810
811 Uint16
812 button_y ( e )
813         SDL_Event *e
814         CODE:
815                 RETVAL = e->button.y;
816         OUTPUT:
817                 RETVAL
818
819 SDL_SysWMmsg *
820 SysWMEventMsg ( e )
821         SDL_Event *e
822         CODE:
823                 RETVAL = e->syswm.msg;
824         OUTPUT:
825                 RETVAL
826
827 int
828 EnableUnicode ( enable )
829         int enable
830         CODE:
831                 RETVAL = SDL_EnableUNICODE(enable);
832         OUTPUT:
833                 RETVAL
834
835 void
836 EnableKeyRepeat ( delay, interval )
837         int delay
838         int interval
839         CODE:
840                 SDL_EnableKeyRepeat(delay,interval);
841
842 Uint32
843 GetModState ()
844         CODE:
845                 RETVAL = SDL_GetModState();
846         OUTPUT:
847                 RETVAL
848
849 void
850 SetModState ( state )
851         Uint32 state
852         CODE:
853                 SDL_SetModState(state);
854
855 char *
856 get_key_name ( sym )
857         int sym
858         CODE:
859                 RETVAL = SDL_GetKeyName(sym);
860         OUTPUT:
861                 RETVAL
862
863 #ifdef HAVE_SDL_IMAGE
864
865 SDL_Surface *
866 IMG_Load ( filename )
867         char *filename
868         CODE:
869                 char* CLASS = "SDL::Surface";
870                 RETVAL = IMG_Load(filename);
871         OUTPUT:
872                 RETVAL
873
874 #endif
875
876 =for comment
877
878 Comment out for now as it does not compile
879
880 SDL_Surface *
881 CreateRGBSurfaceFrom (pixels, width, height, depth, pitch, Rmask, Gmask, Bmask, Amask )
882         char *pixels
883         int width
884         int height
885         int depth
886         int pitch
887         Uint32 Rmask
888         Uint32 Gmask
889         Uint32 Bmask
890         Uint32 Amask
891         CODE:
892                 Uint8* pixeldata;
893                 Uint32 len = pitch * height;
894                 New(0,pixeldata,len,Uint8);
895                 Copy(pixels,pixeldata,len,Uint8);
896                 RETVAL = SDL_CreateRGBSurfaceFrom ( pixeldata, width, height,
897                                 depth, pitch, Rmask, Gmask, Bmask, Amask );
898         OUTPUT: 
899                 RETVAL
900
901 SDL_Surface*
902 SurfaceCopy ( surface )
903         SDL_Surface *surface
904         CODE:
905                 Uint8* pixels;
906                 Uint32 size = surface->pitch * surface->h;
907                 New(0,pixels,size,Uint8);
908                 Copy(surface->pixels,pixels,size,Uint8);
909                 RETVAL = SDL_CreateRGBSurfaceFrom(pixels,surface->w,surface->h,
910                         surface->format->BitsPerPixel, surface->pitch,
911                         surface->format->Rmask, surface->format->Gmask,
912                         surface->format->Bmask, surface->format->Amask);
913         OUTPUT:
914                 RETVAL
915
916 void
917 FreeSurface ( surface )
918         SDL_Surface *surface
919         CODE:
920                 if (surface) {
921                         Uint8* pixels = surface->pixels;
922                         Uint32 flags = surface->flags;
923                         SDL_FreeSurface(surface);
924                         if (flags & SDL_PREALLOC)
925                                 Safefree(pixels);
926                 }
927         
928 Uint32
929 SurfaceFlags ( surface )
930         SDL_Surface *surface
931         CODE:
932                 RETVAL = surface->flags;
933         OUTPUT:
934                 RETVAL
935
936 SDL_Palette *
937 SurfacePalette ( surface )
938         SDL_Surface *surface
939         CODE:
940                 RETVAL = surface->format->palette;
941         OUTPUT:
942                 RETVAL
943
944 Uint8
945 SurfaceBitsPerPixel ( surface )
946         SDL_Surface *surface
947         CODE:
948                 RETVAL = surface->format->BitsPerPixel;
949         OUTPUT:
950                 RETVAL
951
952 Uint8
953 SurfaceBytesPerPixel ( surface )
954         SDL_Surface *surface
955         CODE:   
956                 RETVAL = surface->format->BytesPerPixel;
957         OUTPUT:
958                 RETVAL
959
960 Uint8
961 SurfaceRshift ( surface )
962         SDL_Surface *surface
963         CODE:
964                 RETVAL = surface->format->Rshift;
965         OUTPUT:
966                 RETVAL
967
968 Uint8
969 SurfaceGshift ( surface )
970         SDL_Surface *surface
971         CODE:
972                 RETVAL = surface->format->Gshift;
973         OUTPUT:
974                 RETVAL
975
976 Uint8
977 SurfaceBshift ( surface )
978         SDL_Surface *surface
979         CODE:
980                 RETVAL = surface->format->Bshift;
981         OUTPUT:
982                 RETVAL
983
984 Uint8
985 SurfaceAshift ( surface )
986         SDL_Surface *surface
987         CODE:
988                 RETVAL = surface->format->Ashift;
989         OUTPUT:
990                 RETVAL
991
992 Uint32
993 SurfaceRmask( surface )
994         SDL_Surface *surface
995         CODE:
996                 RETVAL = surface->format->Rmask;
997         OUTPUT:
998                 RETVAL
999
1000 Uint32
1001 SurfaceGmask ( surface )
1002         SDL_Surface *surface
1003         CODE:
1004                 RETVAL = surface->format->Gmask;
1005         OUTPUT:
1006                 RETVAL
1007
1008 Uint32
1009 SurfaceBmask ( surface )
1010         SDL_Surface *surface
1011         CODE:
1012                 RETVAL = surface->format->Bmask;
1013         OUTPUT:
1014                 RETVAL
1015
1016 Uint32
1017 SurfaceAmask ( surface )
1018         SDL_Surface *surface
1019         CODE:
1020                 RETVAL = surface->format->Amask;
1021         OUTPUT:
1022                 RETVAL
1023
1024 Uint32
1025 SurfaceColorKey ( surface )
1026         SDL_Surface *surface
1027         CODE:
1028                 RETVAL = surface->format->colorkey;
1029         OUTPUT:
1030                 RETVAL
1031
1032 Uint32
1033 SurfaceAlpha( surface )
1034         SDL_Surface *surface
1035         CODE:
1036                 RETVAL = surface->format->alpha;
1037         OUTPUT:
1038                 RETVAL
1039
1040 int
1041 SurfaceW ( surface )
1042         SDL_Surface *surface
1043         CODE:   
1044                 RETVAL = surface->w;
1045         OUTPUT:
1046                 RETVAL
1047
1048 int
1049 SurfaceH ( surface )
1050         SDL_Surface *surface
1051         CODE:   
1052                 RETVAL = surface->h;
1053         OUTPUT:
1054                 RETVAL
1055
1056 Uint16
1057 SurfacePitch ( surface )
1058         SDL_Surface *surface
1059         CODE:   
1060                 RETVAL = surface->pitch;
1061         OUTPUT:
1062                 RETVAL
1063
1064 SV*
1065 SurfacePixels ( surface )
1066         SDL_Surface *surface
1067         CODE:   
1068                 RETVAL = newSVpvn(surface->pixels,surface->pitch*surface->h);
1069         OUTPUT:
1070                 RETVAL
1071
1072 =cut
1073
1074 =for comment
1075
1076 Comment out for now as it does not compile
1077
1078 SDL_Color*
1079 SurfacePixel ( surface, x, y, ... )
1080         SDL_Surface *surface
1081         Sint32 x
1082         Sint32 y
1083         CODE:
1084                 SDL_Color* color;
1085                 int pix,index;
1086                 Uint8 r,g,b,a;
1087                 int bpp = surface->format->BytesPerPixel;
1088                 Uint8* p = (Uint8*)surface->pixels + bpp*x + surface->pitch*y;
1089                 if ( items < 3 || items > 4 ) 
1090                         Perl_croak(aTHX_ "usage: SDL::SurfacePixel(surface,x,y,[color])");
1091                 if ( items == 4) {
1092                         color = (SDL_Color*)SvIV(ST(3));
1093                         pix = SDL_MapRGB(surface->format,color->r,color->g,color->b);
1094                         switch(bpp) {
1095                                 case 1:
1096                                         *(Uint8*)p = pix;
1097                                         break;
1098                                 case 2:
1099                                         *(Uint16*)p = pix;
1100                                         break;
1101                                 case 3:
1102                                         if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
1103                                                 p[0] = (pix >> 16) & 0xff;
1104                                                 p[1] = (pix >> 8) & 0xff;
1105                                                 p[2] = pix & 0xff;
1106                                         } else {
1107                                                 p[0] = pix & 0xff;
1108                                                 p[1] = (pix >> 8) & 0xff;
1109                                                 p[2] = (pix >> 16) & 0xff;
1110                                         }
1111                                         break;
1112                                 case 4:
1113                                         *(Uint32*)p = pix;
1114                                         break;
1115                         }
1116                 }
1117                 RETVAL = (SDL_Color *) safemalloc(sizeof(SDL_Color));
1118                 switch(bpp) {
1119                         case 1:
1120                                 index = *(Uint8*)p;
1121                                 memcpy(RETVAL,&surface->format->palette[index],sizeof(SDL_Color));
1122                                 break;
1123                         case 2:
1124                                 pix = *(Uint16*)p;
1125                                 SDL_GetRGB(pix,surface->format,&r,&g,&b);
1126                                 RETVAL->r = r;
1127                                 RETVAL->g = g;
1128                                 RETVAL->b = b;
1129                                 break;
1130                         case 3:
1131                         case 4:
1132                                 pix = *(Uint32*)p;
1133                                 SDL_GetRGB(pix,surface->format,&r,&g,&b);
1134                                 RETVAL->r = r;
1135                                 RETVAL->g = g;
1136                                 RETVAL->b = b;
1137                                 break;
1138                 }
1139         OUTPUT:
1140                 RETVAL
1141
1142 int
1143 MUSTLOCK ( surface )
1144         SDL_Surface *surface
1145         CODE:
1146                 RETVAL = SDL_MUSTLOCK(surface);
1147         OUTPUT:
1148                 RETVAL          
1149
1150 int
1151 SurfaceLock ( surface )
1152         SDL_Surface *surface
1153         CODE:
1154                 RETVAL = SDL_LockSurface(surface);
1155         OUTPUT:
1156                 RETVAL
1157
1158 void
1159 SurfaceUnlock ( surface )
1160         SDL_Surface *surface
1161         CODE:
1162                 SDL_UnlockSurface(surface);
1163
1164 SDL_Surface *
1165 GetVideoSurface ()
1166         CODE:
1167                 RETVAL = SDL_GetVideoSurface();
1168         OUTPUT:
1169                 RETVAL
1170
1171 =cut
1172
1173 HV *
1174 VideoInfo ()
1175         CODE:
1176                 HV *hv;
1177                 SDL_VideoInfo *info;
1178                 info = (SDL_VideoInfo *) safemalloc ( sizeof(SDL_VideoInfo));
1179                 memcpy(info,SDL_GetVideoInfo(),sizeof(SDL_VideoInfo));
1180                 hv = newHV();
1181                 hv_store(hv,"hw_available",strlen("hw_available"),
1182                         newSViv(info->hw_available),0);
1183                 hv_store(hv,"wm_available",strlen("wm_available"),
1184                         newSViv(info->wm_available),0);
1185                 hv_store(hv,"blit_hw",strlen("blit_hw"),
1186                         newSViv(info->blit_hw),0);
1187                 hv_store(hv,"blit_hw_CC",strlen("blit_hw_CC"),
1188                         newSViv(info->blit_hw_CC),0);
1189                 hv_store(hv,"blit_hw_A",strlen("blit_hw_A"),
1190                         newSViv(info->blit_hw_A),0);
1191                 hv_store(hv,"blit_sw",strlen("blit_sw"),
1192                         newSViv(info->blit_sw),0);
1193                 hv_store(hv,"blit_sw_CC",strlen("blit_sw_CC"),
1194                         newSViv(info->blit_sw_CC),0);
1195                 hv_store(hv,"blit_sw_A",strlen("blit_sw_A"),
1196                         newSViv(info->blit_sw_A),0);
1197                 hv_store(hv,"blit_fill",strlen("blit_fill"),
1198                         newSViv(info->blit_fill),0);
1199                 hv_store(hv,"video_mem",strlen("video_mem"),
1200                         newSViv(info->video_mem),0);
1201                 RETVAL = hv;
1202         OUTPUT:
1203                 RETVAL
1204
1205 AV*
1206 ListModes ( format, flags )
1207         Uint32 flags
1208         SDL_PixelFormat *format
1209         CODE:
1210                 SDL_Rect **mode;
1211                 RETVAL = newAV();
1212                 mode = SDL_ListModes(format,flags);
1213                 if (mode == (SDL_Rect**)-1 ) {
1214                         av_push(RETVAL,newSVpv("all",0));
1215                 } else if (! mode ) {
1216                         av_push(RETVAL,newSVpv("none",0));
1217                 } else {
1218                         for (;*mode;mode++) {
1219                                 av_push(RETVAL,newSViv(PTR2IV(*mode)));
1220                         }
1221                 }
1222         OUTPUT:
1223                 RETVAL
1224 =skip
1225
1226 SDL_Palette *
1227 NewPalette ( number )
1228         int number
1229         CODE:
1230                 RETVAL = (SDL_Palette *)safemalloc(sizeof(SDL_Palette));
1231                 RETVAL->colors = (SDL_Color *)safemalloc(number * 
1232                                                 sizeof(SDL_Color));
1233                 RETVAL->ncolors = number;
1234         OUTPUT:
1235                 RETVAL
1236 =cut
1237
1238 int
1239 PaletteNColors ( palette, ... )
1240         SDL_Palette *palette
1241         CODE:
1242                 if ( items > 1 ) palette->ncolors = SvIV(ST(1));
1243                 RETVAL = palette->ncolors;
1244         OUTPUT:
1245                 RETVAL
1246
1247 SDL_Surface *
1248 SetVideoMode ( width, height, bpp, flags )
1249
1250         int width
1251         int height
1252         int bpp
1253         Uint32 flags
1254
1255         CODE:
1256                 char *CLASS = "SDL::Surface";
1257                 RETVAL = SDL_SetVideoMode(width,height,bpp,flags);
1258         OUTPUT:
1259                 RETVAL
1260
1261 int
1262 Flip ( surface )
1263         SDL_Surface *surface
1264         CODE:
1265                 RETVAL = SDL_Flip(surface);
1266         OUTPUT:
1267                 RETVAL
1268
1269 int
1270 BlitSurface ( src, src_rect, dest, dest_rect )
1271         SDL_Surface *src
1272         SDL_Surface *dest
1273         SDL_Rect *src_rect
1274         SDL_Rect *dest_rect
1275         CODE:
1276                 RETVAL = SDL_BlitSurface(src,src_rect,dest,dest_rect);
1277         OUTPUT:
1278                 RETVAL
1279
1280 Uint32
1281 MapRGB ( pixel_format, r, g, b )
1282         SDL_PixelFormat *pixel_format
1283         Uint8 r
1284         Uint8 g
1285         Uint8 b
1286         CODE:
1287                 RETVAL = SDL_MapRGB(pixel_format,r,g,b);
1288         OUTPUT:
1289                 RETVAL
1290
1291 void
1292 UpdateRect ( surface, x, y, w ,h )
1293         SDL_Surface *surface
1294         int x
1295         int y
1296         int w
1297         int h
1298         CODE:
1299                 SDL_UpdateRect(surface,x,y,w,h);
1300
1301 SDL_Surface *
1302 DisplayFormat ( surface )
1303         SDL_Surface *surface
1304         CODE:
1305                 char* CLASS = "SDL::Surface";
1306                 RETVAL = SDL_DisplayFormat(surface);
1307         OUTPUT:
1308                 RETVAL
1309
1310 SDL_Surface *
1311 DisplayFormatAlpha ( surface )
1312         SDL_Surface *surface
1313         CODE:
1314                 char* CLASS = "SDL::Surface";
1315                 RETVAL = SDL_DisplayFormatAlpha(surface);
1316         OUTPUT:
1317                 RETVAL
1318
1319 void
1320 UpdateRects ( surface, ... )
1321         SDL_Surface *surface
1322         CODE:
1323                 SDL_Rect *rects;
1324                 int num_rects,i;
1325                 if ( items < 2 ) return;
1326                 num_rects = items - 1;
1327                 rects = (SDL_Rect *)safemalloc(sizeof(SDL_Rect)*items);
1328                 for(i=0;i<num_rects;i++) {
1329                         rects[i] = *(SDL_Rect *)SvIV((SV*)SvRV( ST(i + 1) ));
1330                 }
1331                 SDL_UpdateRects(surface,num_rects,rects);
1332                 safefree(rects);
1333
1334 =for comment
1335
1336 Comment out for now as it does not compile
1337
1338 int
1339 VideoModeOK ( width, height, bpp, flags )
1340         int width
1341         int height
1342         int bpp
1343         Uint32 flags
1344         CODE:
1345                 RETVAL = SDL_VideoModeOK(width,height,bpp,flags);
1346         OUTPUT:
1347                 RETVAL
1348
1349 SDL_Surface *
1350 SetVideoMode ( width, height, bpp, flags )
1351         int width
1352         int height
1353         int bpp
1354         Uint32 flags
1355         CODE:
1356                 RETVAL = SDL_SetVideoMode(width,height,bpp,flags);
1357         OUTPUT:
1358                 RETVAL
1359
1360 int
1361 Flip ( surface )
1362         SDL_Surface *surface
1363         CODE:
1364                 RETVAL = SDL_Flip(surface);
1365         OUTPUT:
1366                 RETVAL
1367
1368 int
1369 SetColors ( surface, start, ... )
1370         SDL_Surface *surface
1371         int start
1372         CODE:
1373                 SDL_Color *colors,*temp;
1374                 int i, length;
1375                 if ( items < 3 ) { RETVAL = 0;  goto all_done; }
1376                 length = items - 2;
1377                 colors = (SDL_Color *)safemalloc(sizeof(SDL_Color)*(length+1));
1378                 for ( i = 0; i < length ; i++ ) {
1379                         temp = (SDL_Color *)SvIV(ST(i+2));
1380                         colors[i].r = temp->r;
1381                         colors[i].g = temp->g;
1382                         colors[i].b = temp->b;
1383                 }
1384                 RETVAL = SDL_SetColors(surface, colors, start, length );
1385                 safefree(colors);
1386 all_done:
1387         OUTPUT: 
1388                 RETVAL
1389
1390 Uint32
1391 MapRGBA ( surface, r, g, b, a )
1392         SDL_Surface *surface
1393         Uint8 r
1394         Uint8 g
1395         Uint8 b
1396         Uint8 a
1397         CODE:
1398                 RETVAL = SDL_MapRGBA(surface->format,r,g,b,a);
1399         OUTPUT:
1400                 RETVAL
1401
1402 AV *
1403 GetRGB ( surface, pixel )
1404         SDL_Surface *surface
1405         Uint32 pixel
1406         CODE:
1407                 Uint8 r,g,b;
1408                 SDL_GetRGB(pixel,surface->format,&r,&g,&b);
1409                 RETVAL = newAV();
1410                 av_push(RETVAL,newSViv(r));
1411                 av_push(RETVAL,newSViv(g));
1412                 av_push(RETVAL,newSViv(b));
1413         OUTPUT:
1414                 RETVAL
1415
1416 AV *
1417 GetRGBA ( surface, pixel )
1418         SDL_Surface *surface
1419         Uint32 pixel
1420         CODE:
1421                 Uint8 r,g,b,a;
1422                 SDL_GetRGBA(pixel,surface->format,&r,&g,&b,&a);
1423                 RETVAL = newAV();
1424                 av_push(RETVAL,newSViv(r));
1425                 av_push(RETVAL,newSViv(g));
1426                 av_push(RETVAL,newSViv(b));
1427                 av_push(RETVAL,newSViv(a));
1428         OUTPUT:
1429                 RETVAL
1430
1431 int
1432 SaveBMP ( surface, filename )
1433         SDL_Surface *surface
1434         char *filename
1435         CODE:
1436                 RETVAL = SDL_SaveBMP(surface,filename);
1437         OUTPUT:
1438                 RETVAL  
1439
1440 int
1441 SetColorKey ( surface, flag, key )
1442         SDL_Surface *surface
1443         Uint32 flag
1444         SDL_Color *key
1445         CODE:
1446                 Uint32 pixel = SDL_MapRGB(surface->format,key->r,key->g,key->b);
1447                 RETVAL = SDL_SetColorKey(surface,flag,pixel);
1448         OUTPUT:
1449                 RETVAL
1450
1451 int
1452 SetAlpha ( surface, flag, alpha )
1453         SDL_Surface *surface
1454         Uint32 flag
1455         Uint8 alpha
1456         CODE:
1457                 RETVAL = SDL_SetAlpha(surface,flag,alpha);
1458         OUTPUT:
1459                 RETVAL
1460
1461 SDL_Surface*
1462 ConvertRGB ( surface )
1463         SDL_Surface * surface
1464         CODE:
1465                 SDL_PixelFormat fmt;
1466                 fmt.palette = NULL;
1467                 fmt.BitsPerPixel = 24;
1468                 fmt.BytesPerPixel = 3;
1469                 fmt.Rmask = 0x000000ff;
1470                 fmt.Gmask = 0x0000ff00;
1471                 fmt.Bmask = 0x00ff0000;
1472                 fmt.Amask = 0x00000000;
1473                 fmt.Rloss = 0;
1474                 fmt.Gloss = 0;
1475                 fmt.Bloss = 0;
1476                 fmt.Aloss = 0;
1477                 fmt.Rshift = 0;
1478                 fmt.Gshift = 8;
1479                 fmt.Bshift = 16;
1480                 fmt.Ashift = 24;
1481                 fmt.colorkey = 0;
1482                 fmt.alpha = 0;
1483                 RETVAL = SDL_ConvertSurface(surface,&fmt,surface->flags);
1484         OUTPUT:
1485                 RETVAL
1486
1487 SDL_Surface* 
1488 ConvertRGBA ( surface )
1489         SDL_Surface * surface
1490         CODE:
1491                 SDL_PixelFormat fmt;
1492                 fmt.palette = NULL;
1493                 fmt.BitsPerPixel = 32;
1494                 fmt.BytesPerPixel = 4;
1495                 fmt.Rmask = 0x000000ff;
1496                 fmt.Gmask = 0x0000ff00;
1497                 fmt.Bmask = 0x00ff0000;
1498                 fmt.Amask = 0xff000000;
1499                 fmt.Rloss = 0;
1500                 fmt.Gloss = 0;
1501                 fmt.Bloss = 0;
1502                 fmt.Aloss = 0;
1503                 fmt.Rshift = 0;
1504                 fmt.Gshift = 8;
1505                 fmt.Bshift = 16;
1506                 fmt.Ashift = 24;
1507                 fmt.colorkey = 0;
1508                 fmt.alpha = 0;
1509                 RETVAL = SDL_ConvertSurface(surface,&fmt,surface->flags);
1510         OUTPUT:
1511                 RETVAL
1512
1513 =cut
1514
1515 int
1516 FillRect ( dest, dest_rect, pixel )
1517         SDL_Surface *dest
1518         SDL_Rect *dest_rect
1519         Uint32 pixel
1520         CODE:
1521                 RETVAL = SDL_FillRect(dest,dest_rect,pixel);
1522         OUTPUT:
1523                 RETVAL
1524
1525 Uint8
1526 GetAppState ()
1527         CODE:
1528                 RETVAL = SDL_GetAppState();
1529         OUTPUT:
1530                 RETVAL
1531
1532
1533 void
1534 WMSetCaption ( title, icon )
1535         char *title
1536         char *icon
1537         CODE:
1538                 SDL_WM_SetCaption(title,icon);
1539
1540 AV *
1541 WMGetCaption ()
1542         CODE:
1543                 char *title,*icon;
1544                 SDL_WM_GetCaption(&title,&icon);
1545                 RETVAL = newAV();
1546                 av_push(RETVAL,newSVpv(title,0));
1547                 av_push(RETVAL,newSVpv(icon,0));
1548         OUTPUT:
1549                 RETVAL
1550
1551 void
1552 WMSetIcon ( icon )
1553         SDL_Surface *icon
1554         CODE:
1555                 SDL_WM_SetIcon(icon,NULL);
1556
1557 void
1558 WarpMouse ( x, y )
1559         Uint16 x
1560         Uint16 y
1561         CODE:
1562                 SDL_WarpMouse(x,y);
1563
1564 AV*
1565 GetMouseState ()
1566         CODE:
1567                 Uint8 mask;
1568                 int x;
1569                 int y;
1570                 mask = SDL_GetMouseState(&x,&y);
1571                 RETVAL = newAV();
1572                 av_push(RETVAL,newSViv(mask));
1573                 av_push(RETVAL,newSViv(x));
1574                 av_push(RETVAL,newSViv(y));
1575         OUTPUT:
1576                 RETVAL  
1577
1578 AV*
1579 GetRelativeMouseState ()
1580         CODE:
1581                 Uint8 mask;
1582                 int x;
1583                 int y;
1584                 mask = SDL_GetRelativeMouseState(&x,&y);
1585                 RETVAL = newAV();
1586                 av_push(RETVAL,newSViv(mask));
1587                 av_push(RETVAL,newSViv(x));
1588                 av_push(RETVAL,newSViv(y));
1589         OUTPUT:
1590                 RETVAL  
1591
1592 SDL_Cursor *
1593 NewCursor ( data, mask, x ,y )
1594         SDL_Surface *data
1595         SDL_Surface *mask
1596         int x
1597         int y
1598         CODE:
1599                 RETVAL = SDL_CreateCursor((Uint8*)data->pixels,
1600                                 (Uint8*)mask->pixels,data->w,data->h,x,y);
1601         OUTPUT:
1602                 RETVAL
1603
1604 void
1605 FreeCursor ( cursor )
1606         SDL_Cursor *cursor
1607         CODE:
1608                 SDL_FreeCursor(cursor);
1609
1610 void
1611 SetCursor ( cursor )
1612         SDL_Cursor *cursor
1613         CODE:
1614                 SDL_SetCursor(cursor);
1615
1616 SDL_Cursor *
1617 GetCursor ()
1618         CODE:
1619                 RETVAL = SDL_GetCursor();
1620         OUTPUT:
1621                 RETVAL
1622
1623 int
1624 ShowCursor ( toggle )
1625         int toggle
1626         CODE:
1627                 RETVAL = SDL_ShowCursor(toggle);
1628         OUTPUT: 
1629                 RETVAL
1630
1631 SDL_AudioSpec *
1632 NewAudioSpec ( freq, format, channels, samples )
1633         int freq
1634         Uint16 format
1635         Uint8 channels
1636         Uint16 samples
1637         CODE:
1638                 RETVAL = (SDL_AudioSpec *)safemalloc(sizeof(SDL_AudioSpec));
1639                 RETVAL->freq = freq;
1640                 RETVAL->format = format;
1641                 RETVAL->channels = channels;
1642                 RETVAL->samples = samples;
1643         OUTPUT:
1644                 RETVAL
1645
1646 void
1647 FreeAudioSpec ( spec )
1648         SDL_AudioSpec *spec
1649         CODE:
1650                 safefree(spec);
1651
1652 SDL_AudioCVT *
1653 NewAudioCVT ( src_format, src_channels, src_rate, dst_format, dst_channels, dst_rate)
1654         Uint16 src_format
1655         Uint8 src_channels
1656         int src_rate
1657         Uint16 dst_format
1658         Uint8 dst_channels
1659         int dst_rate
1660         CODE:
1661                 RETVAL = (SDL_AudioCVT *)safemalloc(sizeof(SDL_AudioCVT));
1662                 if (SDL_BuildAudioCVT(RETVAL,src_format, src_channels, src_rate,
1663                         dst_format, dst_channels, dst_rate)) { 
1664                         safefree(RETVAL); RETVAL = NULL; }
1665         OUTPUT:
1666                 RETVAL
1667
1668 void
1669 FreeAudioCVT ( cvt )
1670         SDL_AudioCVT *cvt
1671         CODE:
1672                 safefree(cvt);
1673
1674 int
1675 ConvertAudioData ( cvt, data, len )
1676         SDL_AudioCVT *cvt
1677         Uint8 *data
1678         int len
1679         CODE:
1680                 cvt->len = len;
1681                 cvt->buf = (Uint8*) safemalloc(cvt->len*cvt->len_mult);
1682                 memcpy(cvt->buf,data,cvt->len);
1683                 RETVAL = SDL_ConvertAudio(cvt);
1684         OUTPUT:
1685                 RETVAL                  
1686
1687 int
1688 OpenAudio ( spec, callback )
1689         SDL_AudioSpec *spec
1690         SV* callback
1691         CODE:
1692                 spec->userdata = (void*)callback;
1693                 spec->callback = sdl_perl_audio_callback;
1694                 RETVAL = SDL_OpenAudio(spec,NULL);
1695         OUTPUT:
1696                 RETVAL
1697
1698 Uint32
1699 GetAudioStatus ()
1700         CODE:
1701                 RETVAL = SDL_GetAudioStatus ();
1702         OUTPUT:
1703                 RETVAL
1704
1705 void
1706 PauseAudio ( p_on )
1707         int p_on
1708         CODE:
1709                 SDL_PauseAudio(p_on);
1710         
1711 void
1712 LockAudio ()
1713         CODE:
1714                 SDL_LockAudio();
1715
1716 void
1717 UnlockAudio ()
1718         CODE:
1719                 SDL_UnlockAudio();
1720
1721 void
1722 CloseAudio ()
1723         CODE:
1724                 SDL_CloseAudio();
1725
1726 void
1727 FreeWAV ( buf )
1728         Uint8 *buf
1729         CODE:
1730                 SDL_FreeWAV(buf);
1731
1732 AV *
1733 LoadWAV ( filename, spec )
1734         char *filename
1735         SDL_AudioSpec *spec
1736         CODE:
1737                 SDL_AudioSpec *temp;
1738                 Uint8 *buf;
1739                 Uint32 len;
1740
1741                 RETVAL = newAV();
1742                 temp = SDL_LoadWAV(filename,spec,&buf,&len);
1743                 if ( ! temp ) goto error;
1744                 av_push(RETVAL,newSViv(PTR2IV(temp)));
1745                 av_push(RETVAL,newSViv(PTR2IV(buf)));
1746                 av_push(RETVAL,newSViv(len));
1747 error:
1748         OUTPUT:
1749                 RETVAL
1750         
1751 #ifdef HAVE_SDL_MIXER
1752
1753 void
1754 MixAudio ( dst, src, len, volume )
1755         Uint8 *dst
1756         Uint8 *src
1757         Uint32 len
1758         int volume
1759         CODE:
1760                 SDL_MixAudio(dst,src,len,volume);
1761
1762 int
1763 MixOpenAudio ( frequency, format, channels, chunksize )
1764         int frequency
1765         Uint16 format
1766         int channels
1767         int chunksize   
1768         CODE:
1769                 RETVAL = Mix_OpenAudio(frequency, format, channels, chunksize);
1770         OUTPUT:
1771                 RETVAL
1772
1773 int
1774 MixAllocateChannels ( number )
1775         int number
1776         CODE:
1777                 RETVAL = Mix_AllocateChannels(number);
1778         OUTPUT:
1779                 RETVAL
1780
1781 AV *
1782 MixQuerySpec ()
1783         CODE:
1784                 int freq, channels, status;
1785                 Uint16 format;
1786                 status = Mix_QuerySpec(&freq,&format,&channels);
1787                 RETVAL = newAV();
1788                 av_push(RETVAL,newSViv(status));
1789                 av_push(RETVAL,newSViv(freq));
1790                 av_push(RETVAL,newSViv(format));
1791                 av_push(RETVAL,newSViv(channels));
1792         OUTPUT:
1793                 RETVAL
1794
1795 Mix_Chunk *
1796 MixLoadWAV ( filename )
1797         char *filename
1798         CODE:
1799                 RETVAL = Mix_LoadWAV(filename);
1800         OUTPUT:
1801                 RETVAL
1802
1803 Mix_Music *
1804 MixLoadMusic ( filename )
1805         char *filename
1806         CODE:
1807                 RETVAL = Mix_LoadMUS(filename);
1808         OUTPUT:
1809                 RETVAL
1810
1811 Mix_Chunk *
1812 MixQuickLoadWAV ( buf )
1813         Uint8 *buf
1814         CODE:
1815                 RETVAL = Mix_QuickLoad_WAV(buf);
1816         OUTPUT:
1817                 RETVAL
1818
1819 void
1820 MixFreeChunk( chunk )
1821         Mix_Chunk *chunk
1822         CODE:
1823                 Mix_FreeChunk(chunk);
1824
1825 void
1826 MixFreeMusic ( music )
1827         Mix_Music *music
1828         CODE:
1829                 Mix_FreeMusic(music);
1830
1831 void
1832 MixSetPostMixCallback ( func, arg )
1833         void *func
1834         void *arg
1835         CODE:
1836                 Mix_SetPostMix(func,arg);
1837
1838 void*
1839 PerlMixMusicHook ()
1840         CODE:
1841                 RETVAL = sdl_perl_music_callback;
1842         OUTPUT:
1843                 RETVAL
1844
1845 void
1846 MixSetMusicHook ( func, arg )
1847         void *func
1848         void *arg
1849         CODE:
1850                 Mix_HookMusic(func,arg);
1851
1852 void
1853 MixSetMusicFinishedHook ( func )
1854         void *func
1855         CODE:
1856                 mix_music_finished_cv = func;
1857                 Mix_HookMusicFinished(sdl_perl_music_finished_callback);
1858
1859 void *
1860 MixGetMusicHookData ()
1861         CODE:
1862                 RETVAL = Mix_GetMusicHookData();
1863         OUTPUT:
1864                 RETVAL
1865
1866 int
1867 MixReverseChannels ( number )
1868         int number
1869         CODE:
1870                 RETVAL = Mix_ReserveChannels ( number );
1871         OUTPUT:
1872                 RETVAL
1873
1874 int
1875 MixGroupChannel ( which, tag )
1876         int which
1877         int tag
1878         CODE:
1879                 RETVAL = Mix_GroupChannel(which,tag);
1880         OUTPUT:
1881                 RETVAL
1882
1883 int
1884 MixGroupChannels ( from, to, tag )
1885         int from
1886         int to
1887         int tag
1888         CODE:
1889                 RETVAL = Mix_GroupChannels(from,to,tag);
1890         OUTPUT:
1891                 RETVAL
1892
1893 int
1894 MixGroupAvailable ( tag )
1895         int tag
1896         CODE:
1897                 RETVAL = Mix_GroupAvailable(tag);
1898         OUTPUT:
1899                 RETVAL
1900
1901 int
1902 MixGroupCount ( tag )
1903         int tag
1904         CODE:
1905                 RETVAL = Mix_GroupCount(tag);
1906         OUTPUT:
1907                 RETVAL
1908
1909 int
1910 MixGroupOldest ( tag )
1911         int tag
1912         CODE:
1913                 RETVAL = Mix_GroupOldest(tag);
1914         OUTPUT:
1915                 RETVAL
1916
1917 int
1918 MixGroupNewer ( tag )
1919         int tag
1920         CODE:
1921                 RETVAL = Mix_GroupNewer(tag);
1922         OUTPUT:
1923                 RETVAL
1924
1925 int
1926 MixPlayChannel ( channel, chunk, loops )
1927         int channel
1928         Mix_Chunk *chunk
1929         int loops
1930         CODE:
1931                 RETVAL = Mix_PlayChannel(channel,chunk,loops);
1932         OUTPUT:
1933                 RETVAL
1934
1935 int
1936 MixPlayChannelTimed ( channel, chunk, loops, ticks )
1937         int channel
1938         Mix_Chunk *chunk
1939         int loops
1940         int ticks
1941         CODE:
1942                 RETVAL = Mix_PlayChannelTimed(channel,chunk,loops,ticks);
1943         OUTPUT:
1944                 RETVAL
1945
1946 int
1947 MixPlayMusic ( music, loops )
1948         Mix_Music *music
1949         int loops
1950         CODE:
1951                 RETVAL = Mix_PlayMusic(music,loops);
1952         OUTPUT:
1953                 RETVAL
1954
1955 int
1956 MixFadeInChannel ( channel, chunk, loops, ms )
1957         int channel
1958         Mix_Chunk *chunk
1959         int loops
1960         int ms
1961         CODE:
1962                 RETVAL = Mix_FadeInChannel(channel,chunk,loops,ms);
1963         OUTPUT:
1964                 RETVAL
1965
1966 int
1967 MixFadeInChannelTimed ( channel, chunk, loops, ms, ticks )
1968         int channel
1969         Mix_Chunk *chunk
1970         int loops
1971         int ticks
1972         int ms
1973         CODE:
1974                 RETVAL = Mix_FadeInChannelTimed(channel,chunk,loops,ms,ticks);
1975         OUTPUT:
1976                 RETVAL
1977
1978 int
1979 MixFadeInMusic ( music, loops, ms )
1980         Mix_Music *music
1981         int loops
1982         int ms
1983         CODE:
1984                 RETVAL = Mix_FadeInMusic(music,loops,ms);
1985         OUTPUT:
1986                 RETVAL
1987
1988 int
1989 MixVolume ( channel, volume )
1990         int channel
1991         int volume
1992         CODE:   
1993                 RETVAL = Mix_Volume(channel,volume);
1994         OUTPUT:
1995                 RETVAL
1996
1997 int
1998 MixVolumeChunk ( chunk, volume )
1999         Mix_Chunk *chunk
2000         int volume
2001         CODE:
2002                 RETVAL = Mix_VolumeChunk(chunk,volume);
2003         OUTPUT:
2004                 RETVAL
2005
2006 int
2007 MixVolumeMusic ( volume )
2008         int volume
2009         CODE:
2010                 RETVAL = Mix_VolumeMusic(volume);
2011         OUTPUT:
2012                 RETVAL
2013
2014 int
2015 MixHaltChannel ( channel )
2016         int channel
2017         CODE:
2018                 RETVAL = Mix_HaltChannel(channel);
2019         OUTPUT:
2020                 RETVAL
2021
2022 int
2023 MixHaltGroup ( tag )
2024         int tag
2025         CODE:
2026                 RETVAL = Mix_HaltGroup(tag);
2027         OUTPUT:
2028                 RETVAL
2029
2030 int
2031 MixHaltMusic ()
2032         CODE:
2033                 RETVAL = Mix_HaltMusic();
2034         OUTPUT:
2035                 RETVAL
2036
2037 int
2038 MixExpireChannel ( channel, ticks )
2039         int channel
2040         int ticks
2041         CODE:
2042                 RETVAL = Mix_ExpireChannel ( channel,ticks);
2043         OUTPUT:
2044                 RETVAL
2045
2046 int
2047 MixFadeOutChannel ( which, ms )
2048         int which
2049         int ms
2050         CODE:
2051                 RETVAL = Mix_FadeOutChannel(which,ms);
2052         OUTPUT:
2053                 RETVAL
2054
2055 int
2056 MixFadeOutGroup ( which, ms )
2057         int which
2058         int ms
2059         CODE:
2060                 RETVAL = Mix_FadeOutGroup(which,ms);
2061         OUTPUT:
2062                 RETVAL
2063
2064 int
2065 MixFadeOutMusic ( ms )
2066         int ms
2067         CODE:
2068                 RETVAL = Mix_FadeOutMusic(ms);
2069         OUTPUT:
2070                 RETVAL
2071
2072 Mix_Fading
2073 MixFadingMusic()
2074         CODE:
2075                 RETVAL = Mix_FadingMusic();
2076         OUTPUT:
2077                 RETVAL
2078
2079 Mix_Fading
2080 MixFadingChannel( which )
2081         int which
2082         CODE:
2083                 RETVAL = Mix_FadingChannel(which);
2084         OUTPUT:
2085                 RETVAL
2086
2087 void
2088 MixPause ( channel )
2089         int channel
2090         CODE:
2091                 Mix_Pause(channel);
2092
2093 void
2094 MixResume ( channel )
2095         int channel
2096         CODE:
2097                 Mix_Resume(channel);
2098
2099 int
2100 MixPaused ( channel )
2101         int channel
2102         CODE:
2103                 RETVAL = Mix_Paused(channel);
2104         OUTPUT:
2105                 RETVAL
2106
2107 void
2108 MixPauseMusic ()
2109         CODE:
2110                 Mix_PauseMusic();
2111
2112 void
2113 MixResumeMusic ()
2114         CODE:
2115                 Mix_ResumeMusic();
2116
2117 void
2118 MixRewindMusic ()
2119         CODE:
2120                 Mix_RewindMusic();
2121
2122 int
2123 MixPausedMusic ()
2124         CODE:
2125                 RETVAL = Mix_PausedMusic();
2126         OUTPUT:
2127                 RETVAL
2128
2129 int
2130 MixPlaying( channel )
2131         int channel     
2132         CODE:
2133                 RETVAL = Mix_Playing(channel);
2134         OUTPUT:
2135                 RETVAL
2136
2137 int
2138 MixPlayingMusic()
2139         CODE:
2140                 RETVAL = Mix_PlayingMusic();
2141         OUTPUT:
2142                 RETVAL
2143
2144 int
2145 MixSetPanning ( channel, left, right )
2146         int channel
2147         int left
2148         int right
2149         CODE:
2150                 RETVAL = Mix_SetPanning(channel, left, right);
2151         OUTPUT:
2152                 RETVAL
2153
2154 void
2155 MixCloseAudio ()
2156         CODE:
2157                 Mix_CloseAudio();
2158
2159 #endif
2160
2161 int
2162 GLLoadLibrary ( path )
2163         char *path
2164         CODE:
2165                 RETVAL = SDL_GL_LoadLibrary(path);
2166         OUTPUT:
2167                 RETVAL
2168
2169 void*
2170 GLGetProcAddress ( proc )
2171         char *proc
2172         CODE:
2173                 RETVAL = SDL_GL_GetProcAddress(proc);
2174         OUTPUT:
2175                 RETVAL
2176
2177 int
2178 GLSetAttribute ( attr,  value )
2179         int        attr
2180         int        value
2181         CODE:
2182                 RETVAL = SDL_GL_SetAttribute(attr, value);
2183         OUTPUT:
2184                 RETVAL
2185
2186 AV *
2187 GLGetAttribute ( attr )
2188         int        attr
2189         CODE:
2190                 int value;
2191                 RETVAL = newAV();
2192                 av_push(RETVAL,newSViv(SDL_GL_GetAttribute(attr, &value)));
2193                 av_push(RETVAL,newSViv(value));
2194         OUTPUT:
2195                 RETVAL
2196
2197 void
2198 GLSwapBuffers ()
2199         CODE:
2200                 SDL_GL_SwapBuffers ();
2201
2202
2203 int
2204 BigEndian ()
2205         CODE:
2206                 RETVAL = (SDL_BYTEORDER == SDL_BIG_ENDIAN);
2207         OUTPUT:
2208                 RETVAL
2209
2210 int
2211 NumJoysticks ()
2212         CODE:
2213                 RETVAL = SDL_NumJoysticks();
2214         OUTPUT:
2215                 RETVAL
2216
2217 char *
2218 JoystickName ( index )
2219         int index
2220         CODE:
2221                 RETVAL = (char*)SDL_JoystickName(index);
2222         OUTPUT:
2223                 RETVAL
2224
2225 SDL_Joystick *
2226 JoystickOpen ( index ) 
2227         int index
2228         CODE:
2229                 RETVAL = SDL_JoystickOpen(index);
2230         OUTPUT:
2231                 RETVAL
2232
2233 int
2234 JoystickOpened ( index )
2235         int index
2236         CODE:
2237                 RETVAL = SDL_JoystickOpened(index);
2238         OUTPUT:
2239                 RETVAL
2240
2241 int
2242 JoystickIndex ( joystick )
2243         SDL_Joystick *joystick
2244         CODE:
2245                 RETVAL = SDL_JoystickIndex(joystick);
2246         OUTPUT:
2247                 RETVAL
2248
2249 int
2250 JoystickNumAxes ( joystick )
2251         SDL_Joystick *joystick
2252         CODE:
2253                 RETVAL = SDL_JoystickNumAxes(joystick);
2254         OUTPUT:
2255                 RETVAL
2256
2257 int
2258 JoystickNumBalls ( joystick )
2259         SDL_Joystick *joystick
2260         CODE:
2261                 RETVAL = SDL_JoystickNumBalls(joystick);
2262         OUTPUT:
2263                 RETVAL
2264
2265 int
2266 JoystickNumHats ( joystick )
2267         SDL_Joystick *joystick
2268         CODE:
2269                 RETVAL = SDL_JoystickNumHats(joystick);
2270         OUTPUT:
2271                 RETVAL
2272
2273 int
2274 JoystickNumButtons ( joystick )
2275         SDL_Joystick *joystick
2276         CODE:
2277                 RETVAL = SDL_JoystickNumButtons(joystick);
2278         OUTPUT:
2279                 RETVAL
2280
2281 void
2282 JoystickUpdate ()
2283         CODE:
2284                 SDL_JoystickUpdate();
2285
2286 Sint16
2287 JoystickGetAxis ( joystick, axis )
2288         SDL_Joystick *joystick
2289         int axis
2290         CODE:
2291                 RETVAL = SDL_JoystickGetAxis(joystick,axis);
2292         OUTPUT:
2293                 RETVAL
2294
2295 Uint8
2296 JoystickGetHat ( joystick, hat )
2297         SDL_Joystick *joystick
2298         int hat 
2299         CODE:
2300                 RETVAL = SDL_JoystickGetHat(joystick,hat);
2301         OUTPUT:
2302                 RETVAL
2303
2304 Uint8
2305 JoystickGetButton ( joystick, button)
2306         SDL_Joystick *joystick
2307         int button 
2308         CODE:
2309                 RETVAL = SDL_JoystickGetButton(joystick,button);
2310         OUTPUT:
2311                 RETVAL
2312
2313 AV *
2314 JoystickGetBall ( joystick, ball )
2315         SDL_Joystick *joystick
2316         int ball 
2317         CODE:
2318                 int success,dx,dy;
2319                 success = SDL_JoystickGetBall(joystick,ball,&dx,&dy);
2320                 RETVAL = newAV();
2321                 av_push(RETVAL,newSViv(success));
2322                 av_push(RETVAL,newSViv(dx));
2323                 av_push(RETVAL,newSViv(dy));
2324         OUTPUT:
2325                 RETVAL  
2326
2327 void
2328 JoystickClose ( joystick )
2329         SDL_Joystick *joystick
2330         CODE:
2331                 SDL_JoystickClose(joystick);
2332
2333 Sint16
2334 JoyAxisEventWhich ( e )
2335         SDL_Event *e
2336         CODE:
2337                 RETVAL = e->jaxis.which;
2338         OUTPUT:
2339                 RETVAL
2340
2341 Uint8
2342 JoyAxisEventAxis ( e )
2343         SDL_Event *e
2344         CODE:
2345                 RETVAL = e->jaxis.axis;
2346         OUTPUT:
2347                 RETVAL
2348
2349 Sint16
2350 JoyAxisEventValue ( e )
2351         SDL_Event *e
2352         CODE:
2353                 RETVAL = e->jaxis.value;
2354         OUTPUT:
2355                 RETVAL
2356
2357 Uint8
2358 JoyButtonEventWhich ( e )
2359         SDL_Event *e
2360         CODE:
2361                 RETVAL = e->jbutton.which;
2362         OUTPUT:
2363                 RETVAL
2364
2365 Uint8
2366 JoyButtonEventButton ( e )
2367         SDL_Event *e
2368         CODE:
2369                 RETVAL = e->jbutton.button;
2370         OUTPUT:
2371                 RETVAL
2372
2373 Uint8
2374 JoyButtonEventState ( e )
2375         SDL_Event *e
2376         CODE:
2377                 RETVAL = e->jbutton.state;
2378         OUTPUT:
2379                 RETVAL
2380         
2381 Uint8
2382 JoyHatEventWhich ( e )
2383         SDL_Event *e
2384         CODE:
2385                 RETVAL = e->jhat.which;
2386         OUTPUT:
2387                 RETVAL
2388
2389 Uint8
2390 JoyHatEventHat ( e )
2391         SDL_Event *e
2392         CODE:
2393                 RETVAL = e->jhat.hat;
2394         OUTPUT:
2395                 RETVAL
2396
2397 Uint8
2398 JoyHatEventValue ( e )
2399         SDL_Event *e
2400         CODE:
2401                 RETVAL = e->jhat.value;
2402         OUTPUT:
2403                 RETVAL
2404
2405 Uint8
2406 JoyBallEventWhich ( e )
2407         SDL_Event *e
2408         CODE: 
2409                 RETVAL = e->jball.which;
2410         OUTPUT:
2411                 RETVAL
2412
2413 Uint8
2414 JoyBallEventBall ( e )
2415         SDL_Event *e
2416         CODE:
2417                 RETVAL = e->jball.ball;
2418         OUTPUT:
2419                 RETVAL
2420
2421 Sint16
2422 JoyBallEventXrel ( e )
2423         SDL_Event *e
2424         CODE:
2425                 RETVAL = e->jball.xrel;
2426         OUTPUT:
2427                 RETVAL
2428
2429 Sint16
2430 JoyBallEventYrel ( e )
2431         SDL_Event *e
2432         CODE:
2433                 RETVAL = e->jball.yrel;
2434         OUTPUT:
2435                 RETVAL
2436
2437 void
2438 SetClipRect ( surface, rect )
2439         SDL_Surface *surface
2440         SDL_Rect *rect
2441         CODE:
2442                 SDL_SetClipRect(surface,rect);
2443         
2444 void
2445 GetClipRect ( surface, rect )
2446         SDL_Surface *surface
2447         SDL_Rect *rect;
2448         CODE:
2449                 SDL_GetClipRect(surface, rect);
2450
2451
2452 #ifdef HAVE_SDL_NET
2453
2454 int
2455 NetInit ()
2456         CODE:
2457                 RETVAL = SDLNet_Init();
2458         OUTPUT:
2459                 RETVAL
2460
2461 void
2462 NetQuit ()
2463         CODE:
2464                 SDLNet_Quit();
2465
2466 IPaddress*
2467 NetNewIPaddress ( host, port )
2468         Uint32 host
2469         Uint16 port
2470         CODE:
2471                 RETVAL = (IPaddress*) safemalloc(sizeof(IPaddress));
2472                 RETVAL->host = host;
2473                 RETVAL->port = port;
2474         OUTPUT:
2475                 RETVAL
2476
2477 Uint32
2478 NetIPaddressHost ( ip )
2479         IPaddress *ip
2480         CODE:
2481                 RETVAL = ip->host;
2482         OUTPUT:
2483                 RETVAL
2484
2485 Uint16
2486 NetIPaddressPort ( ip )
2487         IPaddress *ip
2488         CODE:
2489                 RETVAL = ip->port;
2490         OUTPUT:
2491                 RETVAL
2492
2493 void
2494 NetFreeIPaddress ( ip )
2495         IPaddress *ip
2496         CODE:
2497                 safefree(ip);
2498
2499 const char*
2500 NetResolveIP ( address )
2501         IPaddress *address
2502         CODE:
2503                 RETVAL = SDLNet_ResolveIP(address);
2504         OUTPUT:
2505                 RETVAL
2506
2507 int
2508 NetResolveHost ( address, host, port )
2509         IPaddress *address
2510         const char *host
2511         Uint16 port
2512         CODE:
2513                 RETVAL = SDLNet_ResolveHost(address,host,port);
2514         OUTPUT:
2515                 RETVAL
2516         
2517 TCPsocket
2518 NetTCPOpen ( ip )
2519         IPaddress *ip
2520         CODE:
2521                 RETVAL = SDLNet_TCP_Open(ip);
2522         OUTPUT:
2523                 RETVAL
2524
2525 TCPsocket
2526 NetTCPAccept ( server )
2527         TCPsocket server
2528         CODE:
2529                 RETVAL = SDLNet_TCP_Accept(server);
2530         OUTPUT:
2531                 RETVAL
2532
2533 IPaddress*
2534 NetTCPGetPeerAddress ( sock )
2535         TCPsocket sock
2536         CODE:
2537                 RETVAL = SDLNet_TCP_GetPeerAddress(sock);
2538         OUTPUT:
2539                 RETVAL
2540
2541 int
2542 NetTCPSend ( sock, data, len  )
2543         TCPsocket sock
2544         void *data
2545         int len
2546         CODE:
2547                 RETVAL = SDLNet_TCP_Send(sock,data,len);
2548         OUTPUT:
2549                 RETVAL
2550
2551 AV*
2552 NetTCPRecv ( sock, maxlen )
2553         TCPsocket sock
2554         int maxlen
2555         CODE:
2556                 int status;
2557                 void *buffer;
2558                 buffer = safemalloc(maxlen);
2559                 RETVAL = newAV();
2560                 status = SDLNet_TCP_Recv(sock,buffer,maxlen);
2561                 av_push(RETVAL,newSViv(status));
2562                 av_push(RETVAL,newSVpvn((char*)buffer,maxlen));
2563         OUTPUT:
2564                 RETVAL  
2565         
2566 void
2567 NetTCPClose ( sock )
2568         TCPsocket sock
2569         CODE:
2570                 SDLNet_TCP_Close(sock);
2571
2572 UDPpacket*
2573 NetAllocPacket ( size )
2574         int size
2575         CODE:
2576                 RETVAL = SDLNet_AllocPacket(size);
2577         OUTPUT:
2578                 RETVAL
2579
2580 UDPpacket**
2581 NetAllocPacketV ( howmany, size )
2582         int howmany
2583         int size
2584         CODE:
2585                 RETVAL = SDLNet_AllocPacketV(howmany,size);
2586         OUTPUT:
2587                 RETVAL
2588
2589 int
2590 NetResizePacket ( packet, newsize )
2591         UDPpacket *packet
2592         int newsize
2593         CODE:
2594                 RETVAL = SDLNet_ResizePacket(packet,newsize);
2595         OUTPUT:
2596                 RETVAL
2597
2598 void
2599 NetFreePacket ( packet )
2600         UDPpacket *packet
2601         CODE:
2602                 SDLNet_FreePacket(packet);
2603
2604 void
2605 NetFreePacketV ( packet )
2606         UDPpacket **packet
2607         CODE:
2608                 SDLNet_FreePacketV(packet);
2609
2610 UDPsocket
2611 NetUDPOpen ( port )
2612         Uint16 port
2613         CODE:
2614                 RETVAL = SDLNet_UDP_Open(port);
2615         OUTPUT:
2616                 RETVAL
2617
2618 int
2619 NetUDPBind ( sock, channel, address )
2620         UDPsocket sock
2621         int channel
2622         IPaddress *address
2623         CODE:
2624                 RETVAL = SDLNet_UDP_Bind(sock,channel,address);
2625         OUTPUT:
2626                 RETVAL
2627
2628 void
2629 NetUDPUnbind ( sock, channel )
2630         UDPsocket sock
2631         int channel
2632         CODE:
2633                 SDLNet_UDP_Unbind(sock,channel);
2634
2635 IPaddress*
2636 NetUDPGetPeerAddress ( sock, channel )
2637         UDPsocket sock
2638         int channel
2639         CODE:
2640                 RETVAL = SDLNet_UDP_GetPeerAddress(sock,channel);
2641         OUTPUT:
2642                 RETVAL
2643
2644 int
2645 NetUDPSendV ( sock, packets, npackets )
2646         UDPsocket sock
2647         UDPpacket **packets
2648         int npackets
2649         CODE:
2650                 RETVAL = SDLNet_UDP_SendV(sock,packets,npackets);
2651         OUTPUT:
2652                 RETVAL
2653
2654 int
2655 NetUDPSend ( sock, channel, packet )
2656         UDPsocket sock
2657         int channel
2658         UDPpacket *packet 
2659         CODE:
2660                 RETVAL = SDLNet_UDP_Send(sock,channel,packet);
2661         OUTPUT:
2662                 RETVAL
2663
2664 int
2665 NetUDPRecvV ( sock, packets )
2666         UDPsocket sock
2667         UDPpacket **packets
2668         CODE:
2669                 RETVAL = SDLNet_UDP_RecvV(sock,packets);
2670         OUTPUT:
2671                 RETVAL
2672
2673 int
2674 NetUDPRecv ( sock, packet )
2675         UDPsocket sock
2676         UDPpacket *packet
2677         CODE:
2678                 RETVAL = SDLNet_UDP_Recv(sock,packet);
2679         OUTPUT:
2680                 RETVAL
2681
2682 void
2683 NetUDPClose ( sock )
2684         UDPsocket sock
2685         CODE:
2686                 SDLNet_UDP_Close(sock);
2687
2688 SDLNet_SocketSet
2689 NetAllocSocketSet ( maxsockets )
2690         int maxsockets
2691         CODE:
2692                 RETVAL = SDLNet_AllocSocketSet(maxsockets);
2693         OUTPUT:
2694                 RETVAL
2695
2696 int
2697 NetTCP_AddSocket ( set, sock )
2698         SDLNet_SocketSet set
2699         TCPsocket sock
2700         CODE:
2701                 RETVAL = SDLNet_TCP_AddSocket(set,sock);
2702         OUTPUT:
2703                 RETVAL
2704
2705 int
2706 NetUDP_AddSocket ( set, sock )
2707         SDLNet_SocketSet set
2708         UDPsocket sock
2709         CODE:
2710                 RETVAL = SDLNet_UDP_AddSocket(set,sock);
2711         OUTPUT:
2712                 RETVAL
2713
2714 int
2715 NetTCP_DelSocket ( set, sock )
2716         SDLNet_SocketSet set
2717         TCPsocket sock
2718         CODE:
2719                 RETVAL = SDLNet_TCP_DelSocket(set,sock);
2720         OUTPUT:
2721                 RETVAL
2722
2723 int
2724 NetUDP_DelSocket ( set, sock )
2725         SDLNet_SocketSet set
2726         UDPsocket sock
2727         CODE:
2728                 RETVAL = SDLNet_UDP_DelSocket(set,sock);
2729         OUTPUT:
2730                 RETVAL
2731
2732 int
2733 NetCheckSockets ( set, timeout )
2734         SDLNet_SocketSet set
2735         Uint32 timeout
2736         CODE:
2737                 RETVAL = SDLNet_CheckSockets(set,timeout);
2738         OUTPUT:
2739                 RETVAL
2740
2741 int
2742 NetSocketReady ( sock )
2743         SDLNet_GenericSocket sock
2744         CODE:
2745                 RETVAL = SDLNet_SocketReady(sock);
2746         OUTPUT:
2747                 RETVAL
2748
2749 void
2750 NetFreeSocketSet ( set )
2751         SDLNet_SocketSet set
2752         CODE:
2753                 SDLNet_FreeSocketSet(set);
2754
2755 void
2756 NetWrite16 ( value, area )
2757         Uint16 value
2758         void *area
2759         CODE:
2760                 SDLNet_Write16(value,area);
2761
2762 void
2763 NetWrite32 ( value, area )
2764         Uint32 value
2765         void *area
2766         CODE:
2767                 SDLNet_Write32(value,area);
2768         
2769 Uint16
2770 NetRead16 ( area )
2771         void *area
2772         CODE:
2773                 RETVAL = SDLNet_Read16(area);
2774         OUTPUT:
2775                 RETVAL
2776
2777 Uint32
2778 NetRead32 ( area )
2779         void *area
2780         CODE:
2781                 RETVAL = SDLNet_Read32(area);
2782         OUTPUT:
2783                 RETVAL
2784
2785 #endif 
2786
2787 int
2788 LockYUVOverlay ( overlay )
2789         SDL_Overlay *overlay
2790         CODE:
2791                 RETVAL = SDL_LockYUVOverlay(overlay);
2792         OUTPUT:
2793                 RETVAL
2794
2795 void
2796 UnlockYUVOverlay ( overlay )
2797         SDL_Overlay *overlay
2798         CODE:
2799                 SDL_UnlockYUVOverlay(overlay);
2800
2801 int
2802 DisplayYUVOverlay ( overlay, dstrect )
2803         SDL_Overlay *overlay
2804         SDL_Rect *dstrect
2805         CODE:
2806                 RETVAL = SDL_DisplayYUVOverlay ( overlay, dstrect );
2807         OUTPUT:
2808                 RETVAL
2809
2810 Uint32
2811 OverlayFormat ( overlay, ... )
2812         SDL_Overlay *overlay
2813         CODE:
2814                 if ( items > 1 ) 
2815                         overlay->format = SvIV(ST(1));
2816                 RETVAL = overlay->format;
2817         OUTPUT:
2818                 RETVAL
2819
2820 int 
2821 OverlayW ( overlay, ... )
2822         SDL_Overlay *overlay
2823         CODE:
2824                 if ( items > 1 ) 
2825                         overlay->w = SvIV(ST(1));
2826                 RETVAL = overlay->w;
2827         OUTPUT:
2828                 RETVAL
2829
2830 int
2831 OverlayH ( overlay, ... )
2832         SDL_Overlay *overlay
2833         CODE:
2834                 if ( items > 1 )
2835                         overlay->h = SvIV(ST(1));
2836                 RETVAL = overlay->h;
2837         OUTPUT:
2838                 RETVAL 
2839
2840 int
2841 OverlayPlanes ( overlay, ... )
2842         SDL_Overlay *overlay
2843         CODE:
2844                 if ( items > 1 )
2845                         overlay->planes = SvIV(ST(1));
2846                 RETVAL = overlay->planes;
2847         OUTPUT:
2848                 RETVAL
2849
2850 Uint32
2851 OverlayHW ( overlay )
2852         SDL_Overlay *overlay
2853         CODE:
2854                 RETVAL = overlay->hw_overlay;
2855         OUTPUT:
2856                 RETVAL
2857
2858 Uint16*
2859 OverlayPitches ( overlay )
2860         SDL_Overlay *overlay
2861         CODE:
2862                 RETVAL = overlay->pitches;
2863         OUTPUT:
2864                 RETVAL
2865
2866 Uint8**
2867 OverlayPixels ( overlay )
2868         SDL_Overlay *overlay
2869         CODE:
2870                 RETVAL = overlay->pixels;
2871         OUTPUT:
2872                 RETVAL
2873
2874 int
2875 WMToggleFullScreen ( surface )
2876         SDL_Surface *surface
2877         CODE:
2878                 RETVAL = SDL_WM_ToggleFullScreen(surface);
2879         OUTPUT:
2880                 RETVAL
2881
2882 Uint32
2883 WMGrabInput ( mode )
2884         Uint32 mode
2885         CODE:
2886                 RETVAL = SDL_WM_GrabInput(mode);
2887         OUTPUT:
2888                 RETVAL
2889
2890 int
2891 WMIconifyWindow ()
2892         CODE:
2893                 RETVAL = SDL_WM_IconifyWindow();
2894         OUTPUT:
2895                 RETVAL
2896
2897 int
2898 ResizeEventW ( e )
2899         SDL_Event *e
2900         CODE:
2901                 RETVAL = e->resize.w;
2902         OUTPUT:
2903                 RETVAL
2904
2905 int
2906 ResizeEventH ( e )
2907         SDL_Event *e
2908         CODE:
2909                 RETVAL = e->resize.h;
2910         OUTPUT:
2911                 RETVAL
2912
2913 char*
2914 AudioDriverName ()
2915         CODE:
2916                 char name[32];
2917                 RETVAL = SDL_AudioDriverName(name,32);
2918         OUTPUT:
2919                 RETVAL
2920
2921 Uint32
2922 GetKeyState ( k )
2923         SDLKey k
2924         CODE:
2925                 if (k >= SDLK_LAST) Perl_croak (aTHX_ "Key out of range");      
2926                 RETVAL = SDL_GetKeyState(NULL)[k];
2927         OUTPUT:
2928                 RETVAL
2929
2930 #ifdef HAVE_SMPEG
2931
2932 SMPEG_Info *
2933 NewSMPEGInfo()
2934         CODE:   
2935                 RETVAL = (SMPEG_Info *) safemalloc (sizeof(SMPEG_Info));
2936         OUTPUT:
2937                 RETVAL
2938
2939 void
2940 FreeSMPEGInfo ( info )
2941         SMPEG_Info *info
2942         CODE:   
2943                 safefree(info);
2944
2945 int
2946 SMPEGInfoHasAudio ( info )
2947         SMPEG_Info* info
2948         CODE:
2949                 RETVAL = info->has_audio;
2950         OUTPUT:
2951                 RETVAL
2952
2953 int
2954 SMPEGInfoHasVideo ( info )
2955         SMPEG_Info* info
2956         CODE:
2957                 RETVAL = info->has_video;
2958         OUTPUT:
2959                 RETVAL
2960
2961 int
2962 SMPEGInfoWidth ( info )
2963         SMPEG_Info* info
2964         CODE:
2965                 RETVAL = info->width;
2966         OUTPUT:
2967                 RETVAL
2968
2969 int
2970 SMPEGInfoHeight ( info )
2971         SMPEG_Info* info
2972         CODE:
2973                 RETVAL = info->height;
2974         OUTPUT:
2975                 RETVAL
2976
2977 int
2978 SMPEGInfoCurrentFrame ( info )
2979         SMPEG_Info* info
2980         CODE:
2981                 RETVAL = info->current_frame;
2982         OUTPUT:
2983                 RETVAL
2984
2985 double
2986 SMPEGInfoCurrentFPS ( info )
2987         SMPEG_Info* info
2988         CODE:
2989                 RETVAL = info->current_fps;
2990         OUTPUT:
2991                 RETVAL
2992
2993 int
2994 SMPEGInfoCurrentAudioFrame ( info )
2995         SMPEG_Info* info
2996         CODE:
2997                 RETVAL = info->audio_current_frame;
2998         OUTPUT:
2999                 RETVAL
3000
3001 int
3002 SMPEGInfoCurrentOffset ( info )
3003         SMPEG_Info* info
3004         CODE:
3005                 RETVAL = info->current_offset;
3006         OUTPUT:
3007                 RETVAL
3008
3009 int
3010 SMPEGInfoTotalSize ( info )
3011         SMPEG_Info* info
3012         CODE:
3013                 RETVAL = info->total_size;
3014         OUTPUT:
3015                 RETVAL
3016
3017 double
3018 SMPEGInfoCurrentTime ( info )
3019         SMPEG_Info* info
3020         CODE:
3021                 RETVAL = info->current_time;
3022         OUTPUT:
3023                 RETVAL
3024
3025 double
3026 SMPEGInfoTotalTime ( info )
3027         SMPEG_Info* info
3028         CODE:
3029                 RETVAL = info->total_time;
3030         OUTPUT:
3031                 RETVAL
3032
3033 char *
3034 SMPEGError ( mpeg )
3035         SMPEG* mpeg
3036         CODE:   
3037                 RETVAL = SMPEG_error(mpeg);
3038         OUTPUT:
3039                 RETVAL
3040
3041 SMPEG*
3042 NewSMPEG ( filename, info, use_audio )
3043         char* filename
3044         SMPEG_Info* info
3045         int use_audio
3046         CODE:   
3047 #ifdef HAVE_SDL_MIXER
3048                 RETVAL = SMPEG_new(filename,info,0);
3049 #else
3050                 RETVAL = SMPEG_new(filename,info,use_audio);
3051 #endif
3052         OUTPUT:
3053                 RETVAL
3054
3055 void
3056 FreeSMPEG ( mpeg )
3057         SMPEG* mpeg
3058         CODE:
3059                 SMPEG_delete(mpeg);
3060
3061 void
3062 SMPEGEnableAudio ( mpeg , flag )
3063         SMPEG* mpeg
3064         int flag
3065         CODE:   
3066                 SMPEG_enableaudio(mpeg,flag);
3067 #ifdef HAVE_SDL_MIXER
3068                 sdl_perl_use_smpeg_audio = flag;
3069 #endif
3070
3071 void
3072 SMPEGEnableVideo ( mpeg , flag )
3073         SMPEG* mpeg
3074         int flag
3075         CODE:   
3076                 SMPEG_enablevideo(mpeg,flag);
3077
3078 void
3079 SMPEGSetVolume ( mpeg , volume )
3080         SMPEG* mpeg
3081         int volume
3082         CODE:   
3083                 SMPEG_setvolume(mpeg,volume);
3084
3085 void
3086 SMPEGSetDisplay ( mpeg, dest, surfLock )
3087         SMPEG* mpeg
3088         SDL_Surface* dest
3089         SDL_mutex*  surfLock
3090         CODE:
3091                 SMPEG_setdisplay(mpeg,dest,surfLock,NULL);
3092
3093 void
3094 SMPEGScaleXY ( mpeg, w, h)
3095         SMPEG* mpeg
3096         int w
3097         int h
3098         CODE:
3099                 SMPEG_scaleXY(mpeg,w,h);
3100
3101 void
3102 SMPEGScale ( mpeg, scale )
3103         SMPEG* mpeg
3104         int scale
3105         CODE:
3106                 SMPEG_scale(mpeg,scale);
3107
3108 void
3109 SMPEGPlay ( mpeg )
3110         SMPEG* mpeg
3111         CODE:
3112                 SDL_AudioSpec audiofmt;
3113                 Uint16 format;
3114                 int freq, channels;
3115 #ifdef HAVE_SDL_MIXER
3116                 if  (sdl_perl_use_smpeg_audio ) {
3117                         SMPEG_enableaudio(mpeg, 0);
3118                         Mix_QuerySpec(&freq, &format, &channels);
3119                         audiofmt.format = format;
3120                         audiofmt.freq = freq;
3121                         audiofmt.channels = channels;
3122                         SMPEG_actualSpec(mpeg, &audiofmt);
3123                         Mix_HookMusic(SMPEG_playAudioSDL, mpeg);
3124                         SMPEG_enableaudio(mpeg, 1);
3125                 }
3126 #endif
3127                 SMPEG_play(mpeg);
3128
3129 SMPEGstatus
3130 SMPEGStatus ( mpeg )
3131         SMPEG* mpeg
3132         CODE:
3133                 RETVAL = SMPEG_status(mpeg);
3134         OUTPUT:
3135                 RETVAL
3136
3137 void
3138 SMPEGPause ( mpeg )
3139         SMPEG* mpeg
3140         CODE:
3141                 SMPEG_pause(mpeg);
3142
3143 void
3144 SMPEGLoop ( mpeg, repeat )
3145         SMPEG* mpeg
3146         int repeat
3147         CODE:
3148                 SMPEG_loop(mpeg,repeat);
3149
3150 void
3151 SMPEGStop ( mpeg )
3152         SMPEG* mpeg
3153         CODE:
3154                 SMPEG_stop(mpeg);
3155 #ifdef HAVE_SDL_MIXER
3156                 Mix_HookMusic(NULL, NULL);
3157 #endif
3158
3159 void
3160 SMPEGRewind ( mpeg )
3161         SMPEG* mpeg
3162         CODE:
3163                 SMPEG_rewind(mpeg);
3164
3165 void
3166 SMPEGSeek ( mpeg, bytes )
3167         SMPEG* mpeg
3168         int bytes
3169         CODE:
3170                 SMPEG_seek(mpeg,bytes);
3171
3172 void
3173 SMPEGSkip ( mpeg, seconds )
3174         SMPEG* mpeg
3175         float seconds
3176         CODE:
3177                 SMPEG_skip(mpeg,seconds);
3178
3179 void
3180 SMPEGSetDisplayRegion ( mpeg, rect )
3181         SMPEG* mpeg
3182         SDL_Rect* rect
3183         CODE:
3184                 SMPEG_setdisplayregion(mpeg,rect->x,rect->y,rect->w,rect->h);
3185
3186 void
3187 SMPEGRenderFrame ( mpeg, frame )
3188         SMPEG* mpeg
3189         int frame
3190         CODE:
3191                 SMPEG_renderFrame(mpeg,frame);
3192
3193 SMPEG_Info *
3194 SMPEGGetInfo ( mpeg )
3195         SMPEG* mpeg
3196         CODE:
3197                 RETVAL = (SMPEG_Info *) safemalloc (sizeof(SMPEG_Info));
3198                 SMPEG_getinfo(mpeg,RETVAL);
3199         OUTPUT:
3200                 RETVAL
3201         
3202
3203 #endif
3204
3205 #ifdef HAVE_SDL_GFX
3206
3207 =cut
3208
3209 SDL_Surface *
3210 GFXRotoZoom ( src, angle, zoom, smooth)
3211         SDL_Surface * src
3212         double angle
3213         double zoom
3214         int smooth
3215         CODE:
3216                 RETVAL = rotozoomSurface( src, angle, zoom, smooth);
3217         OUTPUT:
3218                 RETVAL
3219
3220 SDL_Surface *
3221 GFXZoom ( src, zoomx, zoomy, smooth)
3222         SDL_Surface *src
3223         double zoomx
3224         double zoomy
3225         int smooth
3226         CODE:
3227                 RETVAL = zoomSurface( src, zoomx, zoomy, smooth);
3228         OUTPUT:
3229                 RETVAL
3230
3231 =cut
3232
3233 int
3234 GFXPixelColor ( dst, x, y, color )
3235         SDL_Surface* dst
3236         Sint16 x
3237         Sint16 y
3238         Uint32 color
3239         CODE:
3240                 RETVAL = pixelColor( dst, x, y, color);
3241         OUTPUT:
3242                 RETVAL
3243
3244 int
3245 GFXPixelRGBA ( dst, x, y, r, g, b, a )
3246         SDL_Surface* dst
3247         Sint16 x
3248         Sint16 y
3249         Uint8 r
3250         Uint8 g
3251         Uint8 b
3252         Uint8 a
3253         CODE:
3254                 RETVAL = pixelRGBA( dst, x, y, r, g, b, a );
3255         OUTPUT:
3256                 RETVAL
3257
3258 int
3259 GFXHlineColor ( dst, x1, x2, y, color )
3260         SDL_Surface* dst
3261         Sint16 x1
3262         Sint16 x2
3263         Sint16 y
3264         Uint32 color
3265         CODE:
3266                 RETVAL = hlineColor( dst, x1, x2, y, color );
3267         OUTPUT:
3268                 RETVAL
3269
3270 int
3271 GFXHlineRGBA ( dst, x1, x2, y, r, g, b, a )
3272         SDL_Surface* dst
3273         Sint16 x1
3274         Sint16 x2
3275         Sint16 y
3276         Uint8 r
3277         Uint8 g
3278         Uint8 b
3279         Uint8 a
3280         CODE:
3281                 RETVAL = hlineRGBA( dst, x1, x2, y, r, g, b, a );
3282         OUTPUT:
3283                 RETVAL
3284
3285 int
3286 GFXVlineColor ( dst, x, y1, y2, color )
3287         SDL_Surface* dst
3288         Sint16 x
3289         Sint16 y1
3290         Sint16 y2
3291         Uint32 color
3292         CODE:
3293                 RETVAL = vlineColor( dst, x, y1, y2, color );
3294         OUTPUT:
3295                 RETVAL
3296
3297 int
3298 GFXVlineRGBA ( dst, x, y1, y2, r, g, b, a )
3299         SDL_Surface* dst
3300         Sint16 x
3301         Sint16 y1
3302         Sint16 y2
3303         Uint8 r
3304         Uint8 g
3305         Uint8 b
3306         Uint8 a
3307         CODE:
3308                 RETVAL = vlineRGBA( dst, x, y1, y2, r, g, b, a );
3309         OUTPUT:
3310                 RETVAL
3311
3312 int
3313 GFXRectangleColor ( dst, x1, y1, x2, y2, color )
3314         SDL_Surface* dst
3315         Sint16 x1
3316         Sint16 y1
3317         Sint16 x2
3318         Sint16 y2
3319         Uint32 color
3320         CODE:
3321                 RETVAL = rectangleColor( dst, x1, y1, x2, y2, color );
3322         OUTPUT:
3323                 RETVAL
3324
3325 int
3326 GFXRectangleRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3327         SDL_Surface* dst
3328         Sint16 x1
3329         Sint16 y1
3330         Sint16 x2
3331         Sint16 y2
3332         Uint8 r
3333         Uint8 g
3334         Uint8 b
3335         Uint8 a
3336         CODE:
3337                 RETVAL = rectangleRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3338         OUTPUT:
3339                 RETVAL
3340
3341 int
3342 GFXBoxColor ( dst, x1, y1, x2, y2, color )
3343         SDL_Surface* dst
3344         Sint16 x1
3345         Sint16 y1
3346         Sint16 x2
3347         Sint16 y2
3348         Uint32 color
3349         CODE:
3350                 RETVAL = boxColor( dst, x1, y1, x2, y2, color );
3351         OUTPUT:
3352                 RETVAL
3353
3354 int
3355 GFXBoxRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3356         SDL_Surface* dst;
3357         Sint16 x1
3358         Sint16 y1
3359         Sint16 x2
3360         Sint16 y2
3361         Uint8 r
3362         Uint8 g
3363         Uint8 b
3364         Uint8 a
3365         CODE:
3366                 RETVAL = boxRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3367         OUTPUT:
3368                 RETVAL
3369
3370 int
3371 GFXLineColor ( dst, x1, y1, x2, y2, color )
3372         SDL_Surface* dst
3373         Sint16 x1
3374         Sint16 y1
3375         Sint16 x2
3376         Sint16 y2
3377         Uint32 color
3378         CODE:
3379                 RETVAL = lineColor( dst, x1, y1, x2, y2, color );
3380         OUTPUT:
3381                 RETVAL
3382
3383 int
3384 GFXLineRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3385         SDL_Surface* dst
3386         Sint16 x1
3387         Sint16 y1
3388         Sint16 x2
3389         Sint16 y2
3390         Uint8 r
3391         Uint8 g
3392         Uint8 b
3393         Uint8 a
3394         CODE:
3395                 RETVAL = lineRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3396         OUTPUT:
3397                 RETVAL
3398
3399 int
3400 GFXAalineColor ( dst, x1, y1, x2, y2, color )
3401         SDL_Surface* dst
3402         Sint16 x1
3403         Sint16 y1
3404         Sint16 x2
3405         Sint16 y2
3406         Uint32 color
3407         CODE:
3408                 RETVAL = aalineColor( dst, x1, y1, x2, y2, color );
3409         OUTPUT:
3410                 RETVAL
3411
3412 int
3413 GFXAalineRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3414         SDL_Surface* dst
3415         Sint16 x1
3416         Sint16 y1
3417         Sint16 x2
3418         Sint16 y2
3419         Uint8 r
3420         Uint8 g
3421         Uint8 b
3422         Uint8 a
3423         CODE:
3424                 RETVAL = aalineRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3425         OUTPUT:
3426                 RETVAL
3427
3428 int
3429 GFXCircleColor ( dst, x, y, r, color )
3430         SDL_Surface* dst
3431         Sint16 x
3432         Sint16 y
3433         Sint16 r
3434         Uint32 color
3435         CODE:
3436                 RETVAL = circleColor( dst, x, y, r, color );
3437         OUTPUT:
3438                 RETVAL
3439
3440 int
3441 GFXCircleRGBA ( dst, x, y, rad, r, g, b, a )
3442         SDL_Surface* dst
3443         Sint16 x
3444         Sint16 y
3445         Sint16 rad
3446         Uint8 r
3447         Uint8 g
3448         Uint8 b
3449         Uint8 a
3450         CODE:
3451                 RETVAL = circleRGBA( dst, x, y, rad, r, g, b, a );
3452         OUTPUT:
3453                 RETVAL
3454
3455 int
3456 GFXAacircleColor ( dst, x, y, r, color )
3457         SDL_Surface* dst
3458         Sint16 x
3459         Sint16 y
3460         Sint16 r
3461         Uint32 color
3462         CODE:
3463                 RETVAL = aacircleColor( dst, x, y, r, color );
3464         OUTPUT:
3465                 RETVAL
3466
3467 int
3468 GFXAacircleRGBA ( dst, x, y, rad, r, g, b, a )
3469         SDL_Surface* dst
3470         Sint16 x
3471         Sint16 y
3472         Sint16 rad
3473         Uint8 r
3474         Uint8 g
3475         Uint8 b
3476         Uint8 a
3477         CODE:
3478                 RETVAL = aacircleRGBA( dst, x, y, rad, r, g, b, a );
3479         OUTPUT:
3480                 RETVAL
3481
3482 int
3483 GFXFilledCircleColor ( dst, x, y, r, color )
3484         SDL_Surface* dst
3485         Sint16 x
3486         Sint16 y
3487         Sint16 r
3488         Uint32 color
3489         CODE:
3490                 RETVAL = filledCircleColor( dst, x, y, r, color );
3491         OUTPUT:
3492                 RETVAL
3493
3494 int
3495 GFXFilledCircleRGBA ( dst, x, y, rad, r, g, b, a )
3496         SDL_Surface* dst
3497         Sint16 x
3498         Sint16 y
3499         Sint16 rad
3500         Uint8 r
3501         Uint8 g
3502         Uint8 b
3503         Uint8 a
3504         CODE:
3505                 RETVAL = filledCircleRGBA( dst, x, y, rad, r, g, b, a );
3506         OUTPUT:
3507                 RETVAL
3508
3509 int
3510 GFXEllipseColor ( dst, x, y, rx, ry, color )
3511         SDL_Surface* dst
3512         Sint16 x
3513         Sint16 y
3514         Sint16 rx
3515         Sint16 ry
3516         Uint32 color
3517         CODE:
3518                 RETVAL = ellipseColor( dst, x, y, rx, ry, color );
3519         OUTPUT:
3520                 RETVAL
3521
3522 int
3523 GFXEllipseRGBA ( dst, x, y, rx, ry, r, g, b, a )
3524         SDL_Surface* dst
3525         Sint16 x
3526         Sint16 y
3527         Sint16  rx
3528         Sint16 ry
3529         Uint8 r
3530         Uint8 g
3531         Uint8 b
3532         Uint8 a
3533         CODE:
3534                 RETVAL = ellipseRGBA( dst, x, y, rx, ry, r, g, b, a );
3535         OUTPUT:
3536                 RETVAL
3537
3538 int
3539 GFXAaellipseColor ( dst, xc, yc, rx, ry, color )
3540         SDL_Surface* dst
3541         Sint16 xc
3542         Sint16 yc
3543         Sint16 rx
3544         Sint16 ry
3545         Uint32 color
3546         CODE:
3547                 RETVAL = aaellipseColor( dst, xc, yc, rx, ry, color );
3548         OUTPUT:
3549                 RETVAL
3550
3551 int
3552 GFXAaellipseRGBA ( dst, x, y, rx, ry, r, g, b, a )
3553         SDL_Surface* dst
3554         Sint16 x
3555         Sint16 y
3556         Sint16 rx
3557         Sint16 ry
3558         Uint8 r
3559         Uint8 g
3560         Uint8 b
3561         Uint8 a
3562         CODE:
3563                 RETVAL = aaellipseRGBA( dst, x, y, rx, ry, r, g, b, a );
3564         OUTPUT:
3565                 RETVAL
3566
3567 int
3568 GFXFilledEllipseColor ( dst, x, y, rx, ry, color )
3569         SDL_Surface* dst
3570         Sint16 x
3571         Sint16 y
3572         Sint16 rx
3573         Sint16 ry
3574         Uint32 color
3575         CODE:
3576                 RETVAL = filledEllipseColor( dst, x, y, rx, ry, color );
3577         OUTPUT:
3578                 RETVAL
3579
3580 int
3581 GFXFilledEllipseRGBA ( dst, x, y, rx, ry, r, g, b, a )
3582         SDL_Surface* dst
3583         Sint16 x
3584         Sint16 y
3585         Sint16 rx
3586         Sint16 ry
3587         Uint8 r
3588         Uint8 g
3589         Uint8 b
3590         Uint8 a
3591         CODE:
3592                 RETVAL = filledEllipseRGBA( dst, x, y, rx, ry, r, g, b, a );
3593         OUTPUT:
3594                 RETVAL
3595
3596 int
3597 GFXFilledPieColor ( dst, x, y, rad, start, end, color )
3598         SDL_Surface* dst
3599         Sint16 x
3600         Sint16 y
3601         Sint16 rad
3602         Sint16 start
3603         Sint16 end
3604         Uint32 color
3605         CODE:
3606                 RETVAL = filledPieColor( dst, x, y, rad, start, end, color );
3607         OUTPUT:
3608                 RETVAL
3609
3610 int
3611 GFXFilledPieRGBA ( dst, x, y, rad, start, end, r, g, b, a )
3612         SDL_Surface* dst
3613         Sint16 x
3614         Sint16 y
3615         Sint16 rad
3616         Sint16 start
3617         Sint16 end
3618         Uint8 r
3619         Uint8 g
3620         Uint8 b
3621         Uint8 a
3622         CODE:
3623                 RETVAL = filledPieRGBA( dst, x, y, rad, start, end, r, g, b, a );
3624         OUTPUT:
3625                 RETVAL
3626
3627 int
3628 GFXPolygonColor ( dst, vx, vy, n, color )
3629         SDL_Surface* dst
3630         Sint16* vx
3631         Sint16* vy
3632         int n
3633         Uint32 color;
3634         CODE:
3635                 RETVAL = polygonColor( dst, vx, vy, n, color );
3636         OUTPUT:
3637                 RETVAL
3638
3639 int
3640 GFXPolygonRGBA ( dst, vx, vy, n, r, g, b, a )
3641         SDL_Surface* dst
3642         Sint16* vx
3643         Sint16* vy
3644         int n
3645         Uint8 r
3646         Uint8 g
3647         Uint8 b
3648         Uint8 a
3649         CODE:
3650                 RETVAL = polygonRGBA( dst, vx, vy, n, r, g, b, a );
3651         OUTPUT:
3652                 RETVAL
3653
3654 int
3655 GFXAapolygonColor ( dst, vx, vy, n, color )
3656         SDL_Surface* dst
3657         Sint16* vx
3658         Sint16* vy
3659         int n
3660         Uint32 color
3661         CODE:
3662                 RETVAL = aapolygonColor( dst, vx, vy, n, color );
3663         OUTPUT:
3664                 RETVAL
3665
3666 int
3667 GFXAapolygonRGBA ( dst, vx, vy, n, r, g, b, a )
3668         SDL_Surface* dst
3669         Sint16* vx
3670         Sint16* vy
3671         int n
3672         Uint8 r
3673         Uint8 g
3674         Uint8 b
3675         Uint8 a
3676         CODE:
3677                 RETVAL = aapolygonRGBA( dst, vx, vy, n, r, g, b, a );
3678         OUTPUT:
3679                 RETVAL
3680
3681 int
3682 GFXFilledPolygonColor ( dst, vx, vy, n, color )
3683         SDL_Surface* dst
3684         Sint16* vx
3685         Sint16* vy
3686         int n
3687         int color
3688         CODE:
3689                 RETVAL = filledPolygonColor( dst, vx, vy, n, color );
3690         OUTPUT:
3691                 RETVAL
3692
3693 int
3694 GFXFilledPolygonRGBA ( dst, vx, vy, n, r, g, b, a )
3695         SDL_Surface* dst
3696         Sint16* vx
3697         Sint16* vy
3698         int n
3699         Uint8 r
3700         Uint8 g
3701         Uint8 b
3702         Uint8 a
3703         CODE:
3704                 RETVAL = filledPolygonRGBA( dst, vx, vy, n, r, g, b, a );
3705         OUTPUT:
3706                 RETVAL
3707
3708 int
3709 GFXCharacterColor ( dst, x, y, c, color )
3710         SDL_Surface* dst
3711         Sint16 x
3712         Sint16 y
3713         char c
3714         Uint32 color
3715         CODE:
3716                 RETVAL = characterColor( dst, x, y, c, color );
3717         OUTPUT:
3718                 RETVAL
3719
3720 int
3721 GFXCharacterRGBA ( dst, x, y, c, r, g, b, a )
3722         SDL_Surface* dst
3723         Sint16 x
3724         Sint16 y
3725         char c
3726         Uint8 r
3727         Uint8 g
3728         Uint8 b
3729         Uint8 a
3730         CODE:
3731                 RETVAL = characterRGBA( dst, x, y, c, r, g, b, a );
3732         OUTPUT:
3733                 RETVAL
3734
3735 int
3736 GFXStringColor ( dst, x, y, c, color )
3737         SDL_Surface* dst
3738         Sint16 x
3739         Sint16 y
3740         char* c
3741         Uint32 color
3742         CODE:
3743                 RETVAL = stringColor( dst, x, y, c, color );
3744         OUTPUT:
3745                 RETVAL
3746
3747 int
3748 GFXStringRGBA ( dst, x, y, c, r, g, b, a )
3749         SDL_Surface* dst
3750         Sint16 x
3751         Sint16 y
3752         char* c
3753         Uint8 r
3754         Uint8 g
3755         Uint8 b
3756         Uint8 a
3757         CODE:
3758                 RETVAL = stringRGBA( dst, x, y, c, r, g, b, a );
3759         OUTPUT:
3760                 RETVAL
3761
3762 #endif
3763
3764
3765 #ifdef HAVE_SDL_SVG
3766
3767 SDL_svg_context *
3768 SVG_Load ( filename )
3769         char* filename
3770         CODE:
3771                 RETVAL = SVG_Load(filename);
3772         OUTPUT:
3773                 RETVAL
3774
3775 SDL_svg_context *
3776 SVG_LoadBuffer ( data, len )
3777         char* data
3778         int len
3779         CODE:
3780                 RETVAL = SVG_LoadBuffer(data,len);
3781         OUTPUT:
3782                 RETVAL
3783
3784 int
3785 SVG_SetOffset ( source, xoff, yoff )
3786         SDL_svg_context* source
3787         double xoff
3788         double yoff
3789         CODE:
3790                 RETVAL = SVG_SetOffset(source,xoff,yoff);
3791         OUTPUT:
3792                 RETVAL
3793
3794 int
3795 SVG_SetScale ( source, xscale, yscale )
3796         SDL_svg_context* source
3797         double xscale
3798         double yscale
3799         CODE:
3800                 RETVAL = SVG_SetScale(source,xscale,yscale);
3801         OUTPUT:
3802                 RETVAL
3803
3804 int
3805 SVG_RenderToSurface ( source, x, y, dest )
3806         SDL_svg_context* source
3807         int x
3808         int y
3809         SDL_Surface* dest;
3810         CODE:
3811                 RETVAL = SVG_RenderToSurface(source,x,y,dest);
3812         OUTPUT:
3813                 RETVAL
3814
3815 void
3816 SVG_Free ( source )
3817         SDL_svg_context* source
3818         CODE:
3819                 SVG_Free(source);       
3820
3821 void
3822 SVG_Set_Flags ( source, flags )
3823         SDL_svg_context* source
3824         Uint32 flags
3825         CODE:
3826                 SVG_Set_Flags(source,flags);
3827
3828 float
3829 SVG_Width ( source )
3830         SDL_svg_context* source
3831         CODE:
3832                 RETVAL = SVG_Width(source);
3833         OUTPUT:
3834                 RETVAL
3835
3836 float
3837 SVG_HEIGHT ( source )
3838         SDL_svg_context* source
3839         CODE:
3840                 RETVAL = SVG_Height(source);
3841         OUTPUT:
3842                 RETVAL
3843
3844 void
3845 SVG_SetClipping ( source, minx, miny, maxx, maxy )
3846         SDL_svg_context* source
3847         int minx
3848         int miny
3849         int maxx
3850         int maxy
3851         CODE:
3852                 SVG_SetClipping(source,minx,miny,maxx,maxy);
3853
3854 int
3855 SVG_Version ( )
3856         CODE:
3857                 RETVAL = SVG_Version();
3858         OUTPUT:
3859                 RETVAL
3860
3861
3862 #endif
3863
3864 #ifdef HAVE_SDL_SOUND
3865
3866 Uint16
3867 SoundAudioInfoFormat ( audioinfo )
3868         Sound_AudioInfo* audioinfo
3869         CODE:
3870                 RETVAL = audioinfo->format;
3871         OUTPUT:
3872                 RETVAL
3873
3874 Uint8
3875 SoundAudioInfoChannels ( audioinfo )
3876         Sound_AudioInfo* audioinfo
3877         CODE:
3878                 RETVAL = audioinfo->channels;
3879         OUTPUT:
3880                 RETVAL
3881
3882 Uint32
3883 SoundAudioInforate ( audioinfo )
3884         Sound_AudioInfo* audioinfo
3885         CODE:
3886                 RETVAL = audioinfo->rate;
3887         OUTPUT:
3888                 RETVAL
3889
3890 AV*
3891 SoundDecoderInfoExtensions ( decoderinfo )
3892         Sound_DecoderInfo* decoderinfo
3893         CODE:
3894                 const char **ext;
3895                 for ( ext = decoderinfo->extensions; *ext != NULL; ext++ ){
3896                         av_push(RETVAL,newSVpv(*ext,0));
3897                 }
3898         OUTPUT:
3899                 RETVAL
3900
3901 const char*
3902 SoundDecoderInfoDescription ( decoderinfo )
3903         Sound_DecoderInfo* decoderinfo
3904         CODE:
3905                 RETVAL = decoderinfo->description;
3906         OUTPUT:
3907                 RETVAL
3908
3909 const char*
3910 SoundDecoderInfoAuthor ( decoderinfo )
3911         Sound_DecoderInfo* decoderinfo
3912         CODE:
3913                 RETVAL = decoderinfo->author;
3914         OUTPUT:
3915                 RETVAL
3916
3917 const char*
3918 SoundDecoderInfoUrl ( decoderinfo )
3919         Sound_DecoderInfo* decoderinfo
3920         CODE:
3921                 RETVAL = decoderinfo->url;
3922         OUTPUT:
3923                 RETVAL
3924
3925 const Sound_DecoderInfo*
3926 SoundSampleDecoder ( sample ) 
3927         Sound_Sample* sample
3928         CODE:
3929                 RETVAL = sample->decoder;
3930         OUTPUT:
3931                 RETVAL
3932
3933 Sound_AudioInfo* 
3934 SoundSampleDesired ( sample )
3935         Sound_Sample* sample
3936         CODE:
3937                 RETVAL = &sample->desired;
3938         OUTPUT:
3939                 RETVAL
3940
3941 Sound_AudioInfo*
3942 SoundSampleAcutal ( sample )
3943         Sound_Sample* sample
3944         CODE:
3945                 RETVAL = &sample->actual;
3946         OUTPUT:
3947                 RETVAL
3948
3949 char*
3950 SoundSampleBuffer ( sample )
3951         Sound_Sample* sample
3952         CODE:
3953                 RETVAL = sample->buffer;
3954         OUTPUT:
3955                 RETVAL
3956
3957 Uint32
3958 SoundSampleBufferSize ( sample )
3959         Sound_Sample* sample
3960         CODE:
3961                 RETVAL = sample->buffer_size;
3962         OUTPUT:
3963                 RETVAL
3964
3965 Uint32
3966 SoundSampleFlags ( sample )
3967         Sound_Sample* sample
3968         CODE:
3969                 RETVAL = (Uint32)sample->flags;
3970         OUTPUT:
3971                 RETVAL
3972
3973 int
3974 Sound_Init ( )
3975         CODE:
3976                 RETVAL = Sound_Init();
3977         OUTPUT:
3978                 RETVAL
3979
3980 int
3981 Sound_Quit ( )
3982         CODE:
3983                 RETVAL = Sound_Quit();
3984         OUTPUT:
3985                 RETVAL
3986
3987 AV*
3988 Sound_AvailableDecoders ( )
3989         CODE:
3990                 RETVAL = newAV();
3991                 const Sound_DecoderInfo** sdi;
3992                 sdi = Sound_AvailableDecoders();
3993                 if (sdi != NULL)  {
3994                         for (;*sdi != NULL; ++sdi) {
3995                                 av_push(RETVAL,sv_2mortal(newSViv(PTR2IV(*sdi))));
3996                         }
3997                 }
3998         OUTPUT:
3999                 RETVAL
4000
4001 const char*
4002 Sound_GetError ( )
4003         CODE:
4004                 RETVAL = Sound_GetError();
4005         OUTPUT:
4006                 RETVAL
4007
4008 void
4009 Sound_ClearError ( )
4010         CODE:
4011                 Sound_ClearError();
4012
4013 Sound_Sample*
4014 Sound_NewSample ( rw, ext, desired, buffsize )
4015         SDL_RWops* rw
4016         const char* ext
4017         Sound_AudioInfo* desired
4018         Uint32 buffsize
4019         CODE:
4020                 RETVAL = Sound_NewSample(rw,ext,desired,buffsize);
4021         OUTPUT:
4022                 RETVAL
4023
4024 Sound_Sample*
4025 Sound_NewSampleFromMem ( data, size, ext, desired, buffsize )
4026         const Uint8 *data
4027         Uint32 size
4028         const char* ext
4029         Sound_AudioInfo* desired
4030         Uint32 buffsize
4031         CODE:
4032                 RETVAL = Sound_NewSampleFromMem(data,size,ext,desired,buffsize);
4033         OUTPUT:
4034                 RETVAL
4035
4036 Sound_Sample*
4037 Sound_NewSampleFromFile ( fname, desired, buffsize )
4038         const char* fname
4039         Sound_AudioInfo* desired
4040         Uint32 buffsize
4041         CODE:
4042                 RETVAL = Sound_NewSampleFromFile(fname,desired,buffsize);
4043         OUTPUT:
4044                 RETVAL
4045
4046 void
4047 Sound_FreeSample ( sample )
4048         Sound_Sample* sample
4049         CODE:
4050                 Sound_FreeSample(sample);
4051
4052 Sint32
4053 Sound_GetDuration ( sample )
4054         Sound_Sample* sample
4055         CODE:
4056                 RETVAL = Sound_GetDuration(sample);
4057         OUTPUT:
4058                 RETVAL
4059
4060 int
4061 Sound_SetBufferSize ( sample, size )
4062         Sound_Sample* sample
4063         Uint32 size
4064         CODE:
4065                 RETVAL = Sound_SetBufferSize(sample,size);
4066         OUTPUT:
4067                 RETVAL
4068
4069 Uint32
4070 Sound_Decode ( sample )
4071         Sound_Sample* sample
4072         CODE:
4073                 RETVAL = Sound_Decode(sample);
4074         OUTPUT:
4075                 RETVAL
4076
4077 Uint32
4078 Sound_DecodeAll ( sample ) 
4079         Sound_Sample* sample
4080         CODE:
4081                 RETVAL = Sound_DecodeAll(sample);
4082         OUTPUT:
4083                 RETVAL
4084
4085 int
4086 Sound_Rewind ( sample )
4087         Sound_Sample* sample
4088         CODE:
4089                 RETVAL = Sound_Rewind(sample);
4090         OUTPUT:
4091                 RETVAL
4092
4093 int
4094 Sound_Seek ( sample, ms )
4095         Sound_Sample* sample
4096         Uint32 ms
4097         CODE:
4098                 RETVAL = Sound_Seek(sample,ms);
4099         OUTPUT:
4100                 RETVAL
4101
4102 #endif
4103
4104 #ifdef HAVE_SDL_TTF
4105
4106 int
4107 TTF_Init ()
4108         CODE:
4109                 RETVAL = TTF_Init();
4110         OUTPUT:
4111                 RETVAL
4112
4113 void
4114 TTF_Quit ()
4115         CODE:
4116                 TTF_Quit();
4117
4118 TTF_Font*
4119 TTF_OpenFont ( file, ptsize )
4120         char *file
4121         int ptsize
4122         CODE:
4123                 char* CLASS = "SDL::TTF_Font";
4124                 RETVAL = TTF_OpenFont(file,ptsize);
4125         OUTPUT:
4126                 RETVAL
4127
4128 AV*
4129 TTF_SizeText ( font, text )
4130         TTF_Font *font
4131         char *text
4132         CODE:
4133                 int w,h;
4134                 RETVAL = newAV();
4135                 if(TTF_SizeText(font,text,&w,&h))
4136                 {
4137                         printf("TTF error at TTFSizeText: %s \n", TTF_GetError());
4138                         Perl_croak (aTHX_ "TTF error \n");
4139                 }
4140                 else
4141                 {
4142                         av_push(RETVAL,newSViv(w));
4143                         av_push(RETVAL,newSViv(h));
4144                         sv_2mortal((SV*)RETVAL);
4145                 }
4146         OUTPUT:
4147                 RETVAL
4148
4149 SDL_Surface*
4150 TTF_RenderText_Blended ( font, text, fg )
4151         TTF_Font *font
4152         char *text
4153         SDL_Color *fg
4154         CODE:
4155                 char* CLASS = "SDL::Surface";
4156                 RETVAL = TTF_RenderText_Blended(font,text,*fg);
4157         OUTPUT:
4158                 RETVAL
4159
4160 #endif
4161
4162 MODULE = SDL            PACKAGE = SDL
4163 PROTOTYPES : DISABLE
4164
4165