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 #if defined(TARGET_SDL2)
31 #define SET_TRANSPARENT_PIXEL (SDL_TRUE)
32 #define UNSET_TRANSPARENT_PIXEL (SDL_FALSE)
34 #define SET_TRANSPARENT_PIXEL (SDL_SRCCOLORKEY)
35 #define UNSET_TRANSPARENT_PIXEL (0)
38 #if defined(TARGET_SDL2)
39 #define SDL_DisplayFormat(s) (s)
42 /* system dependent definitions */
44 #define TARGET_STRING "SDL"
45 #define FULLSCREEN_STATUS FULLSCREEN_AVAILABLE
47 #define CURSOR_MAX_WIDTH 32
48 #define CURSOR_MAX_HEIGHT 32
51 /* SDL type definitions */
53 typedef struct SDLSurfaceInfo Bitmap;
54 typedef struct SDLSurfaceInfo DrawBuffer;
55 typedef struct SDLSurfaceInfo DrawWindow;
57 typedef SDL_Cursor *Cursor;
59 #if defined(TARGET_SDL2)
60 typedef SDL_Keycode Key;
64 typedef unsigned int KeyMod;
66 typedef SDL_Event Event;
67 typedef SDL_MouseButtonEvent ButtonEvent;
68 typedef SDL_MouseMotionEvent MotionEvent;
69 typedef SDL_KeyboardEvent KeyEvent;
70 typedef SDL_Event ExposeEvent;
71 typedef SDL_Event FocusChangeEvent;
72 typedef SDL_Event ClientMessageEvent;
81 /* structure definitions */
85 char *source_filename;
89 SDL_Surface *surface_masked;
94 struct MouseCursorInfo
99 byte data[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8];
100 byte mask[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8];
104 /* SDL symbol definitions */
108 #define BLACK_PIXEL 0x000000
109 #define WHITE_PIXEL 0xffffff
111 #define EVENT_BUTTONPRESS SDL_MOUSEBUTTONDOWN
112 #define EVENT_BUTTONRELEASE SDL_MOUSEBUTTONUP
113 #define EVENT_MOTIONNOTIFY SDL_MOUSEMOTION
114 #define EVENT_KEYPRESS SDL_KEYDOWN
115 #define EVENT_KEYRELEASE SDL_KEYUP
116 #define EVENT_EXPOSE SDL_USEREVENT + 0
117 #define EVENT_FOCUSIN SDL_USEREVENT + 1
118 #define EVENT_FOCUSOUT SDL_USEREVENT + 2
119 #define EVENT_CLIENTMESSAGE SDL_QUIT
120 #define EVENT_MAPNOTIFY SDL_USEREVENT + 4
121 #define EVENT_UNMAPNOTIFY SDL_USEREVENT + 5
123 #define KSYM_UNDEFINED SDLK_UNKNOWN
125 #define KSYM_Return SDLK_RETURN
126 #define KSYM_Escape SDLK_ESCAPE
128 #define KSYM_Left SDLK_LEFT
129 #define KSYM_Right SDLK_RIGHT
130 #define KSYM_Up SDLK_UP
131 #define KSYM_Down SDLK_DOWN
134 #define KSYM_KP_Left SDLK_KP_LEFT
135 #define KSYM_KP_Right SDLK_KP_RIGHT
136 #define KSYM_KP_Up SDLK_KP_UP
137 #define KSYM_KP_Down SDLK_KP_DOWN
140 #define KSYM_KP_Enter SDLK_KP_ENTER
141 #define KSYM_KP_Add SDLK_KP_PLUS
142 #define KSYM_KP_Subtract SDLK_KP_MINUS
143 #define KSYM_KP_Multiply SDLK_KP_MULTIPLY
144 #define KSYM_KP_Divide SDLK_KP_DIVIDE
145 #define KSYM_KP_Separator SDLK_KP_PERIOD
147 #define KSYM_Shift_L SDLK_LSHIFT
148 #define KSYM_Shift_R SDLK_RSHIFT
149 #define KSYM_Control_L SDLK_LCTRL
150 #define KSYM_Control_R SDLK_RCTRL
151 #if defined(TARGET_SDL2)
152 #define KSYM_Meta_L SDLK_LGUI
153 #define KSYM_Meta_R SDLK_RGUI
155 #define KSYM_Meta_L SDLK_LMETA
156 #define KSYM_Meta_R SDLK_RMETA
158 #define KSYM_Alt_L SDLK_LALT
159 #define KSYM_Alt_R SDLK_RALT
160 #if !defined(TARGET_SDL2)
161 #define KSYM_Super_L SDLK_LSUPER
162 #define KSYM_Super_R SDLK_RSUPER
164 #define KSYM_Mode_switch SDLK_MODE
165 #define KSYM_Multi_key SDLK_RCTRL
167 #define KSYM_BackSpace SDLK_BACKSPACE
168 #define KSYM_Delete SDLK_DELETE
169 #define KSYM_Insert SDLK_INSERT
170 #define KSYM_Tab SDLK_TAB
171 #define KSYM_Home SDLK_HOME
172 #define KSYM_End SDLK_END
173 #define KSYM_Page_Up SDLK_PAGEUP
174 #define KSYM_Page_Down SDLK_PAGEDOWN
175 #define KSYM_Menu SDLK_MENU
177 #define KSYM_space SDLK_SPACE
178 #define KSYM_exclam SDLK_EXCLAIM
179 #define KSYM_quotedbl SDLK_QUOTEDBL
180 #define KSYM_numbersign SDLK_HASH
181 #define KSYM_dollar SDLK_DOLLAR
182 #define KSYM_percent KSYM_UNDEFINED /* undefined */
183 #define KSYM_ampersand SDLK_AMPERSAND
184 #define KSYM_apostrophe SDLK_QUOTE
185 #define KSYM_parenleft SDLK_LEFTPAREN
186 #define KSYM_parenright SDLK_RIGHTPAREN
187 #define KSYM_asterisk SDLK_ASTERISK
188 #define KSYM_plus SDLK_PLUS
189 #define KSYM_comma SDLK_COMMA
190 #define KSYM_minus SDLK_MINUS
191 #define KSYM_period SDLK_PERIOD
192 #define KSYM_slash SDLK_SLASH
194 #define KSYM_colon SDLK_COLON
195 #define KSYM_semicolon SDLK_SEMICOLON
196 #define KSYM_less SDLK_LESS
197 #define KSYM_equal SDLK_EQUALS
198 #define KSYM_greater SDLK_GREATER
199 #define KSYM_question SDLK_QUESTION
200 #define KSYM_at SDLK_AT
202 #define KSYM_bracketleft SDLK_LEFTBRACKET
203 #define KSYM_backslash SDLK_BACKSLASH
204 #define KSYM_bracketright SDLK_RIGHTBRACKET
205 #define KSYM_asciicircum SDLK_CARET
206 #define KSYM_underscore SDLK_UNDERSCORE
207 #define KSYM_grave SDLK_BACKQUOTE
209 #define KSYM_quoteleft KSYM_UNDEFINED /* undefined */
210 #define KSYM_braceleft KSYM_UNDEFINED /* undefined */
211 #define KSYM_bar KSYM_UNDEFINED /* undefined */
212 #define KSYM_braceright KSYM_UNDEFINED /* undefined */
213 #define KSYM_asciitilde KSYM_UNDEFINED /* undefined */
215 #if !defined(TARGET_SDL2)
216 #define KSYM_degree SDLK_WORLD_16
217 #define KSYM_Adiaeresis SDLK_WORLD_36
218 #define KSYM_Odiaeresis SDLK_WORLD_54
219 #define KSYM_Udiaeresis SDLK_WORLD_60
220 #define KSYM_adiaeresis SDLK_WORLD_68
221 #define KSYM_odiaeresis SDLK_WORLD_86
222 #define KSYM_udiaeresis SDLK_WORLD_92
223 #define KSYM_ssharp SDLK_WORLD_63
255 #define KSYM_A SDLK_A
256 #define KSYM_B SDLK_B
257 #define KSYM_C SDLK_C
258 #define KSYM_D SDLK_D
259 #define KSYM_E SDLK_E
260 #define KSYM_F SDLK_F
261 #define KSYM_G SDLK_G
262 #define KSYM_H SDLK_H
263 #define KSYM_I SDLK_I
264 #define KSYM_J SDLK_J
265 #define KSYM_K SDLK_K
266 #define KSYM_L SDLK_L
267 #define KSYM_M SDLK_M
268 #define KSYM_N SDLK_N
269 #define KSYM_O SDLK_O
270 #define KSYM_P SDLK_P
271 #define KSYM_Q SDLK_Q
272 #define KSYM_R SDLK_R
273 #define KSYM_S SDLK_S
274 #define KSYM_T SDLK_T
275 #define KSYM_U SDLK_U
276 #define KSYM_V SDLK_V
277 #define KSYM_W SDLK_W
278 #define KSYM_X SDLK_X
279 #define KSYM_Y SDLK_Y
280 #define KSYM_Z SDLK_Z
282 #define KSYM_a SDLK_a
283 #define KSYM_b SDLK_b
284 #define KSYM_c SDLK_c
285 #define KSYM_d SDLK_d
286 #define KSYM_e SDLK_e
287 #define KSYM_f SDLK_f
288 #define KSYM_g SDLK_g
289 #define KSYM_h SDLK_h
290 #define KSYM_i SDLK_i
291 #define KSYM_j SDLK_j
292 #define KSYM_k SDLK_k
293 #define KSYM_l SDLK_l
294 #define KSYM_m SDLK_m
295 #define KSYM_n SDLK_n
296 #define KSYM_o SDLK_o
297 #define KSYM_p SDLK_p
298 #define KSYM_q SDLK_q
299 #define KSYM_r SDLK_r
300 #define KSYM_s SDLK_s
301 #define KSYM_t SDLK_t
302 #define KSYM_u SDLK_u
303 #define KSYM_v SDLK_v
304 #define KSYM_w SDLK_w
305 #define KSYM_x SDLK_x
306 #define KSYM_y SDLK_y
307 #define KSYM_z SDLK_z
309 #define KSYM_0 SDLK_0
310 #define KSYM_1 SDLK_1
311 #define KSYM_2 SDLK_2
312 #define KSYM_3 SDLK_3
313 #define KSYM_4 SDLK_4
314 #define KSYM_5 SDLK_5
315 #define KSYM_6 SDLK_6
316 #define KSYM_7 SDLK_7
317 #define KSYM_8 SDLK_8
318 #define KSYM_9 SDLK_9
320 #if defined(TARGET_SDL2)
321 #define KSYM_KP_0 SDLK_KP_0
322 #define KSYM_KP_1 SDLK_KP_1
323 #define KSYM_KP_2 SDLK_KP_2
324 #define KSYM_KP_3 SDLK_KP_3
325 #define KSYM_KP_4 SDLK_KP_4
326 #define KSYM_KP_5 SDLK_KP_5
327 #define KSYM_KP_6 SDLK_KP_6
328 #define KSYM_KP_7 SDLK_KP_7
329 #define KSYM_KP_8 SDLK_KP_8
330 #define KSYM_KP_9 SDLK_KP_9
332 #define KSYM_KP_0 SDLK_KP0
333 #define KSYM_KP_1 SDLK_KP1
334 #define KSYM_KP_2 SDLK_KP2
335 #define KSYM_KP_3 SDLK_KP3
336 #define KSYM_KP_4 SDLK_KP4
337 #define KSYM_KP_5 SDLK_KP5
338 #define KSYM_KP_6 SDLK_KP6
339 #define KSYM_KP_7 SDLK_KP7
340 #define KSYM_KP_8 SDLK_KP8
341 #define KSYM_KP_9 SDLK_KP9
344 #define KSYM_F1 SDLK_F1
345 #define KSYM_F2 SDLK_F2
346 #define KSYM_F3 SDLK_F3
347 #define KSYM_F4 SDLK_F4
348 #define KSYM_F5 SDLK_F5
349 #define KSYM_F6 SDLK_F6
350 #define KSYM_F7 SDLK_F7
351 #define KSYM_F8 SDLK_F8
352 #define KSYM_F9 SDLK_F9
353 #define KSYM_F10 SDLK_F10
354 #define KSYM_F11 SDLK_F11
355 #define KSYM_F12 SDLK_F12
356 #define KSYM_F13 SDLK_F13
357 #define KSYM_F14 SDLK_F14
358 #define KSYM_F15 SDLK_F15
359 #define KSYM_F16 KSYM_UNDEFINED
360 #define KSYM_F17 KSYM_UNDEFINED
361 #define KSYM_F18 KSYM_UNDEFINED
362 #define KSYM_F19 KSYM_UNDEFINED
363 #define KSYM_F20 KSYM_UNDEFINED
364 #define KSYM_F21 KSYM_UNDEFINED
365 #define KSYM_F22 KSYM_UNDEFINED
366 #define KSYM_F23 KSYM_UNDEFINED
367 #define KSYM_F24 KSYM_UNDEFINED
369 #define KSYM_FKEY_FIRST KSYM_F1
370 #define KSYM_FKEY_LAST KSYM_F15
371 #define KSYM_NUM_FKEYS (KSYM_FKEY_LAST - KSYM_FKEY_FIRST + 1)
373 #define KMOD_None None
374 #define KMOD_Shift_L KMOD_LSHIFT
375 #define KMOD_Shift_R KMOD_RSHIFT
376 #define KMOD_Control_L KMOD_LCTRL
377 #define KMOD_Control_R KMOD_RCTRL
378 #if defined(TARGET_SDL2)
379 #define KMOD_Meta_L KMOD_LGUI
380 #define KMOD_Meta_R KMOD_RGUI
382 #define KMOD_Meta_L KMOD_LMETA
383 #define KMOD_Meta_R KMOD_RMETA
385 #define KMOD_Alt_L KMOD_LALT
386 #define KMOD_Alt_R KMOD_RALT
388 #define KMOD_Shift (KMOD_Shift_L | KMOD_Shift_R)
389 #define KMOD_Control (KMOD_Control_L | KMOD_Control_R)
390 #define KMOD_Meta (KMOD_Meta_L | KMOD_Meta_R)
391 #define KMOD_Alt (KMOD_Alt_L | KMOD_Alt_R)
394 /* SDL function definitions */
396 void SDLInitVideoDisplay(void);
397 void SDLInitVideoBuffer(DrawBuffer **, DrawWindow **, boolean);
398 boolean SDLSetVideoMode(DrawBuffer **, boolean);
399 void SDLCreateBitmapContent(Bitmap *, int, int, int);
400 void SDLFreeBitmapPointers(Bitmap *);
401 void SDLCopyArea(Bitmap *, Bitmap *, int, int, int, int, int, int, int);
402 void SDLFillRectangle(Bitmap *, int, int, int, int, Uint32);
403 void SDLFadeRectangle(Bitmap *, int, int, int, int, int, int, int,
404 void (*draw_border_function)(void));
405 void SDLDrawSimpleLine(Bitmap *, int, int, int, int, Uint32);
406 void SDLDrawLine(Bitmap *, int, int, int, int, Uint32);
407 Pixel SDLGetPixel(Bitmap *, int, int);
408 void SDLPutPixel(Bitmap *, int, int, Pixel);
410 void SDLInvertArea(Bitmap *, int, int, int, int, Uint32);
411 void SDLCopyInverseMasked(Bitmap *, Bitmap *, int, int, int, int, int, int);
413 void SDLZoomBitmap(Bitmap *, Bitmap *);
415 Bitmap *SDLLoadImage(char *);
417 void SDLSetMouseCursor(struct MouseCursorInfo *);
419 void SDLOpenAudio(void);
420 void SDLCloseAudio(void);
422 void SDLNextEvent(Event *);
423 void SDLHandleWindowManagerEvent(Event *);
425 void HandleJoystickEvent(Event *);
426 void SDLInitJoysticks(void);
427 boolean SDLReadJoystick(int, int *, int *, boolean *, boolean *);