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