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 #if defined(PLATFORM_ANDROID)
51 #define WINDOW_SCALING_STATUS WINDOW_SCALING_NOT_AVAILABLE
52 #define FULLSCREEN_STATUS FULLSCREEN_AVAILABLE
53 #define USE_DESKTOP_FULLSCREEN TRUE
54 #elif defined(TARGET_SDL2)
55 #define WINDOW_SCALING_STATUS WINDOW_SCALING_AVAILABLE
56 #define FULLSCREEN_STATUS FULLSCREEN_AVAILABLE
57 #define USE_DESKTOP_FULLSCREEN TRUE
59 #define WINDOW_SCALING_STATUS WINDOW_SCALING_NOT_AVAILABLE
60 #define FULLSCREEN_STATUS FULLSCREEN_AVAILABLE
63 #define CURSOR_MAX_WIDTH 32
64 #define CURSOR_MAX_HEIGHT 32
67 /* SDL type definitions */
69 typedef struct SDLSurfaceInfo Bitmap;
70 typedef struct SDLSurfaceInfo DrawBuffer;
71 typedef struct SDLSurfaceInfo DrawWindow;
73 typedef SDL_Cursor *Cursor;
75 #if defined(TARGET_SDL2)
76 typedef SDL_Keycode Key;
77 typedef SDL_Keymod KeyMod;
80 typedef unsigned int KeyMod;
83 typedef SDL_Event Event;
84 typedef SDL_MouseButtonEvent ButtonEvent;
85 typedef SDL_MouseMotionEvent MotionEvent;
86 #if defined(TARGET_SDL2)
87 typedef SDL_TouchFingerEvent FingerEvent;
88 typedef SDL_TextInputEvent TextEvent;
89 typedef SDL_WindowEvent WindowEvent;
91 typedef SDL_KeyboardEvent KeyEvent;
92 typedef SDL_Event ExposeEvent;
93 typedef SDL_Event FocusChangeEvent;
94 typedef SDL_Event ClientMessageEvent;
100 typedef int Colormap;
103 /* structure definitions */
105 struct SDLSurfaceInfo
107 char *source_filename;
110 SDL_Surface *surface;
111 SDL_Surface *surface_masked;
116 struct MouseCursorInfo
121 byte data[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8];
122 byte mask[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8];
126 /* SDL symbol definitions */
130 #define BLACK_PIXEL 0x000000
131 #define WHITE_PIXEL 0xffffff
133 #define EVENT_BUTTONPRESS SDL_MOUSEBUTTONDOWN
134 #define EVENT_BUTTONRELEASE SDL_MOUSEBUTTONUP
135 #define EVENT_MOTIONNOTIFY SDL_MOUSEMOTION
136 #if defined(TARGET_SDL2)
137 #define EVENT_FINGERPRESS SDL_FINGERDOWN
138 #define EVENT_FINGERRELEASE SDL_FINGERUP
139 #define EVENT_FINGERMOTION SDL_FINGERMOTION
140 #define EVENT_TEXTINPUT SDL_TEXTINPUT
142 #define EVENT_KEYPRESS SDL_KEYDOWN
143 #define EVENT_KEYRELEASE SDL_KEYUP
144 #define EVENT_EXPOSE SDL_USEREVENT + 0
145 #define EVENT_FOCUSIN SDL_USEREVENT + 1
146 #define EVENT_FOCUSOUT SDL_USEREVENT + 2
147 #define EVENT_CLIENTMESSAGE SDL_QUIT
148 #define EVENT_MAPNOTIFY SDL_USEREVENT + 4
149 #define EVENT_UNMAPNOTIFY SDL_USEREVENT + 5
151 #define KSYM_UNDEFINED SDLK_UNKNOWN
153 #define KSYM_Return SDLK_RETURN
154 #define KSYM_Escape SDLK_ESCAPE
156 #define KSYM_Left SDLK_LEFT
157 #define KSYM_Right SDLK_RIGHT
158 #define KSYM_Up SDLK_UP
159 #define KSYM_Down SDLK_DOWN
162 #define KSYM_KP_Left SDLK_KP_LEFT
163 #define KSYM_KP_Right SDLK_KP_RIGHT
164 #define KSYM_KP_Up SDLK_KP_UP
165 #define KSYM_KP_Down SDLK_KP_DOWN
168 #define KSYM_KP_Enter SDLK_KP_ENTER
169 #define KSYM_KP_Add SDLK_KP_PLUS
170 #define KSYM_KP_Subtract SDLK_KP_MINUS
171 #define KSYM_KP_Multiply SDLK_KP_MULTIPLY
172 #define KSYM_KP_Divide SDLK_KP_DIVIDE
173 #define KSYM_KP_Separator SDLK_KP_PERIOD
175 #define KSYM_Shift_L SDLK_LSHIFT
176 #define KSYM_Shift_R SDLK_RSHIFT
177 #define KSYM_Control_L SDLK_LCTRL
178 #define KSYM_Control_R SDLK_RCTRL
180 #if defined(TARGET_SDL2)
181 #define KSYM_Meta_L SDLK_LGUI
182 #define KSYM_Meta_R SDLK_RGUI
184 #define KSYM_Meta_L SDLK_LMETA
185 #define KSYM_Meta_R SDLK_RMETA
188 #define KSYM_Alt_L SDLK_LALT
189 #define KSYM_Alt_R SDLK_RALT
190 #if !defined(TARGET_SDL2)
191 #define KSYM_Super_L SDLK_LSUPER
192 #define KSYM_Super_R SDLK_RSUPER
194 #define KSYM_Mode_switch SDLK_MODE
195 #define KSYM_Multi_key SDLK_RCTRL
197 #define KSYM_BackSpace SDLK_BACKSPACE
198 #define KSYM_Delete SDLK_DELETE
199 #define KSYM_Insert SDLK_INSERT
200 #define KSYM_Tab SDLK_TAB
201 #define KSYM_Home SDLK_HOME
202 #define KSYM_End SDLK_END
203 #define KSYM_Page_Up SDLK_PAGEUP
204 #define KSYM_Page_Down SDLK_PAGEDOWN
206 #if defined(TARGET_SDL2)
207 #define KSYM_Menu SDLK_MENU
208 #define KSYM_Back SDLK_AC_BACK
211 #define KSYM_space SDLK_SPACE
212 #define KSYM_exclam SDLK_EXCLAIM
213 #define KSYM_quotedbl SDLK_QUOTEDBL
214 #define KSYM_numbersign SDLK_HASH
215 #define KSYM_dollar SDLK_DOLLAR
217 #if defined(TARGET_SDL2)
218 #define KSYM_percent SDLK_PERCENT
220 #define KSYM_percent 37 /* undefined in SDL */
223 #define KSYM_ampersand SDLK_AMPERSAND
224 #define KSYM_apostrophe SDLK_QUOTE
225 #define KSYM_parenleft SDLK_LEFTPAREN
226 #define KSYM_parenright SDLK_RIGHTPAREN
227 #define KSYM_asterisk SDLK_ASTERISK
228 #define KSYM_plus SDLK_PLUS
229 #define KSYM_comma SDLK_COMMA
230 #define KSYM_minus SDLK_MINUS
231 #define KSYM_period SDLK_PERIOD
232 #define KSYM_slash SDLK_SLASH
234 #define KSYM_colon SDLK_COLON
235 #define KSYM_semicolon SDLK_SEMICOLON
236 #define KSYM_less SDLK_LESS
237 #define KSYM_equal SDLK_EQUALS
238 #define KSYM_greater SDLK_GREATER
239 #define KSYM_question SDLK_QUESTION
240 #define KSYM_at SDLK_AT
242 #define KSYM_bracketleft SDLK_LEFTBRACKET
243 #define KSYM_backslash SDLK_BACKSLASH
244 #define KSYM_bracketright SDLK_RIGHTBRACKET
245 #define KSYM_asciicircum SDLK_CARET
246 #define KSYM_underscore SDLK_UNDERSCORE
247 #define KSYM_grave SDLK_BACKQUOTE
249 #define KSYM_quoteleft KSYM_UNDEFINED /* undefined */
250 #define KSYM_braceleft KSYM_UNDEFINED /* undefined */
251 #define KSYM_bar KSYM_UNDEFINED /* undefined */
252 #define KSYM_braceright KSYM_UNDEFINED /* undefined */
253 #define KSYM_asciitilde KSYM_UNDEFINED /* undefined */
255 #if defined(TARGET_SDL2)
256 #define KSYM_degree 176
257 #define KSYM_Adiaeresis 196
258 #define KSYM_Odiaeresis 214
259 #define KSYM_Udiaeresis 220
260 #define KSYM_adiaeresis 228
261 #define KSYM_odiaeresis 246
262 #define KSYM_udiaeresis 252
263 #define KSYM_ssharp 223
265 #define KSYM_degree SDLK_WORLD_16
266 #define KSYM_Adiaeresis SDLK_WORLD_36
267 #define KSYM_Odiaeresis SDLK_WORLD_54
268 #define KSYM_Udiaeresis SDLK_WORLD_60
269 #define KSYM_adiaeresis SDLK_WORLD_68
270 #define KSYM_odiaeresis SDLK_WORLD_86
271 #define KSYM_udiaeresis SDLK_WORLD_92
272 #define KSYM_ssharp SDLK_WORLD_63
304 #define KSYM_A SDLK_A
305 #define KSYM_B SDLK_B
306 #define KSYM_C SDLK_C
307 #define KSYM_D SDLK_D
308 #define KSYM_E SDLK_E
309 #define KSYM_F SDLK_F
310 #define KSYM_G SDLK_G
311 #define KSYM_H SDLK_H
312 #define KSYM_I SDLK_I
313 #define KSYM_J SDLK_J
314 #define KSYM_K SDLK_K
315 #define KSYM_L SDLK_L
316 #define KSYM_M SDLK_M
317 #define KSYM_N SDLK_N
318 #define KSYM_O SDLK_O
319 #define KSYM_P SDLK_P
320 #define KSYM_Q SDLK_Q
321 #define KSYM_R SDLK_R
322 #define KSYM_S SDLK_S
323 #define KSYM_T SDLK_T
324 #define KSYM_U SDLK_U
325 #define KSYM_V SDLK_V
326 #define KSYM_W SDLK_W
327 #define KSYM_X SDLK_X
328 #define KSYM_Y SDLK_Y
329 #define KSYM_Z SDLK_Z
331 #define KSYM_a SDLK_a
332 #define KSYM_b SDLK_b
333 #define KSYM_c SDLK_c
334 #define KSYM_d SDLK_d
335 #define KSYM_e SDLK_e
336 #define KSYM_f SDLK_f
337 #define KSYM_g SDLK_g
338 #define KSYM_h SDLK_h
339 #define KSYM_i SDLK_i
340 #define KSYM_j SDLK_j
341 #define KSYM_k SDLK_k
342 #define KSYM_l SDLK_l
343 #define KSYM_m SDLK_m
344 #define KSYM_n SDLK_n
345 #define KSYM_o SDLK_o
346 #define KSYM_p SDLK_p
347 #define KSYM_q SDLK_q
348 #define KSYM_r SDLK_r
349 #define KSYM_s SDLK_s
350 #define KSYM_t SDLK_t
351 #define KSYM_u SDLK_u
352 #define KSYM_v SDLK_v
353 #define KSYM_w SDLK_w
354 #define KSYM_x SDLK_x
355 #define KSYM_y SDLK_y
356 #define KSYM_z SDLK_z
358 #define KSYM_0 SDLK_0
359 #define KSYM_1 SDLK_1
360 #define KSYM_2 SDLK_2
361 #define KSYM_3 SDLK_3
362 #define KSYM_4 SDLK_4
363 #define KSYM_5 SDLK_5
364 #define KSYM_6 SDLK_6
365 #define KSYM_7 SDLK_7
366 #define KSYM_8 SDLK_8
367 #define KSYM_9 SDLK_9
369 #if defined(TARGET_SDL2)
370 #define KSYM_KP_0 SDLK_KP_0
371 #define KSYM_KP_1 SDLK_KP_1
372 #define KSYM_KP_2 SDLK_KP_2
373 #define KSYM_KP_3 SDLK_KP_3
374 #define KSYM_KP_4 SDLK_KP_4
375 #define KSYM_KP_5 SDLK_KP_5
376 #define KSYM_KP_6 SDLK_KP_6
377 #define KSYM_KP_7 SDLK_KP_7
378 #define KSYM_KP_8 SDLK_KP_8
379 #define KSYM_KP_9 SDLK_KP_9
381 #define KSYM_KP_0 SDLK_KP0
382 #define KSYM_KP_1 SDLK_KP1
383 #define KSYM_KP_2 SDLK_KP2
384 #define KSYM_KP_3 SDLK_KP3
385 #define KSYM_KP_4 SDLK_KP4
386 #define KSYM_KP_5 SDLK_KP5
387 #define KSYM_KP_6 SDLK_KP6
388 #define KSYM_KP_7 SDLK_KP7
389 #define KSYM_KP_8 SDLK_KP8
390 #define KSYM_KP_9 SDLK_KP9
393 #define KSYM_F1 SDLK_F1
394 #define KSYM_F2 SDLK_F2
395 #define KSYM_F3 SDLK_F3
396 #define KSYM_F4 SDLK_F4
397 #define KSYM_F5 SDLK_F5
398 #define KSYM_F6 SDLK_F6
399 #define KSYM_F7 SDLK_F7
400 #define KSYM_F8 SDLK_F8
401 #define KSYM_F9 SDLK_F9
402 #define KSYM_F10 SDLK_F10
403 #define KSYM_F11 SDLK_F11
404 #define KSYM_F12 SDLK_F12
406 #define KSYM_FKEY_FIRST KSYM_F1
407 #define KSYM_FKEY_LAST KSYM_F12
408 #define KSYM_NUM_FKEYS (KSYM_FKEY_LAST - KSYM_FKEY_FIRST + 1)
410 #define KMOD_None KMOD_NONE
411 #define KMOD_Shift_L KMOD_LSHIFT
412 #define KMOD_Shift_R KMOD_RSHIFT
413 #define KMOD_Control_L KMOD_LCTRL
414 #define KMOD_Control_R KMOD_RCTRL
416 #if defined(TARGET_SDL2)
417 #define KMOD_Meta_L KMOD_LGUI
418 #define KMOD_Meta_R KMOD_RGUI
420 #define KMOD_Meta_L KMOD_LMETA
421 #define KMOD_Meta_R KMOD_RMETA
424 #define KMOD_Alt_L KMOD_LALT
425 #define KMOD_Alt_R KMOD_RALT
427 #define KMOD_Shift (KMOD_Shift_L | KMOD_Shift_R)
428 #define KMOD_Control (KMOD_Control_L | KMOD_Control_R)
429 #define KMOD_Meta (KMOD_Meta_L | KMOD_Meta_R)
430 #define KMOD_Alt (KMOD_Alt_L | KMOD_Alt_R)
432 #if defined(TARGET_SDL2)
433 #define KMOD_TextInput (KMOD_Shift | KMOD_Alt_R)
436 /* SDL function definitions */
438 #if defined(TARGET_SDL2)
439 SDL_Surface *SDL_DisplayFormat(SDL_Surface *);
440 void SDLSetWindowTitle(void);
441 void SDLSetWindowScaling(int);
442 void SDLSetWindowScalingQuality(char *);
443 void SDLSetWindowFullscreen(boolean);
444 void SDLRedrawWindow();
447 void SDLLimitScreenUpdates(boolean);
448 void SDLInitVideoDisplay(void);
449 void SDLInitVideoBuffer(DrawBuffer **, DrawWindow **, boolean);
450 boolean SDLSetVideoMode(DrawBuffer **, boolean);
451 void SDLCreateBitmapContent(Bitmap *, int, int, int);
452 void SDLFreeBitmapPointers(Bitmap *);
453 void SDLCopyArea(Bitmap *, Bitmap *, int, int, int, int, int, int, int);
454 void SDLFillRectangle(Bitmap *, int, int, int, int, Uint32);
455 void SDLFadeRectangle(Bitmap *, int, int, int, int, int, int, int,
456 void (*draw_border_function)(void));
457 void SDLDrawSimpleLine(Bitmap *, int, int, int, int, Uint32);
458 void SDLDrawLine(Bitmap *, int, int, int, int, Uint32);
459 Pixel SDLGetPixel(Bitmap *, int, int);
460 void SDLPutPixel(Bitmap *, int, int, Pixel);
462 void SDLInvertArea(Bitmap *, int, int, int, int, Uint32);
463 void SDLCopyInverseMasked(Bitmap *, Bitmap *, int, int, int, int, int, int);
465 void SDLZoomBitmap(Bitmap *, Bitmap *);
467 Bitmap *SDLLoadImage(char *);
469 void SDLSetMouseCursor(struct MouseCursorInfo *);
471 void SDLOpenAudio(void);
472 void SDLCloseAudio(void);
474 void SDLNextEvent(Event *);
475 void SDLHandleWindowManagerEvent(Event *);
477 void HandleJoystickEvent(Event *);
478 void SDLInitJoysticks(void);
479 boolean SDLReadJoystick(int, int *, int *, boolean *, boolean *);