1 ;;; Gacela, a GNU Common Lisp extension for fast games development
2 ;;; Copyright (C) 2009 by Javier Sancho Fernandez <jsf at jsancho dot org>
4 ;;; This program is free software: you can redistribute it and/or modify
5 ;;; it under the terms of the GNU General Public License as published by
6 ;;; the Free Software Foundation, either version 3 of the License, or
7 ;;; (at your option) any later version.
9 ;;; This program is distributed in the hope that it will be useful,
10 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ;;; GNU General Public License for more details.
14 ;;; You should have received a copy of the GNU General Public License
15 ;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
20 (clines "#include <SDL/SDL.h>")
21 (clines "#include <SDL/SDL_image.h>")
22 (clines "#include <SDL/SDL_ttf.h>")
23 (clines "#include <SDL/SDL_mixer.h>")
24 (clines "#include <SDL/SDL_rotozoom.h>")
26 ;;; SDL constants as functions
27 (mapcconst int "int" "SDL_INIT_TIMER")
28 (mapcconst int "int" "SDL_INIT_AUDIO")
29 (mapcconst int "int" "SDL_INIT_VIDEO")
30 (mapcconst int "int" "SDL_INIT_CDROM")
31 (mapcconst int "int" "SDL_INIT_JOYSTICK")
32 (mapcconst int "int" "SDL_INIT_NOPARACHUTE")
33 (mapcconst int "int" "SDL_INIT_EVENTTHREAD")
34 (mapcconst int "int" "SDL_INIT_EVERYTHING")
36 (mapcconst int "int" "SDL_SWSURFACE")
37 (mapcconst int "int" "SDL_HWSURFACE")
38 (mapcconst int "int" "SDL_ASYNCBLIT")
40 (mapcconst int "int" "SDL_ANYFORMAT")
41 (mapcconst int "int" "SDL_HWPALETTE")
42 (mapcconst int "int" "SDL_DOUBLEBUF")
43 (mapcconst int "int" "SDL_FULLSCREEN")
44 (mapcconst int "int" "SDL_OPENGL")
45 (mapcconst int "int" "SDL_OPENGLBLIT")
46 (mapcconst int "int" "SDL_RESIZABLE")
47 (mapcconst int "int" "SDL_NOFRAME")
49 (mapcconst int "int" "SDL_HWACCEL")
50 (mapcconst int "int" "SDL_SRCCOLORKEY")
52 (mapcconst int "int" "SDL_GL_DOUBLEBUFFER")
54 (mapcconst int "int" "SDL_DEFAULT_REPEAT_DELAY")
55 (mapcconst int "int" "SDL_DEFAULT_REPEAT_INTERVAL")
57 (mapcconst int "int" "SDL_LIL_ENDIAN")
58 (mapcconst int "int" "SDL_BIG_ENDIAN")
61 (defcfun "int gacela_SDL_Init (int flags)" 0
62 "return SDL_Init (flags);")
64 (defcfun "void gacela_SDL_Quit (void)" 0
67 (defcfun "int gacela_SDL_SetVideoMode (int width, int height, int bpp, int flags)" 0
68 "return SDL_SetVideoMode (width, height, bpp, flags);")
70 (defcfun "void gacela_SDL_WM_SetCaption (char *title, char *icon)" 0
71 "SDL_WM_SetCaption (title, icon);")
73 (defcfun "int gacela_SDL_Flip (int screen)" 0
74 "return SDL_Flip (screen);")
76 (defcfun "void gacela_SDL_FreeSurface (int surface)" 0
77 "SDL_FreeSurface (surface);")
79 (defcfun "void gacela_SDL_Delay (int ms)" 0
82 (defcfun "int gacela_SDL_GetTicks (void)" 0
83 "return SDL_GetTicks ();")
85 (defcfun "int gacela_SDL_DisplayFormat (int surface)" 0
86 "return SDL_DisplayFormat (surface);")
88 (defcfun "int gacela_SDL_MapRGB (int format, int r, int g, int b)" 0
89 "return SDL_MapRGB (format, r, g, b);")
91 (defcfun "int gacela_SDL_SetColorKey (int surface, int flag, int key)" 0
92 "return SDL_SetColorKey (surface, flag, key);")
94 (defcfun "int gacela_SDL_LoadBMP (char *file)" 0
95 "return SDL_LoadBMP (file);")
97 (defcfun "int gacela_IMG_Load (char *filename)" 0
98 "return IMG_Load (filename);")
100 (defcfun "static object gacela_SDL_GetVideoInfo (void)" 0
101 "const SDL_VideoInfo *info;"
103 "info = SDL_GetVideoInfo ();"
105 ((cons (int info->blit_hw) vi) vi) (':blit_hw label) ((cons label vi) vi)
106 ((cons (int info->hw_available) vi) vi) (':hw_available label) ((cons label vi) vi)
109 (defcfun "int gacela_SDL_GL_SetAttribute (int attr, int value)" 0
110 "return SDL_GL_SetAttribute (attr, value);")
112 (defcfun "static object gacela_SDL_PollEvent (void)" 0
113 "SDL_Event sdl_event;"
114 "object event, label;"
116 "if (SDL_PollEvent (&sdl_event)) {"
117 " switch (sdl_event.type) {"
120 ((cons (int sdl_event.key.keysym.sym) event) event) (':key.keysym.sym label) ((cons label event) event)
123 ((cons (int sdl_event.type) event) event) (':type label) ((cons label event) event)
127 (defcfun "void gacela_SDL_GL_SwapBuffers (void)" 0
128 "SDL_GL_SwapBuffers ();")
130 (defcfun "int gacela_SDL_EnableKeyRepeat (int delay, int interval)" 0
131 "return SDL_EnableKeyRepeat (delay, interval);")
133 (defcfun "int gacela_zoomSurface (int src, float zoomx, float zoomy, int smooth)" 0
134 "return zoomSurface (src, zoomx, zoomy, smooth);")
136 (defcfun "int gacela_SDL_ByteOrder (void)" 0
137 "return SDL_BYTEORDER;")
139 (defentry SDL_Init (int) (int "gacela_SDL_Init"))
140 (defentry SDL_Quit () (void "gacela_SDL_Quit"))
141 (defentry SDL_SetVideoMode (int int int int) (int "gacela_SDL_SetVideoMode"))
142 (defentry SDL_WM_SetCaption (string string) (void "gacela_SDL_WM_SetCaption"))
143 (defentry SDL_Flip (int) (int "gacela_SDL_Flip"))
144 (defentry SDL_FreeSurface (int) (void "gacela_SDL_FreeSurface"))
145 (defentry SDL_Delay (int) (void "gacela_SDL_Delay"))
146 (defentry SDL_GetTicks () (int "gacela_SDL_GetTicks"))
147 (defentry SDL_DisplayFormat (int) (int "gacela_SDL_DisplayFormat"))
148 ;(defentry SDL_SurfaceFormat (int) (int "gacela_SDL_SurfaceFormat"))
149 (defentry SDL_MapRGB (int int int int) (int "gacela_SDL_MapRGB"))
150 (defentry SDL_SetColorKey (int int int) (int "gacela_SDL_SetColorKey"))
151 ;(defentry SDL_BlitSurface (int int int int) (void "gacela_SDL_BlitSurface"))
152 ;(defentry SDL_Rect (int int int int) (int "gacela_SDL_Rect"))
153 (defentry SDL_LoadBMP (string) (int "gacela_SDL_LoadBMP"))
154 (defentry IMG_Load (string) (int "gacela_IMG_Load"))
155 (defentry SDL_GetVideoInfo () (object "gacela_SDL_GetVideoInfo"))
156 (defentry SDL_GL_SetAttribute (int int) (int "gacela_SDL_GL_SetAttribute"))
157 (defentry SDL_PollEvent () (object "gacela_SDL_PollEvent"))
158 ;(defentry TTF_Init () (int "gacela_TTF_Init"))
159 ;(defentry TTF_OpenFont (string int) (int "gacela_TTF_OpenFont"))
160 ;(defentry TTF_CloseFont (int) (void "gacela_TTF_CloseFont"))
161 ;(defentry TTF_Quit () (void "gacela_TTF_Quit"))
162 ;(defentry Mix_OpenAudio (int int int) (int "gacela_Mix_OpenAudio"))
163 ;(defentry Mix_LoadMUS (string) (int "gacela_Mix_LoadMUS"))
164 ;(defentry Mix_LoadWAV (string) (int "gacela_Mix_LoadWAV"))
165 ;(defentry Mix_PlayChannel (int int int) (int "gacela_Mix_PlayChannel"))
166 ;(defentry Mix_PlayMusic (int int) (int "gacela_Mix_PlayMusic"))
167 ;(defentry Mix_PlayingMusic () (int "gacela_Mix_PlayingMusic"))
168 ;(defentry Mix_PausedMusic () (int "gacela_Mix_PausedMusic"))
169 ;(defentry Mix_PauseMusic () (void "gacela_Mix_PauseMusic"))
170 ;(defentry Mix_ResumeMusic () (void "gacela_Mix_ResumeMusic"))
171 ;(defentry Mix_HaltMusic () (int "gacela_Mix_HaltMusic"))
172 ;(defentry Mix_FreeMusic (int) (void "gacela_Mix_FreeMusic"))
173 ;(defentry Mix_FreeChunk (int) (void "gacela_Mix_FreeChunk"))
174 ;(defentry Mix_CloseAudio () (void "gacela_Mix_CloseAudio"))
175 ;(defentry free (int) (void "gacela_free"))
176 (defentry SDL_GL_SwapBuffers () (void "gacela_SDL_GL_SwapBuffers"))
177 (defentry SDL_EnableKeyRepeat (int int) (int "gacela_SDL_EnableKeyRepeat"))
178 (defentry zoomSurface (int float float int) (int "gacela_zoomSurface"))
179 (defentry SDL_ByteOrder () (int "gacela_SDL_ByteOrder"))
181 ;;; C-Gacela Functions
182 (defcfun "int gacela_surface_format (int surface)" 0
183 "const SDL_Surface *s = surface;"
186 (defcfun "int gacela_surface_w (int surface)" 0
187 "const SDL_Surface *s = surface;"
190 (defcfun "int gacela_surface_h (int surface)" 0
191 "const SDL_Surface *s = surface;"
194 (defcfun "int gacela_surface_pixels (int surface)" 0
195 "const SDL_Surface *s = surface;"
198 (defcfun "int gacela_surface_format_BytesPerPixel (int surface)" 0
199 "const SDL_Surface *s = surface;"
200 "return s->format->BytesPerPixel;")
202 ;(defentry apply-surface2 (int int int int int int int int int) (void "apply_surface"))
203 ;(defentry render-text2 (int string int int int) (int "render_text"))
204 ;(defentry fill-surface (int int int int) (void "fill_surface"))
205 ;(defentry box-collision (int int int int int int) (int "box_collision"))
206 ;(defentry create-SDL_Surface (int int int int int int) (int "create_SDL_Surface"))
207 ;(defentry copy-SDL_Surface (int) (int "copy_SDL_Surface"))
208 (defentry surface-format (int) (int "gacela_surface_format"))
209 (defentry surface-w (int) (int "gacela_surface_w"))
210 (defentry surface-h (int) (int "gacela_surface_h"))
211 (defentry surface-pixels (int) (int "gacela_surface_pixels"))
212 (defentry surface-format-BytesPerPixel (int) (int "gacela_surface_format_BytesPerPixel"))