]> git.jsancho.org Git - gacela.git/blob - gacela_SDL.lisp
(no commit message)
[gacela.git] / gacela_SDL.lisp
1 ;;; Gacela, a GNU Common Lisp extension for fast games development
2 ;;; Copyright (C) 2009 by Javier Sancho Fernandez <jsf at jsancho dot org>
3 ;;;
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.
8 ;;;
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.
13 ;;;
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/>.
16
17
18 (in-package :gacela)
19
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
25 ;;; These are the flags which may be passed to SDL_Init()
26 (defconstant SDL_INIT_TIMER             #x00000001)
27 (defconstant SDL_INIT_AUDIO             #x00000010)
28 (defconstant SDL_INIT_VIDEO             #x00000020)
29 (defconstant SDL_INIT_CDROM             #x00000100)
30 (defconstant SDL_INIT_JOYSTICK          #x00000200)
31 (defconstant SDL_INIT_NOPARACHUTE       #x00100000)
32 (defconstant SDL_INIT_EVENTTHREAD       #x01000000)
33 (defconstant SDL_INIT_EVERYTHING        #x0000FFFF)
34
35
36 ;;; These are the currently supported flags for the SDL_surface
37 ;;; Available for SDL_CreateRGBSurface() or SDL_SetVideoMode()
38 (defconstant SDL_SWSURFACE              #x00000000)
39 (defconstant SDL_HWSURFACE              #x00000001)
40 (defconstant SDL_ASYNCBLIT              #x00000004)
41
42
43 ;;; Available for SDL_SetVideoMode()
44 (defconstant SDL_ANYFORMAT              #x10000000)
45 (defconstant SDL_HWPALETTE              #x20000000)
46 (defconstant SDL_DOUBLEBUF              #x40000000)
47 (defconstant SDL_FULLSCREEN             #x80000000)
48 (defconstant SDL_OPENGL                 #x00000002)
49 (defconstant SDL_OPENGLBLIT             #x0000000A)
50 (defconstant SDL_RESIZABLE              #x00000010)
51 (defconstant SDL_NOFRAME                #x00000020)
52
53 ;;; Used internally (read-only)
54 (defconstant SDL_HWACCEL                #x00000100)
55 (defconstant SDL_SRCCOLORKEY            #x00001000)
56
57 ;;; For setting the OpenGL window attributes
58 (defconstant SDL_GL_DOUBLEBUFFER        5)
59
60 ;;; Keyboard
61 (defconstant SDL_DEFAULT_REPEAT_DELAY     500)
62 (defconstant SDL_DEFAULT_REPEAT_INTERVAL  30)
63
64 ;;; The two types of endianness
65 (defconstant SDL_LIL_ENDIAN  1234)
66 (defconstant SDL_BIG_ENDIAN  4321)
67
68
69 ;;; SDL Functions
70 (defcfun "int gacela_SDL_Init (int flags)" 0
71   "return SDL_Init (flags);")
72
73 (defcfun "void gacela_SDL_Quit (void)" 0
74   "SDL_Quit ();")
75
76 (defcfun "int gacela_SDL_SetVideoMode (int width, int height, int bpp, int flags)" 0
77   "return SDL_SetVideoMode (width, height, bpp, flags);")
78
79 (defcfun "void gacela_SDL_WM_SetCaption (char *title, char *icon)" 0
80   "SDL_WM_SetCaption (title, icon);")
81
82 (defcfun "int gacela_SDL_Flip (int screen)" 0
83   "return SDL_Flip (screen);")
84
85 (defcfun "void gacela_SDL_FreeSurface (int surface)" 0
86   "SDL_FreeSurface (surface);")
87
88 (defcfun "void gacela_SDL_Delay (int ms)" 0
89   "SDL_Delay (ms);")
90
91 (defcfun "int gacela_SDL_GetTicks (void)" 0
92   "return SDL_GetTicks ();")
93
94 (defcfun "int gacela_SDL_DisplayFormat (int surface)" 0
95   "return SDL_DisplayFormat (surface);")
96
97 (defcfun "int gacela_SDL_MapRGB (int format, int r, int g, int b)" 0
98   "return SDL_MapRGB (format, r, g, b);")
99
100 (defcfun "int gacela_SDL_SetColorKey (int surface, int flag, int key)" 0
101   "return SDL_SetColorKey (surface, flag, key);")
102
103 (defcfun "int gacela_SDL_LoadBMP (char *file)" 0
104   "return SDL_LoadBMP (file);")
105
106 (defcfun "int gacela_IMG_Load (char *filename)" 0
107   "return IMG_Load (filename);")
108
109 (defcfun "static object gacela_SDL_GetVideoInfo (void)" 0
110   "const SDL_VideoInfo *info;"
111   "object vi, label;"
112   "info = SDL_GetVideoInfo ();"
113   ('nil vi)
114   ((cons (int info->blit_hw) vi) vi) (':blit_hw label) ((cons label vi) vi)
115   ((cons (int info->hw_available) vi) vi) (':hw_available label) ((cons label vi) vi)
116   "return vi;")
117
118 (defcfun "int gacela_SDL_GL_SetAttribute (int attr, int value)" 0
119   "return SDL_GL_SetAttribute (attr, value);")
120
121 (defcfun "static object gacela_SDL_PollEvent (void)" 0
122   "SDL_Event sdl_event;"
123   "object event, label;"
124   ('nil event)
125   "if (SDL_PollEvent (&sdl_event)) {"
126   "  switch (sdl_event.type) {"
127   "    case SDL_KEYDOWN:"
128   "    case SDL_KEYUP:"
129   ((cons (int sdl_event.key.keysym.sym) event) event) (':key.keysym.sym label) ((cons label event) event)
130   "      break;"
131   "  }"
132   ((cons (int sdl_event.type) event) event) (':type label) ((cons label event) event)
133   "}"
134   "return event;")
135
136 (defcfun "void gacela_SDL_GL_SwapBuffers (void)" 0
137   "SDL_GL_SwapBuffers ();")
138
139 (defcfun "int gacela_SDL_EnableKeyRepeat (int delay, int interval)" 0
140   "return SDL_EnableKeyRepeat (delay, interval);")
141
142 (defcfun "int gacela_zoomSurface (int src, float zoomx, float zoomy, int smooth)" 0
143   "return zoomSurface (src, zoomx, zoomy, smooth);")
144
145 (defcfun "int gacela_SDL_ByteOrder (void)" 0
146   "return SDL_BYTEORDER;")
147
148 (defentry SDL_Init (int) (int "gacela_SDL_Init"))
149 (defentry SDL_Quit () (void "gacela_SDL_Quit"))
150 (defentry SDL_SetVideoMode (int int int int) (int "gacela_SDL_SetVideoMode"))
151 (defentry SDL_WM_SetCaption (string string) (void "gacela_SDL_WM_SetCaption"))
152 (defentry SDL_Flip (int) (int "gacela_SDL_Flip"))
153 (defentry SDL_FreeSurface (int) (void "gacela_SDL_FreeSurface"))
154 (defentry SDL_Delay (int) (void "gacela_SDL_Delay"))
155 (defentry SDL_GetTicks () (int "gacela_SDL_GetTicks"))
156 (defentry SDL_DisplayFormat (int) (int "gacela_SDL_DisplayFormat"))
157 ;(defentry SDL_SurfaceFormat (int) (int "gacela_SDL_SurfaceFormat"))
158 (defentry SDL_MapRGB (int int int int) (int "gacela_SDL_MapRGB"))
159 (defentry SDL_SetColorKey (int int int) (int "gacela_SDL_SetColorKey"))
160 ;(defentry SDL_BlitSurface (int int int int) (void "gacela_SDL_BlitSurface"))
161 ;(defentry SDL_Rect (int int int int) (int "gacela_SDL_Rect"))
162 (defentry SDL_LoadBMP (string) (int "gacela_SDL_LoadBMP"))
163 (defentry IMG_Load (string) (int "gacela_IMG_Load"))
164 (defentry SDL_GetVideoInfo () (object "gacela_SDL_GetVideoInfo"))
165 (defentry SDL_GL_SetAttribute (int int) (int "gacela_SDL_GL_SetAttribute"))
166 (defentry SDL_PollEvent () (object "gacela_SDL_PollEvent"))
167 ;(defentry TTF_Init () (int "gacela_TTF_Init"))
168 ;(defentry TTF_OpenFont (string int) (int "gacela_TTF_OpenFont"))
169 ;(defentry TTF_CloseFont (int) (void "gacela_TTF_CloseFont"))
170 ;(defentry TTF_Quit () (void "gacela_TTF_Quit"))
171 ;(defentry Mix_OpenAudio (int int int) (int "gacela_Mix_OpenAudio"))
172 ;(defentry Mix_LoadMUS (string) (int "gacela_Mix_LoadMUS"))
173 ;(defentry Mix_LoadWAV (string) (int "gacela_Mix_LoadWAV"))
174 ;(defentry Mix_PlayChannel (int int int) (int "gacela_Mix_PlayChannel"))
175 ;(defentry Mix_PlayMusic (int int) (int "gacela_Mix_PlayMusic"))
176 ;(defentry Mix_PlayingMusic () (int "gacela_Mix_PlayingMusic"))
177 ;(defentry Mix_PausedMusic () (int "gacela_Mix_PausedMusic"))
178 ;(defentry Mix_PauseMusic () (void "gacela_Mix_PauseMusic"))
179 ;(defentry Mix_ResumeMusic () (void "gacela_Mix_ResumeMusic"))
180 ;(defentry Mix_HaltMusic () (int "gacela_Mix_HaltMusic"))
181 ;(defentry Mix_FreeMusic (int) (void "gacela_Mix_FreeMusic"))
182 ;(defentry Mix_FreeChunk (int) (void "gacela_Mix_FreeChunk"))
183 ;(defentry Mix_CloseAudio () (void "gacela_Mix_CloseAudio"))
184 ;(defentry free (int) (void "gacela_free"))
185 (defentry SDL_GL_SwapBuffers () (void "gacela_SDL_GL_SwapBuffers"))
186 (defentry SDL_EnableKeyRepeat (int int) (int "gacela_SDL_EnableKeyRepeat"))
187 (defentry zoomSurface (int float float int) (int "gacela_zoomSurface"))
188 (defentry SDL_ByteOrder () (int "gacela_SDL_ByteOrder"))
189
190 ;;; C-Gacela Functions
191 (defcfun "int gacela_surface_format (int surface)" 0
192   "const SDL_Surface *s = surface;"
193   "return s->format;")
194
195 (defcfun "int gacela_surface_w (int surface)" 0
196   "const SDL_Surface *s = surface;"
197   "return s->w;")
198
199 (defcfun "int gacela_surface_h (int surface)" 0
200   "const SDL_Surface *s = surface;"
201   "return s->h;")
202
203 (defcfun "int gacela_surface_pixels (int surface)" 0
204   "const SDL_Surface *s = surface;"
205   "return s->pixels;")
206
207 (defcfun "int gacela_surface_format_BytesPerPixel (int surface)" 0
208   "const SDL_Surface *s = surface;"
209   "return s->format->BytesPerPixel;")
210
211 ;(defentry apply-surface2 (int int int int int int int int int) (void "apply_surface"))
212 ;(defentry render-text2 (int string int int int) (int "render_text"))
213 ;(defentry fill-surface (int int int int) (void "fill_surface"))
214 ;(defentry box-collision (int int int int int int) (int "box_collision"))
215 ;(defentry create-SDL_Surface (int int int int int int) (int "create_SDL_Surface"))
216 ;(defentry copy-SDL_Surface (int) (int "copy_SDL_Surface"))
217 (defentry surface-format (int) (int "gacela_surface_format"))
218 (defentry surface-w (int) (int "gacela_surface_w"))
219 (defentry surface-h (int) (int "gacela_surface_h"))
220 (defentry surface-pixels (int) (int "gacela_surface_pixels"))
221 (defentry surface-format-BytesPerPixel (int) (int "gacela_surface_format_BytesPerPixel"))