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"
29 static scm_t_bits surface_tag;
32 gacela_make_surface (SCM name)
35 struct surface *surface;
37 surface = (struct surface *) scm_gc_malloc (sizeof (struct surface), "surface");
39 surface->name = SCM_BOOL_F;
41 SCM_NEWSMOB (smob, surface_tag, surface);
49 gacela_SDL_Init (SCM flags)
51 return scm_from_int (SDL_Init (scm_to_int (flags)));
55 gacela_SDL_Quit (void)
58 return SCM_UNSPECIFIED;
62 gacela_SDL_SetVideoMode (SCM width, SCM height, SCM bpp, SCM flags)
64 return scm_from_int ((int)SDL_SetVideoMode (scm_to_int (width), scm_to_int (height), \
65 scm_to_int (bpp), scm_to_int (flags)));
69 gacela_SDL_WM_SetCaption (SCM title, SCM icon)
71 SDL_WM_SetCaption (scm_to_locale_string(title), scm_to_locale_string(icon));
72 return SCM_UNSPECIFIED;
76 gacela_SDL_Flip (SCM screen)
78 return scm_from_int (SDL_Flip ((SDL_Surface *)scm_to_int (screen)));
82 gacela_SDL_FreeSurface (SCM surface)
84 SDL_FreeSurface ((SDL_Surface *)scm_to_int (surface));
85 return SCM_UNSPECIFIED;
89 gacela_SDL_Delay (SCM ms)
91 SDL_Delay ((int)scm_to_double (ms));
92 return SCM_UNSPECIFIED;
96 gacela_SDL_GetTicks (void)
98 return scm_from_int (SDL_GetTicks ());
102 gacela_SDL_DisplayFormat (SCM surface)
104 return scm_from_int ((int)SDL_DisplayFormat ((SDL_Surface *)scm_to_int (surface)));
108 gacela_SDL_MapRGB (SCM format, SCM r, SCM g, SCM b)
110 return scm_from_int (SDL_MapRGB ((SDL_PixelFormat *)scm_to_int (format), scm_to_int (r), scm_to_int (g), scm_to_int (b)));
114 gacela_SDL_SetColorKey (SCM surface, SCM flag, SCM key)
116 return scm_from_int (SDL_SetColorKey ((SDL_Surface *)scm_to_int (surface), scm_to_int (flag), scm_to_int (key)));
120 gacela_SDL_LoadBMP (SCM file)
122 return scm_from_int ((int)SDL_LoadBMP (scm_to_locale_string (file)));
126 gacela_IMG_Load (SCM filename)
128 return scm_from_int ((int)IMG_Load (scm_to_locale_string (filename)));
132 gacela_SDL_GetVideoInfo (void)
134 const SDL_VideoInfo *info;
137 info = SDL_GetVideoInfo ();
138 vi = scm_list_n (SCM_UNDEFINED);
140 vi = scm_cons (scm_cons (scm_from_locale_symbol ("blit_hw"), scm_from_int (info->blit_hw)), vi);
141 vi = scm_cons (scm_cons (scm_from_locale_symbol ("hw_available"), scm_from_int (info->hw_available)), vi);
147 gacela_SDL_GL_SetAttribute (SCM attr, SCM value)
149 return scm_from_int (SDL_GL_SetAttribute (scm_to_int (attr), scm_to_int (value)));
153 gacela_SDL_PollEvent (void)
158 event = scm_list_n (SCM_UNDEFINED);
160 if (SDL_PollEvent (&sdl_event)) {
161 switch (sdl_event.type) {
164 event = scm_cons (scm_cons (scm_from_locale_symbol ("key.keysym.sym"), scm_from_int (sdl_event.key.keysym.sym)), event);
167 event = scm_cons (scm_cons (scm_from_locale_symbol ("type"), scm_from_int (sdl_event.type)), event);
174 gacela_SDL_GL_SwapBuffers (void)
176 SDL_GL_SwapBuffers ();
177 return SCM_UNSPECIFIED;
181 gacela_SDL_EnableKeyRepeat (SCM delay, SCM interval)
183 return scm_from_int (SDL_EnableKeyRepeat (scm_to_int (delay), scm_to_int (interval)));
187 gacela_Mix_OpenAudio (SCM frequency, SCM format, SCM channels, SCM chunksize)
189 return scm_from_int (Mix_OpenAudio (scm_to_int (frequency), scm_to_int (format), scm_to_int (channels), scm_to_int (chunksize)));
193 gacela_Mix_LoadMUS (SCM file)
195 return scm_from_int ((int)Mix_LoadMUS (scm_to_locale_string (file)));
199 gacela_Mix_LoadWAV (SCM file)
201 return scm_from_int ((int)Mix_LoadWAV (scm_to_locale_string (file)));
205 gacela_Mix_PlayChannel (SCM channel, SCM chunk, SCM loops)
207 return scm_from_int (Mix_PlayChannel (scm_to_int (channel), (Mix_Chunk *)scm_to_int (chunk), scm_to_int (loops)));
211 gacela_Mix_PlayMusic (SCM music, SCM loops)
213 return scm_from_int (Mix_PlayMusic ((Mix_Music *)scm_to_int (music), scm_to_int (loops)));
217 gacela_Mix_PlayingMusic (void)
219 return scm_from_int (Mix_PlayingMusic ());
223 gacela_Mix_PausedMusic (void)
225 return scm_from_int (Mix_PausedMusic ());
229 gacela_Mix_PauseMusic (void)
232 return SCM_UNSPECIFIED;
236 gacela_Mix_ResumeMusic (void)
239 return SCM_UNSPECIFIED;
243 gacela_Mix_HaltMusic (void)
245 return scm_from_int (Mix_HaltMusic ());
249 gacela_Mix_FreeMusic (SCM music)
251 Mix_FreeMusic ((Mix_Music *)scm_to_int (music));
252 return SCM_UNSPECIFIED;
256 gacela_Mix_FreeChunk (SCM chunk)
258 Mix_FreeChunk ((Mix_Chunk *)scm_to_int (chunk));
259 return SCM_UNSPECIFIED;
263 gacela_Mix_CloseAudio (void)
266 return SCM_UNSPECIFIED;
271 SDL_register_functions (void* data)
273 surface_tag = scm_make_smob_type ("surface", sizeof (struct surface));
274 // scm_set_smob_mark (surface_tag, mark_surface);
275 // scm_set_smob_free (surface_tag, free_surface);
276 // scm_set_smob_print (surface_tag, print_surface);
277 // scm_set_smob_equalp (surface_tag, equalp_surface);
279 scm_c_define ("SDL_INIT_TIMER", scm_from_int (SDL_INIT_TIMER));
280 scm_c_define ("SDL_INIT_AUDIO", scm_from_int (SDL_INIT_AUDIO));
281 scm_c_define ("SDL_INIT_VIDEO", scm_from_int (SDL_INIT_VIDEO));
282 scm_c_define ("SDL_INIT_CDROM", scm_from_int (SDL_INIT_CDROM));
283 scm_c_define ("SDL_INIT_JOYSTICK", scm_from_int (SDL_INIT_JOYSTICK));
284 scm_c_define ("SDL_INIT_NOPARACHUTE", scm_from_int (SDL_INIT_NOPARACHUTE));
285 scm_c_define ("SDL_INIT_EVENTTHREAD", scm_from_int (SDL_INIT_EVENTTHREAD));
286 scm_c_define ("SDL_INIT_EVERYTHING", scm_from_int (SDL_INIT_EVERYTHING));
288 scm_c_define ("SDL_SWSURFACE", scm_from_int (SDL_SWSURFACE));
289 scm_c_define ("SDL_HWSURFACE", scm_from_int (SDL_HWSURFACE));
290 scm_c_define ("SDL_ASYNCBLIT", scm_from_int (SDL_ASYNCBLIT));
292 scm_c_define ("SDL_ANYFORMAT", scm_from_int (SDL_ANYFORMAT));
293 scm_c_define ("SDL_HWPALETTE", scm_from_int (SDL_HWPALETTE));
294 scm_c_define ("SDL_DOUBLEBUF", scm_from_int (SDL_DOUBLEBUF));
295 scm_c_define ("SDL_FULLSCREEN", scm_from_int (SDL_FULLSCREEN));
296 scm_c_define ("SDL_OPENGL", scm_from_int (SDL_OPENGL));
297 scm_c_define ("SDL_OPENGLBLIT", scm_from_int (SDL_OPENGLBLIT));
298 scm_c_define ("SDL_RESIZABLE", scm_from_int (SDL_RESIZABLE));
299 scm_c_define ("SDL_NOFRAME", scm_from_int (SDL_NOFRAME));
301 scm_c_define ("SDL_HWACCEL", scm_from_int (SDL_HWACCEL));
302 scm_c_define ("SDL_SRCCOLORKEY", scm_from_int (SDL_SRCCOLORKEY));
304 scm_c_define ("SDL_GL_DOUBLEBUFFER", scm_from_int (SDL_GL_DOUBLEBUFFER));
306 scm_c_define ("SDL_DEFAULT_REPEAT_DELAY", scm_from_int (SDL_DEFAULT_REPEAT_DELAY));
307 scm_c_define ("SDL_DEFAULT_REPEAT_INTERVAL", scm_from_int (SDL_DEFAULT_REPEAT_INTERVAL));
309 scm_c_define ("SDL_LIL_ENDIAN", scm_from_int (SDL_LIL_ENDIAN));
310 scm_c_define ("SDL_BIG_ENDIAN", scm_from_int (SDL_BIG_ENDIAN));
311 scm_c_define ("SDL_BYTEORDER", scm_from_int (SDL_BYTEORDER));
313 scm_c_define ("MIX_DEFAULT_FORMAT", scm_from_int (MIX_DEFAULT_FORMAT));
315 scm_c_define_gsubr ("SDL_Init", 1, 0, 0, gacela_SDL_Init);
316 scm_c_define_gsubr ("SDL_Quit", 0, 0, 0, gacela_SDL_Quit);
317 scm_c_define_gsubr ("SDL_SetVideoMode", 4, 0, 0, gacela_SDL_SetVideoMode);
318 scm_c_define_gsubr ("SDL_WM_SetCaption", 2, 0, 0, gacela_SDL_WM_SetCaption);
319 scm_c_define_gsubr ("SDL_Flip", 1, 0, 0, gacela_SDL_Flip);
320 scm_c_define_gsubr ("SDL_FreeSurface", 1, 0, 0, gacela_SDL_FreeSurface);
321 scm_c_define_gsubr ("SDL_Delay", 1, 0, 0, gacela_SDL_Delay);
322 scm_c_define_gsubr ("SDL_GetTicks", 0, 0, 0, gacela_SDL_GetTicks);
323 scm_c_define_gsubr ("SDL_DisplayFormat", 1, 0, 0, gacela_SDL_DisplayFormat);
324 scm_c_define_gsubr ("SDL_MapRGB", 4, 0, 0, gacela_SDL_MapRGB);
325 scm_c_define_gsubr ("SDL_SetColorKey", 3, 0, 0, gacela_SDL_SetColorKey);
326 scm_c_define_gsubr ("SDL_LoadBMP", 1, 0, 0, gacela_SDL_LoadBMP);
327 scm_c_define_gsubr ("IMG_Load", 1, 0, 0, gacela_IMG_Load);
328 scm_c_define_gsubr ("SDL_GetVideoInfo", 0, 0, 0, gacela_SDL_GetVideoInfo);
329 scm_c_define_gsubr ("SDL_GL_SetAttribute", 2, 0, 0, gacela_SDL_GL_SetAttribute);
330 scm_c_define_gsubr ("SDL_PollEvent", 0, 0, 0, gacela_SDL_PollEvent);
331 scm_c_define_gsubr ("SDL_GL_SwapBuffers", 0, 0, 0, gacela_SDL_GL_SwapBuffers);
332 scm_c_define_gsubr ("SDL_EnableKeyRepeat", 2, 0, 0, gacela_SDL_EnableKeyRepeat);
333 scm_c_define_gsubr ("Mix_OpenAudio", 4, 0, 0, gacela_Mix_OpenAudio);
334 scm_c_define_gsubr ("Mix_LoadMUS", 1, 0, 0, gacela_Mix_LoadMUS);
335 scm_c_define_gsubr ("Mix_LoadWAV", 1, 0, 0, gacela_Mix_LoadWAV);
336 scm_c_define_gsubr ("Mix_PlayChannel", 3, 0, 0, gacela_Mix_PlayChannel);
337 scm_c_define_gsubr ("Mix_PlayMusic", 2, 0, 0, gacela_Mix_PlayMusic);
338 scm_c_define_gsubr ("Mix_PlayingMusic", 0, 0, 0, gacela_Mix_PlayingMusic);
339 scm_c_define_gsubr ("Mix_PausedMusic", 0, 0, 0, gacela_Mix_PausedMusic);
340 scm_c_define_gsubr ("Mix_PauseMusic", 0, 0, 0, gacela_Mix_PauseMusic);
341 scm_c_define_gsubr ("Mix_ResumeMusic", 0, 0, 0, gacela_Mix_ResumeMusic);
342 scm_c_define_gsubr ("Mix_HaltMusic", 0, 0, 0, gacela_Mix_HaltMusic);
343 scm_c_define_gsubr ("Mix_FreeMusic", 1, 0, 0, gacela_Mix_FreeMusic);
344 scm_c_define_gsubr ("Mix_FreeChunk", 1, 0, 0, gacela_Mix_FreeChunk);
345 scm_c_define_gsubr ("Mix_CloseAudio", 0, 0, 0, gacela_Mix_CloseAudio);
346 scm_c_define_gsubr ("make-surface", 1, 0, 0, gacela_make_surface);