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 #if defined(TARGET_SDL2)
29 #define SURFACE_FLAGS (0)
31 #define SURFACE_FLAGS (SDL_SWSURFACE)
34 #if defined(TARGET_SDL2)
35 #define SET_TRANSPARENT_PIXEL (SDL_TRUE)
36 #define UNSET_TRANSPARENT_PIXEL (SDL_FALSE)
38 #define SET_TRANSPARENT_PIXEL (SDL_SRCCOLORKEY)
39 #define UNSET_TRANSPARENT_PIXEL (0)
42 /* system dependent definitions */
44 #if defined(TARGET_SDL2)
45 #define TARGET_STRING "SDL2"
47 #define TARGET_STRING "SDL"
50 #define FULLSCREEN_STATUS FULLSCREEN_AVAILABLE
52 #define CURSOR_MAX_WIDTH 32
53 #define CURSOR_MAX_HEIGHT 32
56 /* SDL type definitions */
58 typedef struct SDLSurfaceInfo Bitmap;
59 typedef struct SDLSurfaceInfo DrawBuffer;
60 typedef struct SDLSurfaceInfo DrawWindow;
62 typedef SDL_Cursor *Cursor;
64 #if defined(TARGET_SDL2)
65 typedef SDL_Keycode Key;
66 typedef SDL_Keymod KeyMod;
69 typedef unsigned int KeyMod;
72 typedef SDL_Event Event;
73 typedef SDL_MouseButtonEvent ButtonEvent;
74 typedef SDL_MouseMotionEvent MotionEvent;
75 #if defined(TARGET_SDL2)
76 typedef SDL_TouchFingerEvent FingerEvent;
77 typedef SDL_TextInputEvent TextEvent;
79 typedef SDL_KeyboardEvent KeyEvent;
80 typedef SDL_Event ExposeEvent;
81 typedef SDL_Event FocusChangeEvent;
82 typedef SDL_Event ClientMessageEvent;
91 /* structure definitions */
95 char *source_filename;
99 SDL_Surface *surface_masked;
104 struct MouseCursorInfo
109 byte data[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8];
110 byte mask[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8];
114 /* SDL symbol definitions */
118 #define BLACK_PIXEL 0x000000
119 #define WHITE_PIXEL 0xffffff
121 #define EVENT_BUTTONPRESS SDL_MOUSEBUTTONDOWN
122 #define EVENT_BUTTONRELEASE SDL_MOUSEBUTTONUP
123 #define EVENT_MOTIONNOTIFY SDL_MOUSEMOTION
124 #if defined(TARGET_SDL2)
125 #define EVENT_FINGERPRESS SDL_FINGERDOWN
126 #define EVENT_FINGERRELEASE SDL_FINGERUP
127 #define EVENT_FINGERMOTION SDL_FINGERMOTION
128 #define EVENT_TEXTINPUT SDL_TEXTINPUT
130 #define EVENT_KEYPRESS SDL_KEYDOWN
131 #define EVENT_KEYRELEASE SDL_KEYUP
132 #define EVENT_EXPOSE SDL_USEREVENT + 0
133 #define EVENT_FOCUSIN SDL_USEREVENT + 1
134 #define EVENT_FOCUSOUT SDL_USEREVENT + 2
135 #define EVENT_CLIENTMESSAGE SDL_QUIT
136 #define EVENT_MAPNOTIFY SDL_USEREVENT + 4
137 #define EVENT_UNMAPNOTIFY SDL_USEREVENT + 5
139 #define KSYM_UNDEFINED SDLK_UNKNOWN
141 #define KSYM_Return SDLK_RETURN
142 #define KSYM_Escape SDLK_ESCAPE
144 #define KSYM_Left SDLK_LEFT
145 #define KSYM_Right SDLK_RIGHT
146 #define KSYM_Up SDLK_UP
147 #define KSYM_Down SDLK_DOWN
150 #define KSYM_KP_Left SDLK_KP_LEFT
151 #define KSYM_KP_Right SDLK_KP_RIGHT
152 #define KSYM_KP_Up SDLK_KP_UP
153 #define KSYM_KP_Down SDLK_KP_DOWN
156 #define KSYM_KP_Enter SDLK_KP_ENTER
157 #define KSYM_KP_Add SDLK_KP_PLUS
158 #define KSYM_KP_Subtract SDLK_KP_MINUS
159 #define KSYM_KP_Multiply SDLK_KP_MULTIPLY
160 #define KSYM_KP_Divide SDLK_KP_DIVIDE
161 #define KSYM_KP_Separator SDLK_KP_PERIOD
163 #define KSYM_Shift_L SDLK_LSHIFT
164 #define KSYM_Shift_R SDLK_RSHIFT
165 #define KSYM_Control_L SDLK_LCTRL
166 #define KSYM_Control_R SDLK_RCTRL
168 #if defined(TARGET_SDL2)
169 #define KSYM_Meta_L SDLK_LGUI
170 #define KSYM_Meta_R SDLK_RGUI
172 #define KSYM_Meta_L SDLK_LMETA
173 #define KSYM_Meta_R SDLK_RMETA
176 #define KSYM_Alt_L SDLK_LALT
177 #define KSYM_Alt_R SDLK_RALT
178 #if !defined(TARGET_SDL2)
179 #define KSYM_Super_L SDLK_LSUPER
180 #define KSYM_Super_R SDLK_RSUPER
182 #define KSYM_Mode_switch SDLK_MODE
183 #define KSYM_Multi_key SDLK_RCTRL
185 #define KSYM_BackSpace SDLK_BACKSPACE
186 #define KSYM_Delete SDLK_DELETE
187 #define KSYM_Insert SDLK_INSERT
188 #define KSYM_Tab SDLK_TAB
189 #define KSYM_Home SDLK_HOME
190 #define KSYM_End SDLK_END
191 #define KSYM_Page_Up SDLK_PAGEUP
192 #define KSYM_Page_Down SDLK_PAGEDOWN
194 #if defined(TARGET_SDL2)
195 #define KSYM_Menu SDLK_MENU
196 #define KSYM_Back SDLK_AC_BACK
199 #define KSYM_space SDLK_SPACE
200 #define KSYM_exclam SDLK_EXCLAIM
201 #define KSYM_quotedbl SDLK_QUOTEDBL
202 #define KSYM_numbersign SDLK_HASH
203 #define KSYM_dollar SDLK_DOLLAR
204 #define KSYM_percent KSYM_UNDEFINED /* undefined */
205 #define KSYM_ampersand SDLK_AMPERSAND
206 #define KSYM_apostrophe SDLK_QUOTE
207 #define KSYM_parenleft SDLK_LEFTPAREN
208 #define KSYM_parenright SDLK_RIGHTPAREN
209 #define KSYM_asterisk SDLK_ASTERISK
210 #define KSYM_plus SDLK_PLUS
211 #define KSYM_comma SDLK_COMMA
212 #define KSYM_minus SDLK_MINUS
213 #define KSYM_period SDLK_PERIOD
214 #define KSYM_slash SDLK_SLASH
216 #define KSYM_colon SDLK_COLON
217 #define KSYM_semicolon SDLK_SEMICOLON
218 #define KSYM_less SDLK_LESS
219 #define KSYM_equal SDLK_EQUALS
220 #define KSYM_greater SDLK_GREATER
221 #define KSYM_question SDLK_QUESTION
222 #define KSYM_at SDLK_AT
224 #define KSYM_bracketleft SDLK_LEFTBRACKET
225 #define KSYM_backslash SDLK_BACKSLASH
226 #define KSYM_bracketright SDLK_RIGHTBRACKET
227 #define KSYM_asciicircum SDLK_CARET
228 #define KSYM_underscore SDLK_UNDERSCORE
229 #define KSYM_grave SDLK_BACKQUOTE
231 #define KSYM_quoteleft KSYM_UNDEFINED /* undefined */
232 #define KSYM_braceleft KSYM_UNDEFINED /* undefined */
233 #define KSYM_bar KSYM_UNDEFINED /* undefined */
234 #define KSYM_braceright KSYM_UNDEFINED /* undefined */
235 #define KSYM_asciitilde KSYM_UNDEFINED /* undefined */
237 #if defined(TARGET_SDL2)
238 #define KSYM_degree 176
239 #define KSYM_Adiaeresis 196
240 #define KSYM_Odiaeresis 214
241 #define KSYM_Udiaeresis 220
242 #define KSYM_adiaeresis 228
243 #define KSYM_odiaeresis 246
244 #define KSYM_udiaeresis 252
245 #define KSYM_ssharp 223
247 #define KSYM_degree SDLK_WORLD_16
248 #define KSYM_Adiaeresis SDLK_WORLD_36
249 #define KSYM_Odiaeresis SDLK_WORLD_54
250 #define KSYM_Udiaeresis SDLK_WORLD_60
251 #define KSYM_adiaeresis SDLK_WORLD_68
252 #define KSYM_odiaeresis SDLK_WORLD_86
253 #define KSYM_udiaeresis SDLK_WORLD_92
254 #define KSYM_ssharp SDLK_WORLD_63
286 #define KSYM_A SDLK_A
287 #define KSYM_B SDLK_B
288 #define KSYM_C SDLK_C
289 #define KSYM_D SDLK_D
290 #define KSYM_E SDLK_E
291 #define KSYM_F SDLK_F
292 #define KSYM_G SDLK_G
293 #define KSYM_H SDLK_H
294 #define KSYM_I SDLK_I
295 #define KSYM_J SDLK_J
296 #define KSYM_K SDLK_K
297 #define KSYM_L SDLK_L
298 #define KSYM_M SDLK_M
299 #define KSYM_N SDLK_N
300 #define KSYM_O SDLK_O
301 #define KSYM_P SDLK_P
302 #define KSYM_Q SDLK_Q
303 #define KSYM_R SDLK_R
304 #define KSYM_S SDLK_S
305 #define KSYM_T SDLK_T
306 #define KSYM_U SDLK_U
307 #define KSYM_V SDLK_V
308 #define KSYM_W SDLK_W
309 #define KSYM_X SDLK_X
310 #define KSYM_Y SDLK_Y
311 #define KSYM_Z SDLK_Z
313 #define KSYM_a SDLK_a
314 #define KSYM_b SDLK_b
315 #define KSYM_c SDLK_c
316 #define KSYM_d SDLK_d
317 #define KSYM_e SDLK_e
318 #define KSYM_f SDLK_f
319 #define KSYM_g SDLK_g
320 #define KSYM_h SDLK_h
321 #define KSYM_i SDLK_i
322 #define KSYM_j SDLK_j
323 #define KSYM_k SDLK_k
324 #define KSYM_l SDLK_l
325 #define KSYM_m SDLK_m
326 #define KSYM_n SDLK_n
327 #define KSYM_o SDLK_o
328 #define KSYM_p SDLK_p
329 #define KSYM_q SDLK_q
330 #define KSYM_r SDLK_r
331 #define KSYM_s SDLK_s
332 #define KSYM_t SDLK_t
333 #define KSYM_u SDLK_u
334 #define KSYM_v SDLK_v
335 #define KSYM_w SDLK_w
336 #define KSYM_x SDLK_x
337 #define KSYM_y SDLK_y
338 #define KSYM_z SDLK_z
340 #define KSYM_0 SDLK_0
341 #define KSYM_1 SDLK_1
342 #define KSYM_2 SDLK_2
343 #define KSYM_3 SDLK_3
344 #define KSYM_4 SDLK_4
345 #define KSYM_5 SDLK_5
346 #define KSYM_6 SDLK_6
347 #define KSYM_7 SDLK_7
348 #define KSYM_8 SDLK_8
349 #define KSYM_9 SDLK_9
351 #if defined(TARGET_SDL2)
352 #define KSYM_KP_0 SDLK_KP_0
353 #define KSYM_KP_1 SDLK_KP_1
354 #define KSYM_KP_2 SDLK_KP_2
355 #define KSYM_KP_3 SDLK_KP_3
356 #define KSYM_KP_4 SDLK_KP_4
357 #define KSYM_KP_5 SDLK_KP_5
358 #define KSYM_KP_6 SDLK_KP_6
359 #define KSYM_KP_7 SDLK_KP_7
360 #define KSYM_KP_8 SDLK_KP_8
361 #define KSYM_KP_9 SDLK_KP_9
363 #define KSYM_KP_0 SDLK_KP0
364 #define KSYM_KP_1 SDLK_KP1
365 #define KSYM_KP_2 SDLK_KP2
366 #define KSYM_KP_3 SDLK_KP3
367 #define KSYM_KP_4 SDLK_KP4
368 #define KSYM_KP_5 SDLK_KP5
369 #define KSYM_KP_6 SDLK_KP6
370 #define KSYM_KP_7 SDLK_KP7
371 #define KSYM_KP_8 SDLK_KP8
372 #define KSYM_KP_9 SDLK_KP9
375 #define KSYM_F1 SDLK_F1
376 #define KSYM_F2 SDLK_F2
377 #define KSYM_F3 SDLK_F3
378 #define KSYM_F4 SDLK_F4
379 #define KSYM_F5 SDLK_F5
380 #define KSYM_F6 SDLK_F6
381 #define KSYM_F7 SDLK_F7
382 #define KSYM_F8 SDLK_F8
383 #define KSYM_F9 SDLK_F9
384 #define KSYM_F10 SDLK_F10
385 #define KSYM_F11 SDLK_F11
386 #define KSYM_F12 SDLK_F12
388 #define KSYM_FKEY_FIRST KSYM_F1
389 #define KSYM_FKEY_LAST KSYM_F12
390 #define KSYM_NUM_FKEYS (KSYM_FKEY_LAST - KSYM_FKEY_FIRST + 1)
392 #define KMOD_None KMOD_NONE
393 #define KMOD_Shift_L KMOD_LSHIFT
394 #define KMOD_Shift_R KMOD_RSHIFT
395 #define KMOD_Control_L KMOD_LCTRL
396 #define KMOD_Control_R KMOD_RCTRL
398 #if defined(TARGET_SDL2)
399 #define KMOD_Meta_L KMOD_LGUI
400 #define KMOD_Meta_R KMOD_RGUI
402 #define KMOD_Meta_L KMOD_LMETA
403 #define KMOD_Meta_R KMOD_RMETA
406 #define KMOD_Alt_L KMOD_LALT
407 #define KMOD_Alt_R KMOD_RALT
409 #define KMOD_Shift (KMOD_Shift_L | KMOD_Shift_R)
410 #define KMOD_Control (KMOD_Control_L | KMOD_Control_R)
411 #define KMOD_Meta (KMOD_Meta_L | KMOD_Meta_R)
412 #define KMOD_Alt (KMOD_Alt_L | KMOD_Alt_R)
415 /* SDL function definitions */
417 #if defined(TARGET_SDL2)
418 SDL_Surface *SDL_DisplayFormat(SDL_Surface *);
421 void SDLInitVideoDisplay(void);
422 void SDLInitVideoBuffer(DrawBuffer **, DrawWindow **, boolean);
423 boolean SDLSetVideoMode(DrawBuffer **, boolean);
424 void SDLCreateBitmapContent(Bitmap *, int, int, int);
425 void SDLFreeBitmapPointers(Bitmap *);
426 void SDLCopyArea(Bitmap *, Bitmap *, int, int, int, int, int, int, int);
427 void SDLFillRectangle(Bitmap *, int, int, int, int, Uint32);
428 void SDLFadeRectangle(Bitmap *, int, int, int, int, int, int, int,
429 void (*draw_border_function)(void));
430 void SDLDrawSimpleLine(Bitmap *, int, int, int, int, Uint32);
431 void SDLDrawLine(Bitmap *, int, int, int, int, Uint32);
432 Pixel SDLGetPixel(Bitmap *, int, int);
433 void SDLPutPixel(Bitmap *, int, int, Pixel);
435 void SDLInvertArea(Bitmap *, int, int, int, int, Uint32);
436 void SDLCopyInverseMasked(Bitmap *, Bitmap *, int, int, int, int, int, int);
438 void SDLZoomBitmap(Bitmap *, Bitmap *);
440 Bitmap *SDLLoadImage(char *);
442 void SDLSetMouseCursor(struct MouseCursorInfo *);
444 void SDLOpenAudio(void);
445 void SDLCloseAudio(void);
447 void SDLNextEvent(Event *);
448 void SDLHandleWindowManagerEvent(Event *);
450 void HandleJoystickEvent(Event *);
451 void SDLInitJoysticks(void);
452 boolean SDLReadJoystick(int, int *, int *, boolean *, boolean *);