1 /* Gacela, a GNU Guile 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 #include <SDL/SDL_image.h>
21 #include <SDL/SDL_mixer.h>
22 #include "gacela_SDL.h"
25 gacela_SDL_Init (SCM flags)
27 return scm_from_int (SDL_Init (scm_to_int (flags)));
31 gacela_SDL_Quit (void)
34 return SCM_UNSPECIFIED;
38 gacela_SDL_SetVideoMode (SCM width, SCM height, SCM bpp, SCM flags)
40 return scm_from_int ((int)SDL_SetVideoMode (scm_to_int (width), scm_to_int (height), \
41 scm_to_int (bpp), scm_to_int (flags)));
45 gacela_SDL_WM_SetCaption (SCM title, SCM icon)
47 SDL_WM_SetCaption (scm_to_locale_string(title), scm_to_locale_string(icon));
48 return SCM_UNSPECIFIED;
52 gacela_SDL_Flip (SCM screen)
54 return scm_from_int (SDL_Flip ((SDL_Surface *)scm_to_int (screen)));
58 gacela_SDL_FreeSurface (SCM surface)
60 SDL_FreeSurface ((SDL_Surface *)scm_to_int (surface));
61 return SCM_UNSPECIFIED;
65 gacela_SDL_Delay (SCM ms)
67 SDL_Delay (scm_to_int (ms));
68 return SCM_UNSPECIFIED;
72 gacela_SDL_GetTicks (void)
74 return scm_from_int (SDL_GetTicks ());
78 gacela_SDL_DisplayFormat (SCM surface)
80 return scm_from_int ((int)SDL_DisplayFormat ((SDL_Surface *)scm_to_int (surface)));
84 gacela_SDL_MapRGB (SCM format, SCM r, SCM g, SCM b)
86 return scm_from_int (SDL_MapRGB ((SDL_PixelFormat *)scm_to_int (format), scm_to_int (r), scm_to_int (g), scm_to_int (b)));
90 gacela_SDL_SetColorKey (SCM surface, SCM flag, SCM key)
92 return scm_from_int (SDL_SetColorKey ((SDL_Surface *)scm_to_int (surface), scm_to_int (flag), scm_to_int (key)));
96 gacela_SDL_LoadBMP (SCM file)
98 return scm_from_int ((int)SDL_LoadBMP (scm_to_locale_string (file)));
102 gacela_IMG_Load (SCM filename)
104 return scm_from_int ((int)IMG_Load (scm_to_locale_string (filename)));
108 gacela_SDL_GetVideoInfo (void)
110 const SDL_VideoInfo *info;
113 info = SDL_GetVideoInfo ();
114 vi = scm_list_n (SCM_UNDEFINED);
116 vi = scm_cons (scm_cons (scm_from_locale_symbol ("blit_hw"), scm_from_int (info->blit_hw)), vi);
117 vi = scm_cons (scm_cons (scm_from_locale_symbol ("hw_available"), scm_from_int (info->hw_available)), vi);
123 gacela_SDL_GL_SetAttribute (SCM attr, SCM value)
125 return scm_from_int (SDL_GL_SetAttribute (scm_to_int (attr), scm_to_int (value)));
129 gacela_SDL_PollEvent (void)
134 event = scm_list_n (SCM_UNDEFINED);
136 if (SDL_PollEvent (&sdl_event)) {
137 switch (sdl_event.type) {
140 event = scm_cons (scm_cons (scm_from_locale_symbol ("key.keysym.sym"), scm_from_int (sdl_event.key.keysym.sym)), event);
143 event = scm_cons (scm_cons (scm_from_locale_symbol ("type"), scm_from_int (sdl_event.type)), event);
150 gacela_SDL_GL_SwapBuffers (void)
152 SDL_GL_SwapBuffers ();
153 return SCM_UNSPECIFIED;
157 gacela_SDL_EnableKeyRepeat (SCM delay, SCM interval)
159 return scm_from_int (SDL_EnableKeyRepeat (scm_to_int (delay), scm_to_int (interval)));
163 gacela_Mix_OpenAudio (SCM frequency, SCM format, SCM channels, SCM chunksize)
165 return scm_from_int (Mix_OpenAudio (scm_to_int (frequency), scm_to_int (format), scm_to_int (channels), scm_to_int (chunksize)));
169 gacela_Mix_LoadMUS (SCM file)
171 return scm_from_int ((int)Mix_LoadMUS (scm_to_locale_string (file)));
175 gacela_Mix_LoadWAV (SCM file)
177 return scm_from_int ((int)Mix_LoadWAV (scm_to_locale_string (file)));
181 gacela_Mix_PlayChannel (SCM channel, SCM chunk, SCM loops)
183 return scm_from_int (Mix_PlayChannel (scm_to_int (channel), (Mix_Chunk *)scm_to_int (chunk), scm_to_int (loops)));
187 gacela_Mix_PlayMusic (SCM music, SCM loops)
189 return scm_from_int (Mix_PlayMusic ((Mix_Music *)scm_to_int (music), scm_to_int (loops)));
193 gacela_Mix_PlayingMusic (void)
195 return scm_from_int (Mix_PlayingMusic ());
199 gacela_Mix_PausedMusic (void)
201 return scm_from_int (Mix_PausedMusic ());
205 gacela_Mix_PauseMusic (void)
208 return SCM_UNSPECIFIED;
212 gacela_Mix_ResumeMusic (void)
215 return SCM_UNSPECIFIED;
219 gacela_Mix_HaltMusic (void)
221 return scm_from_int (Mix_HaltMusic ());
225 gacela_Mix_FreeMusic (SCM music)
227 Mix_FreeMusic ((Mix_Music *)scm_to_int (music));
228 return SCM_UNSPECIFIED;
232 gacela_Mix_FreeChunk (SCM chunk)
234 Mix_FreeChunk ((Mix_Chunk *)scm_to_int (chunk));
235 return SCM_UNSPECIFIED;
239 gacela_Mix_CloseAudio (void)
242 return SCM_UNSPECIFIED;
247 SDL_register_functions (void* data)
249 scm_c_define ("SDL_INIT_TIMER", scm_from_int (SDL_INIT_TIMER));
250 scm_c_define ("SDL_INIT_AUDIO", scm_from_int (SDL_INIT_AUDIO));
251 scm_c_define ("SDL_INIT_VIDEO", scm_from_int (SDL_INIT_VIDEO));
252 scm_c_define ("SDL_INIT_CDROM", scm_from_int (SDL_INIT_CDROM));
253 scm_c_define ("SDL_INIT_JOYSTICK", scm_from_int (SDL_INIT_JOYSTICK));
254 scm_c_define ("SDL_INIT_NOPARACHUTE", scm_from_int (SDL_INIT_NOPARACHUTE));
255 scm_c_define ("SDL_INIT_EVENTTHREAD", scm_from_int (SDL_INIT_EVENTTHREAD));
256 scm_c_define ("SDL_INIT_EVERYTHING", scm_from_int (SDL_INIT_EVERYTHING));
258 scm_c_define ("SDL_SWSURFACE", scm_from_int (SDL_SWSURFACE));
259 scm_c_define ("SDL_HWSURFACE", scm_from_int (SDL_HWSURFACE));
260 scm_c_define ("SDL_ASYNCBLIT", scm_from_int (SDL_ASYNCBLIT));
262 scm_c_define ("SDL_ANYFORMAT", scm_from_int (SDL_ANYFORMAT));
263 scm_c_define ("SDL_HWPALETTE", scm_from_int (SDL_HWPALETTE));
264 scm_c_define ("SDL_DOUBLEBUF", scm_from_int (SDL_DOUBLEBUF));
265 scm_c_define ("SDL_FULLSCREEN", scm_from_int (SDL_FULLSCREEN));
266 scm_c_define ("SDL_OPENGL", scm_from_int (SDL_OPENGL));
267 scm_c_define ("SDL_OPENGLBLIT", scm_from_int (SDL_OPENGLBLIT));
268 scm_c_define ("SDL_RESIZABLE", scm_from_int (SDL_RESIZABLE));
269 scm_c_define ("SDL_NOFRAME", scm_from_int (SDL_NOFRAME));
271 scm_c_define ("SDL_HWACCEL", scm_from_int (SDL_HWACCEL));
272 scm_c_define ("SDL_SRCCOLORKEY", scm_from_int (SDL_SRCCOLORKEY));
274 scm_c_define ("SDL_GL_DOUBLEBUFFER", scm_from_int (SDL_GL_DOUBLEBUFFER));
276 scm_c_define ("SDL_DEFAULT_REPEAT_DELAY", scm_from_int (SDL_DEFAULT_REPEAT_DELAY));
277 scm_c_define ("SDL_DEFAULT_REPEAT_INTERVAL", scm_from_int (SDL_DEFAULT_REPEAT_INTERVAL));
279 scm_c_define ("SDL_LIL_ENDIAN", scm_from_int (SDL_LIL_ENDIAN));
280 scm_c_define ("SDL_BIG_ENDIAN", scm_from_int (SDL_BIG_ENDIAN));
281 scm_c_define ("SDL_BYTEORDER", scm_from_int (SDL_BYTEORDER));
283 scm_c_define ("MIX_DEFAULT_FORMAT", scm_from_int (MIX_DEFAULT_FORMAT));
285 scm_c_define_gsubr ("SDL_Init", 1, 0, 0, gacela_SDL_Init);
286 scm_c_define_gsubr ("SDL_Quit", 0, 0, 0, gacela_SDL_Quit);
287 scm_c_define_gsubr ("SDL_SetVideoMode", 4, 0, 0, gacela_SDL_SetVideoMode);
288 scm_c_define_gsubr ("SDL_WM_SetCaption", 2, 0, 0, gacela_SDL_WM_SetCaption);
289 scm_c_define_gsubr ("SDL_Flip", 1, 0, 0, gacela_SDL_Flip);
290 scm_c_define_gsubr ("SDL_FreeSurface", 1, 0, 0, gacela_SDL_FreeSurface);
291 scm_c_define_gsubr ("SDL_Delay", 1, 0, 0, gacela_SDL_Delay);
292 scm_c_define_gsubr ("SDL_GetTicks", 0, 0, 0, gacela_SDL_GetTicks);
293 scm_c_define_gsubr ("SDL_DisplayFormat", 1, 0, 0, gacela_SDL_DisplayFormat);
294 scm_c_define_gsubr ("SDL_MapRGB", 4, 0, 0, gacela_SDL_MapRGB);
295 scm_c_define_gsubr ("SDL_SetColorKey", 3, 0, 0, gacela_SDL_SetColorKey);
296 scm_c_define_gsubr ("SDL_LoadBMP", 1, 0, 0, gacela_SDL_LoadBMP);
297 scm_c_define_gsubr ("IMG_Load", 1, 0, 0, gacela_IMG_Load);
298 scm_c_define_gsubr ("SDL_GetVideoInfo", 0, 0, 0, gacela_SDL_GetVideoInfo);
299 scm_c_define_gsubr ("SDL_GL_SetAttribute", 2, 0, 0, gacela_SDL_GL_SetAttribute);
300 scm_c_define_gsubr ("SDL_PollEvent", 0, 0, 0, gacela_SDL_PollEvent);
301 scm_c_define_gsubr ("SDL_GL_SwapBuffers", 0, 0, 0, gacela_SDL_GL_SwapBuffers);
302 scm_c_define_gsubr ("SDL_EnableKeyRepeat", 2, 0, 0, gacela_SDL_EnableKeyRepeat);
303 scm_c_define_gsubr ("Mix_OpenAudio", 4, 0, 0, gacela_Mix_OpenAudio);
304 scm_c_define_gsubr ("Mix_LoadMUS", 1, 0, 0, gacela_Mix_LoadMUS);
305 scm_c_define_gsubr ("Mix_LoadWAV", 1, 0, 0, gacela_Mix_LoadWAV);
306 scm_c_define_gsubr ("Mix_PlayChannel", 3, 0, 0, gacela_Mix_PlayChannel);
307 scm_c_define_gsubr ("Mix_PlayMusic", 2, 0, 0, gacela_Mix_PlayMusic);
308 scm_c_define_gsubr ("Mix_PlayingMusic", 0, 0, 0, gacela_Mix_PlayingMusic);
309 scm_c_define_gsubr ("Mix_PausedMusic", 0, 0, 0, gacela_Mix_PausedMusic);
310 scm_c_define_gsubr ("Mix_PauseMusic", 0, 0, 0, gacela_Mix_PauseMusic);
311 scm_c_define_gsubr ("Mix_ResumeMusic", 0, 0, 0, gacela_Mix_ResumeMusic);
312 scm_c_define_gsubr ("Mix_HaltMusic", 0, 0, 0, gacela_Mix_HaltMusic);
313 scm_c_define_gsubr ("Mix_FreeMusic", 1, 0, 0, gacela_Mix_FreeMusic);
314 scm_c_define_gsubr ("Mix_FreeChunk", 1, 0, 0, gacela_Mix_FreeChunk);
315 scm_c_define_gsubr ("Mix_CloseAudio", 0, 0, 0, gacela_Mix_CloseAudio);