1 /***********************************************************
2 * Artsoft Retro-Game Library *
3 *----------------------------------------------------------*
4 * (c) 1994-2006 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
18 #include <SDL_image.h>
19 #include <SDL_mixer.h>
21 #include <SDL_thread.h>
22 #if defined(PLATFORM_WIN32)
23 #include <SDL_syswm.h>
26 /* definitions needed for "system.c" */
28 #define SURFACE_FLAGS (SDL_SWSURFACE)
30 /* system dependent definitions */
32 #define TARGET_STRING "SDL"
33 #define FULLSCREEN_STATUS FULLSCREEN_AVAILABLE
35 #define CURSOR_MAX_WIDTH 32
36 #define CURSOR_MAX_HEIGHT 32
39 /* SDL type definitions */
41 typedef struct SDLSurfaceInfo Bitmap;
42 typedef struct SDLSurfaceInfo DrawBuffer;
43 typedef struct SDLSurfaceInfo DrawWindow;
45 typedef SDL_Cursor *Cursor;
48 typedef unsigned int KeyMod;
50 typedef SDL_Event Event;
51 typedef SDL_MouseButtonEvent ButtonEvent;
52 typedef SDL_MouseMotionEvent MotionEvent;
53 typedef SDL_KeyboardEvent KeyEvent;
54 typedef SDL_Event ExposeEvent;
55 typedef SDL_Event FocusChangeEvent;
56 typedef SDL_Event ClientMessageEvent;
65 /* structure definitions */
69 char *source_filename;
73 SDL_Surface *surface_masked;
78 struct MouseCursorInfo
83 byte data[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8];
84 byte mask[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8];
88 /* SDL symbol definitions */
92 #define BLACK_PIXEL 0x000000
93 #define WHITE_PIXEL 0xffffff
95 #define EVENT_BUTTONPRESS SDL_MOUSEBUTTONDOWN
96 #define EVENT_BUTTONRELEASE SDL_MOUSEBUTTONUP
97 #define EVENT_MOTIONNOTIFY SDL_MOUSEMOTION
98 #define EVENT_KEYPRESS SDL_KEYDOWN
99 #define EVENT_KEYRELEASE SDL_KEYUP
100 #define EVENT_EXPOSE SDL_USEREVENT + 0
101 #define EVENT_FOCUSIN SDL_USEREVENT + 1
102 #define EVENT_FOCUSOUT SDL_USEREVENT + 2
103 #define EVENT_CLIENTMESSAGE SDL_QUIT
104 #define EVENT_MAPNOTIFY SDL_USEREVENT + 4
105 #define EVENT_UNMAPNOTIFY SDL_USEREVENT + 5
107 #define KSYM_UNDEFINED SDLK_UNKNOWN
109 #define KSYM_Return SDLK_RETURN
110 #define KSYM_Escape SDLK_ESCAPE
112 #define KSYM_Left SDLK_LEFT
113 #define KSYM_Right SDLK_RIGHT
114 #define KSYM_Up SDLK_UP
115 #define KSYM_Down SDLK_DOWN
118 #define KSYM_KP_Left SDLK_KP_LEFT
119 #define KSYM_KP_Right SDLK_KP_RIGHT
120 #define KSYM_KP_Up SDLK_KP_UP
121 #define KSYM_KP_Down SDLK_KP_DOWN
124 #define KSYM_KP_Enter SDLK_KP_ENTER
125 #define KSYM_KP_Add SDLK_KP_PLUS
126 #define KSYM_KP_Subtract SDLK_KP_MINUS
127 #define KSYM_KP_Multiply SDLK_KP_MULTIPLY
128 #define KSYM_KP_Divide SDLK_KP_DIVIDE
129 #define KSYM_KP_Separator SDLK_KP_PERIOD
131 #define KSYM_Shift_L SDLK_LSHIFT
132 #define KSYM_Shift_R SDLK_RSHIFT
133 #define KSYM_Control_L SDLK_LCTRL
134 #define KSYM_Control_R SDLK_RCTRL
135 #define KSYM_Meta_L SDLK_LMETA
136 #define KSYM_Meta_R SDLK_RMETA
137 #define KSYM_Alt_L SDLK_LALT
138 #define KSYM_Alt_R SDLK_RALT
139 #define KSYM_Super_L SDLK_LSUPER
140 #define KSYM_Super_R SDLK_RSUPER
141 #define KSYM_Mode_switch SDLK_MODE
142 #define KSYM_Multi_key SDLK_RCTRL
144 #define KSYM_BackSpace SDLK_BACKSPACE
145 #define KSYM_Delete SDLK_DELETE
146 #define KSYM_Insert SDLK_INSERT
147 #define KSYM_Tab SDLK_TAB
148 #define KSYM_Home SDLK_HOME
149 #define KSYM_End SDLK_END
150 #define KSYM_Page_Up SDLK_PAGEUP
151 #define KSYM_Page_Down SDLK_PAGEDOWN
152 #define KSYM_Menu SDLK_MENU
154 #define KSYM_space SDLK_SPACE
155 #define KSYM_exclam SDLK_EXCLAIM
156 #define KSYM_quotedbl SDLK_QUOTEDBL
157 #define KSYM_numbersign SDLK_HASH
158 #define KSYM_dollar SDLK_DOLLAR
159 #define KSYM_percent KSYM_UNDEFINED /* undefined */
160 #define KSYM_ampersand SDLK_AMPERSAND
161 #define KSYM_apostrophe SDLK_QUOTE
162 #define KSYM_parenleft SDLK_LEFTPAREN
163 #define KSYM_parenright SDLK_RIGHTPAREN
164 #define KSYM_asterisk SDLK_ASTERISK
165 #define KSYM_plus SDLK_PLUS
166 #define KSYM_comma SDLK_COMMA
167 #define KSYM_minus SDLK_MINUS
168 #define KSYM_period SDLK_PERIOD
169 #define KSYM_slash SDLK_SLASH
171 #define KSYM_colon SDLK_COLON
172 #define KSYM_semicolon SDLK_SEMICOLON
173 #define KSYM_less SDLK_LESS
174 #define KSYM_equal SDLK_EQUALS
175 #define KSYM_greater SDLK_GREATER
176 #define KSYM_question SDLK_QUESTION
177 #define KSYM_at SDLK_AT
179 #define KSYM_bracketleft SDLK_LEFTBRACKET
180 #define KSYM_backslash SDLK_BACKSLASH
181 #define KSYM_bracketright SDLK_RIGHTBRACKET
182 #define KSYM_asciicircum SDLK_CARET
183 #define KSYM_underscore SDLK_UNDERSCORE
184 #define KSYM_grave SDLK_BACKQUOTE
186 #define KSYM_quoteleft KSYM_UNDEFINED /* undefined */
187 #define KSYM_braceleft KSYM_UNDEFINED /* undefined */
188 #define KSYM_bar KSYM_UNDEFINED /* undefined */
189 #define KSYM_braceright KSYM_UNDEFINED /* undefined */
190 #define KSYM_asciitilde KSYM_UNDEFINED /* undefined */
192 #define KSYM_degree SDLK_WORLD_16
193 #define KSYM_Adiaeresis SDLK_WORLD_36
194 #define KSYM_Odiaeresis SDLK_WORLD_54
195 #define KSYM_Udiaeresis SDLK_WORLD_60
196 #define KSYM_adiaeresis SDLK_WORLD_68
197 #define KSYM_odiaeresis SDLK_WORLD_86
198 #define KSYM_udiaeresis SDLK_WORLD_92
199 #define KSYM_ssharp SDLK_WORLD_63
230 #define KSYM_A SDLK_A
231 #define KSYM_B SDLK_B
232 #define KSYM_C SDLK_C
233 #define KSYM_D SDLK_D
234 #define KSYM_E SDLK_E
235 #define KSYM_F SDLK_F
236 #define KSYM_G SDLK_G
237 #define KSYM_H SDLK_H
238 #define KSYM_I SDLK_I
239 #define KSYM_J SDLK_J
240 #define KSYM_K SDLK_K
241 #define KSYM_L SDLK_L
242 #define KSYM_M SDLK_M
243 #define KSYM_N SDLK_N
244 #define KSYM_O SDLK_O
245 #define KSYM_P SDLK_P
246 #define KSYM_Q SDLK_Q
247 #define KSYM_R SDLK_R
248 #define KSYM_S SDLK_S
249 #define KSYM_T SDLK_T
250 #define KSYM_U SDLK_U
251 #define KSYM_V SDLK_V
252 #define KSYM_W SDLK_W
253 #define KSYM_X SDLK_X
254 #define KSYM_Y SDLK_Y
255 #define KSYM_Z SDLK_Z
257 #define KSYM_a SDLK_a
258 #define KSYM_b SDLK_b
259 #define KSYM_c SDLK_c
260 #define KSYM_d SDLK_d
261 #define KSYM_e SDLK_e
262 #define KSYM_f SDLK_f
263 #define KSYM_g SDLK_g
264 #define KSYM_h SDLK_h
265 #define KSYM_i SDLK_i
266 #define KSYM_j SDLK_j
267 #define KSYM_k SDLK_k
268 #define KSYM_l SDLK_l
269 #define KSYM_m SDLK_m
270 #define KSYM_n SDLK_n
271 #define KSYM_o SDLK_o
272 #define KSYM_p SDLK_p
273 #define KSYM_q SDLK_q
274 #define KSYM_r SDLK_r
275 #define KSYM_s SDLK_s
276 #define KSYM_t SDLK_t
277 #define KSYM_u SDLK_u
278 #define KSYM_v SDLK_v
279 #define KSYM_w SDLK_w
280 #define KSYM_x SDLK_x
281 #define KSYM_y SDLK_y
282 #define KSYM_z SDLK_z
284 #define KSYM_0 SDLK_0
285 #define KSYM_1 SDLK_1
286 #define KSYM_2 SDLK_2
287 #define KSYM_3 SDLK_3
288 #define KSYM_4 SDLK_4
289 #define KSYM_5 SDLK_5
290 #define KSYM_6 SDLK_6
291 #define KSYM_7 SDLK_7
292 #define KSYM_8 SDLK_8
293 #define KSYM_9 SDLK_9
295 #define KSYM_KP_0 SDLK_KP0
296 #define KSYM_KP_1 SDLK_KP1
297 #define KSYM_KP_2 SDLK_KP2
298 #define KSYM_KP_3 SDLK_KP3
299 #define KSYM_KP_4 SDLK_KP4
300 #define KSYM_KP_5 SDLK_KP5
301 #define KSYM_KP_6 SDLK_KP6
302 #define KSYM_KP_7 SDLK_KP7
303 #define KSYM_KP_8 SDLK_KP8
304 #define KSYM_KP_9 SDLK_KP9
306 #define KSYM_F1 SDLK_F1
307 #define KSYM_F2 SDLK_F2
308 #define KSYM_F3 SDLK_F3
309 #define KSYM_F4 SDLK_F4
310 #define KSYM_F5 SDLK_F5
311 #define KSYM_F6 SDLK_F6
312 #define KSYM_F7 SDLK_F7
313 #define KSYM_F8 SDLK_F8
314 #define KSYM_F9 SDLK_F9
315 #define KSYM_F10 SDLK_F10
316 #define KSYM_F11 SDLK_F11
317 #define KSYM_F12 SDLK_F12
318 #define KSYM_F13 SDLK_F13
319 #define KSYM_F14 SDLK_F14
320 #define KSYM_F15 SDLK_F15
321 #define KSYM_F16 KSYM_UNDEFINED
322 #define KSYM_F17 KSYM_UNDEFINED
323 #define KSYM_F18 KSYM_UNDEFINED
324 #define KSYM_F19 KSYM_UNDEFINED
325 #define KSYM_F20 KSYM_UNDEFINED
326 #define KSYM_F21 KSYM_UNDEFINED
327 #define KSYM_F22 KSYM_UNDEFINED
328 #define KSYM_F23 KSYM_UNDEFINED
329 #define KSYM_F24 KSYM_UNDEFINED
331 #define KSYM_FKEY_FIRST KSYM_F1
332 #define KSYM_FKEY_LAST KSYM_F15
333 #define KSYM_NUM_FKEYS (KSYM_FKEY_LAST - KSYM_FKEY_FIRST + 1)
335 #define KMOD_None None
336 #define KMOD_Shift_L KMOD_LSHIFT
337 #define KMOD_Shift_R KMOD_RSHIFT
338 #define KMOD_Control_L KMOD_LCTRL
339 #define KMOD_Control_R KMOD_RCTRL
340 #define KMOD_Meta_L KMOD_LMETA
341 #define KMOD_Meta_R KMOD_RMETA
342 #define KMOD_Alt_L KMOD_LALT
343 #define KMOD_Alt_R KMOD_RALT
345 #define KMOD_Shift (KMOD_Shift_L | KMOD_Shift_R)
346 #define KMOD_Control (KMOD_Control_L | KMOD_Control_R)
347 #define KMOD_Meta (KMOD_Meta_L | KMOD_Meta_R)
348 #define KMOD_Alt (KMOD_Alt_L | KMOD_Alt_R)
351 /* SDL function definitions */
353 void SDLInitVideoDisplay(void);
354 void SDLInitVideoBuffer(DrawBuffer **, DrawWindow **, boolean);
355 boolean SDLSetVideoMode(DrawBuffer **, boolean);
356 void SDLCreateBitmapContent(Bitmap *, int, int, int);
357 void SDLFreeBitmapPointers(Bitmap *);
358 void SDLCopyArea(Bitmap *, Bitmap *, int, int, int, int, int, int, int);
359 void SDLFillRectangle(Bitmap *, int, int, int, int, Uint32);
360 void SDLFadeRectangle(Bitmap *, int, int, int, int, int, int, int,
361 void (*draw_border_function)(void));
362 void SDLDrawSimpleLine(Bitmap *, int, int, int, int, Uint32);
363 void SDLDrawLine(Bitmap *, int, int, int, int, Uint32);
364 Pixel SDLGetPixel(Bitmap *, int, int);
365 void SDLPutPixel(Bitmap *, int, int, Pixel);
367 void SDLInvertArea(Bitmap *, int, int, int, int, Uint32);
368 void SDLCopyInverseMasked(Bitmap *, Bitmap *, int, int, int, int, int, int);
370 void SDLZoomBitmap(Bitmap *, Bitmap *);
372 Bitmap *SDLLoadImage(char *);
374 void SDLSetMouseCursor(struct MouseCursorInfo *);
376 void SDLOpenAudio(void);
377 void SDLCloseAudio(void);
379 void SDLNextEvent(Event *);
380 void SDLHandleWindowManagerEvent(Event *);
382 void HandleJoystickEvent(Event *);
383 void SDLInitJoysticks(void);
384 boolean SDLReadJoystick(int, int *, int *, boolean *, boolean *);