1 // ============================================================================
2 // Artsoft Retro-Game Library
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // http://www.artsoft.org/
8 // ----------------------------------------------------------------------------
10 // ============================================================================
16 #include <SDL_image.h>
17 #include <SDL_mixer.h>
19 #include <SDL_thread.h>
20 #if defined(PLATFORM_WIN32)
21 #include <SDL_syswm.h>
24 /* definitions needed for "system.c" */
26 #if defined(TARGET_SDL2)
27 #define SURFACE_FLAGS (0)
29 #define SURFACE_FLAGS (SDL_SWSURFACE)
32 #if defined(TARGET_SDL2)
33 #define SET_TRANSPARENT_PIXEL (SDL_TRUE)
34 #define UNSET_TRANSPARENT_PIXEL (SDL_FALSE)
36 #define SET_TRANSPARENT_PIXEL (SDL_SRCCOLORKEY)
37 #define UNSET_TRANSPARENT_PIXEL (0)
40 /* system dependent definitions */
42 #if defined(TARGET_SDL2)
43 #define TARGET_STRING "SDL2"
45 #define TARGET_STRING "SDL"
48 #if defined(PLATFORM_ANDROID)
49 #define WINDOW_SCALING_STATUS WINDOW_SCALING_NOT_AVAILABLE
50 #define FULLSCREEN_STATUS FULLSCREEN_AVAILABLE
51 #define USE_DESKTOP_FULLSCREEN TRUE
52 #elif defined(TARGET_SDL2)
53 #define WINDOW_SCALING_STATUS WINDOW_SCALING_AVAILABLE
54 #define FULLSCREEN_STATUS FULLSCREEN_AVAILABLE
55 #define USE_DESKTOP_FULLSCREEN TRUE
57 #define WINDOW_SCALING_STATUS WINDOW_SCALING_NOT_AVAILABLE
58 #define FULLSCREEN_STATUS FULLSCREEN_AVAILABLE
61 #define CURSOR_MAX_WIDTH 32
62 #define CURSOR_MAX_HEIGHT 32
65 /* SDL type definitions */
67 typedef struct SDLSurfaceInfo Bitmap;
68 typedef struct SDLSurfaceInfo DrawBuffer;
69 typedef struct SDLSurfaceInfo DrawWindow;
71 typedef SDL_Cursor *Cursor;
73 #if defined(TARGET_SDL2)
74 typedef SDL_Keycode Key;
75 typedef SDL_Keymod KeyMod;
78 typedef unsigned int KeyMod;
81 typedef SDL_Event Event;
82 typedef SDL_MouseButtonEvent ButtonEvent;
83 typedef SDL_MouseMotionEvent MotionEvent;
84 #if defined(TARGET_SDL2)
85 typedef SDL_TouchFingerEvent FingerEvent;
86 typedef SDL_TextInputEvent TextEvent;
87 typedef SDL_Event PauseResumeEvent;
88 typedef SDL_WindowEvent WindowEvent;
90 typedef SDL_KeyboardEvent KeyEvent;
91 typedef SDL_Event ExposeEvent;
92 typedef SDL_Event FocusChangeEvent;
93 typedef SDL_Event ClientMessageEvent;
102 /* structure definitions */
104 struct SDLSurfaceInfo
106 char *source_filename;
109 SDL_Surface *surface;
110 SDL_Surface *surface_masked;
115 struct MouseCursorInfo
120 byte data[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8];
121 byte mask[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8];
125 /* SDL symbol definitions */
129 #define BLACK_PIXEL 0x000000
130 #define WHITE_PIXEL 0xffffff
132 #define EVENT_BUTTONPRESS SDL_MOUSEBUTTONDOWN
133 #define EVENT_BUTTONRELEASE SDL_MOUSEBUTTONUP
134 #define EVENT_MOTIONNOTIFY SDL_MOUSEMOTION
135 #if defined(TARGET_SDL2)
136 #define EVENT_FINGERPRESS SDL_FINGERDOWN
137 #define EVENT_FINGERRELEASE SDL_FINGERUP
138 #define EVENT_FINGERMOTION SDL_FINGERMOTION
139 #define EVENT_TEXTINPUT SDL_TEXTINPUT
141 #define EVENT_KEYPRESS SDL_KEYDOWN
142 #define EVENT_KEYRELEASE SDL_KEYUP
143 #define EVENT_EXPOSE SDL_USEREVENT + 0
144 #define EVENT_FOCUSIN SDL_USEREVENT + 1
145 #define EVENT_FOCUSOUT SDL_USEREVENT + 2
146 #define EVENT_CLIENTMESSAGE SDL_QUIT
147 #define EVENT_MAPNOTIFY SDL_USEREVENT + 4
148 #define EVENT_UNMAPNOTIFY SDL_USEREVENT + 5
150 #define KSYM_UNDEFINED SDLK_UNKNOWN
152 #define KSYM_Return SDLK_RETURN
153 #define KSYM_Escape SDLK_ESCAPE
155 #define KSYM_Left SDLK_LEFT
156 #define KSYM_Right SDLK_RIGHT
157 #define KSYM_Up SDLK_UP
158 #define KSYM_Down SDLK_DOWN
161 #define KSYM_KP_Left SDLK_KP_LEFT
162 #define KSYM_KP_Right SDLK_KP_RIGHT
163 #define KSYM_KP_Up SDLK_KP_UP
164 #define KSYM_KP_Down SDLK_KP_DOWN
167 #define KSYM_KP_Enter SDLK_KP_ENTER
168 #define KSYM_KP_Add SDLK_KP_PLUS
169 #define KSYM_KP_Subtract SDLK_KP_MINUS
170 #define KSYM_KP_Multiply SDLK_KP_MULTIPLY
171 #define KSYM_KP_Divide SDLK_KP_DIVIDE
172 #define KSYM_KP_Separator SDLK_KP_PERIOD
174 #define KSYM_Shift_L SDLK_LSHIFT
175 #define KSYM_Shift_R SDLK_RSHIFT
176 #define KSYM_Control_L SDLK_LCTRL
177 #define KSYM_Control_R SDLK_RCTRL
179 #if defined(TARGET_SDL2)
180 #define KSYM_Meta_L SDLK_LGUI
181 #define KSYM_Meta_R SDLK_RGUI
183 #define KSYM_Meta_L SDLK_LMETA
184 #define KSYM_Meta_R SDLK_RMETA
187 #define KSYM_Alt_L SDLK_LALT
188 #define KSYM_Alt_R SDLK_RALT
189 #if !defined(TARGET_SDL2)
190 #define KSYM_Super_L SDLK_LSUPER
191 #define KSYM_Super_R SDLK_RSUPER
193 #define KSYM_Mode_switch SDLK_MODE
194 #define KSYM_Multi_key SDLK_RCTRL
196 #define KSYM_BackSpace SDLK_BACKSPACE
197 #define KSYM_Delete SDLK_DELETE
198 #define KSYM_Insert SDLK_INSERT
199 #define KSYM_Tab SDLK_TAB
200 #define KSYM_Home SDLK_HOME
201 #define KSYM_End SDLK_END
202 #define KSYM_Page_Up SDLK_PAGEUP
203 #define KSYM_Page_Down SDLK_PAGEDOWN
205 #if defined(TARGET_SDL2)
206 #define KSYM_Menu SDLK_MENU
207 #define KSYM_Back SDLK_AC_BACK
210 #define KSYM_space SDLK_SPACE
211 #define KSYM_exclam SDLK_EXCLAIM
212 #define KSYM_quotedbl SDLK_QUOTEDBL
213 #define KSYM_numbersign SDLK_HASH
214 #define KSYM_dollar SDLK_DOLLAR
216 #if defined(TARGET_SDL2)
217 #define KSYM_percent SDLK_PERCENT
219 #define KSYM_percent 37 /* undefined in SDL */
222 #define KSYM_ampersand SDLK_AMPERSAND
223 #define KSYM_apostrophe SDLK_QUOTE
224 #define KSYM_parenleft SDLK_LEFTPAREN
225 #define KSYM_parenright SDLK_RIGHTPAREN
226 #define KSYM_asterisk SDLK_ASTERISK
227 #define KSYM_plus SDLK_PLUS
228 #define KSYM_comma SDLK_COMMA
229 #define KSYM_minus SDLK_MINUS
230 #define KSYM_period SDLK_PERIOD
231 #define KSYM_slash SDLK_SLASH
233 #define KSYM_colon SDLK_COLON
234 #define KSYM_semicolon SDLK_SEMICOLON
235 #define KSYM_less SDLK_LESS
236 #define KSYM_equal SDLK_EQUALS
237 #define KSYM_greater SDLK_GREATER
238 #define KSYM_question SDLK_QUESTION
239 #define KSYM_at SDLK_AT
241 #define KSYM_bracketleft SDLK_LEFTBRACKET
242 #define KSYM_backslash SDLK_BACKSLASH
243 #define KSYM_bracketright SDLK_RIGHTBRACKET
244 #define KSYM_asciicircum SDLK_CARET
245 #define KSYM_underscore SDLK_UNDERSCORE
246 #define KSYM_grave SDLK_BACKQUOTE
248 #define KSYM_quoteleft KSYM_UNDEFINED /* undefined */
249 #define KSYM_braceleft KSYM_UNDEFINED /* undefined */
250 #define KSYM_bar KSYM_UNDEFINED /* undefined */
251 #define KSYM_braceright KSYM_UNDEFINED /* undefined */
252 #define KSYM_asciitilde KSYM_UNDEFINED /* undefined */
254 #if defined(TARGET_SDL2)
255 #define KSYM_degree 176
256 #define KSYM_Adiaeresis 196
257 #define KSYM_Odiaeresis 214
258 #define KSYM_Udiaeresis 220
259 #define KSYM_adiaeresis 228
260 #define KSYM_odiaeresis 246
261 #define KSYM_udiaeresis 252
262 #define KSYM_ssharp 223
264 #define KSYM_degree SDLK_WORLD_16
265 #define KSYM_Adiaeresis SDLK_WORLD_36
266 #define KSYM_Odiaeresis SDLK_WORLD_54
267 #define KSYM_Udiaeresis SDLK_WORLD_60
268 #define KSYM_adiaeresis SDLK_WORLD_68
269 #define KSYM_odiaeresis SDLK_WORLD_86
270 #define KSYM_udiaeresis SDLK_WORLD_92
271 #define KSYM_ssharp SDLK_WORLD_63
303 #define KSYM_A SDLK_A
304 #define KSYM_B SDLK_B
305 #define KSYM_C SDLK_C
306 #define KSYM_D SDLK_D
307 #define KSYM_E SDLK_E
308 #define KSYM_F SDLK_F
309 #define KSYM_G SDLK_G
310 #define KSYM_H SDLK_H
311 #define KSYM_I SDLK_I
312 #define KSYM_J SDLK_J
313 #define KSYM_K SDLK_K
314 #define KSYM_L SDLK_L
315 #define KSYM_M SDLK_M
316 #define KSYM_N SDLK_N
317 #define KSYM_O SDLK_O
318 #define KSYM_P SDLK_P
319 #define KSYM_Q SDLK_Q
320 #define KSYM_R SDLK_R
321 #define KSYM_S SDLK_S
322 #define KSYM_T SDLK_T
323 #define KSYM_U SDLK_U
324 #define KSYM_V SDLK_V
325 #define KSYM_W SDLK_W
326 #define KSYM_X SDLK_X
327 #define KSYM_Y SDLK_Y
328 #define KSYM_Z SDLK_Z
330 #define KSYM_a SDLK_a
331 #define KSYM_b SDLK_b
332 #define KSYM_c SDLK_c
333 #define KSYM_d SDLK_d
334 #define KSYM_e SDLK_e
335 #define KSYM_f SDLK_f
336 #define KSYM_g SDLK_g
337 #define KSYM_h SDLK_h
338 #define KSYM_i SDLK_i
339 #define KSYM_j SDLK_j
340 #define KSYM_k SDLK_k
341 #define KSYM_l SDLK_l
342 #define KSYM_m SDLK_m
343 #define KSYM_n SDLK_n
344 #define KSYM_o SDLK_o
345 #define KSYM_p SDLK_p
346 #define KSYM_q SDLK_q
347 #define KSYM_r SDLK_r
348 #define KSYM_s SDLK_s
349 #define KSYM_t SDLK_t
350 #define KSYM_u SDLK_u
351 #define KSYM_v SDLK_v
352 #define KSYM_w SDLK_w
353 #define KSYM_x SDLK_x
354 #define KSYM_y SDLK_y
355 #define KSYM_z SDLK_z
357 #define KSYM_0 SDLK_0
358 #define KSYM_1 SDLK_1
359 #define KSYM_2 SDLK_2
360 #define KSYM_3 SDLK_3
361 #define KSYM_4 SDLK_4
362 #define KSYM_5 SDLK_5
363 #define KSYM_6 SDLK_6
364 #define KSYM_7 SDLK_7
365 #define KSYM_8 SDLK_8
366 #define KSYM_9 SDLK_9
368 #if defined(TARGET_SDL2)
369 #define KSYM_KP_0 SDLK_KP_0
370 #define KSYM_KP_1 SDLK_KP_1
371 #define KSYM_KP_2 SDLK_KP_2
372 #define KSYM_KP_3 SDLK_KP_3
373 #define KSYM_KP_4 SDLK_KP_4
374 #define KSYM_KP_5 SDLK_KP_5
375 #define KSYM_KP_6 SDLK_KP_6
376 #define KSYM_KP_7 SDLK_KP_7
377 #define KSYM_KP_8 SDLK_KP_8
378 #define KSYM_KP_9 SDLK_KP_9
380 #define KSYM_KP_0 SDLK_KP0
381 #define KSYM_KP_1 SDLK_KP1
382 #define KSYM_KP_2 SDLK_KP2
383 #define KSYM_KP_3 SDLK_KP3
384 #define KSYM_KP_4 SDLK_KP4
385 #define KSYM_KP_5 SDLK_KP5
386 #define KSYM_KP_6 SDLK_KP6
387 #define KSYM_KP_7 SDLK_KP7
388 #define KSYM_KP_8 SDLK_KP8
389 #define KSYM_KP_9 SDLK_KP9
392 #define KSYM_F1 SDLK_F1
393 #define KSYM_F2 SDLK_F2
394 #define KSYM_F3 SDLK_F3
395 #define KSYM_F4 SDLK_F4
396 #define KSYM_F5 SDLK_F5
397 #define KSYM_F6 SDLK_F6
398 #define KSYM_F7 SDLK_F7
399 #define KSYM_F8 SDLK_F8
400 #define KSYM_F9 SDLK_F9
401 #define KSYM_F10 SDLK_F10
402 #define KSYM_F11 SDLK_F11
403 #define KSYM_F12 SDLK_F12
405 #define KSYM_FKEY_FIRST KSYM_F1
406 #define KSYM_FKEY_LAST KSYM_F12
407 #define KSYM_NUM_FKEYS (KSYM_FKEY_LAST - KSYM_FKEY_FIRST + 1)
409 #define KMOD_None KMOD_NONE
410 #define KMOD_Shift_L KMOD_LSHIFT
411 #define KMOD_Shift_R KMOD_RSHIFT
412 #define KMOD_Control_L KMOD_LCTRL
413 #define KMOD_Control_R KMOD_RCTRL
415 #if defined(TARGET_SDL2)
416 #define KMOD_Meta_L KMOD_LGUI
417 #define KMOD_Meta_R KMOD_RGUI
419 #define KMOD_Meta_L KMOD_LMETA
420 #define KMOD_Meta_R KMOD_RMETA
423 #define KMOD_Alt_L KMOD_LALT
424 #define KMOD_Alt_R KMOD_RALT
426 #define KMOD_Shift (KMOD_Shift_L | KMOD_Shift_R)
427 #define KMOD_Control (KMOD_Control_L | KMOD_Control_R)
428 #define KMOD_Meta (KMOD_Meta_L | KMOD_Meta_R)
429 #define KMOD_Alt (KMOD_Alt_L | KMOD_Alt_R)
431 #if defined(TARGET_SDL2)
432 #define KMOD_TextInput (KMOD_Shift | KMOD_Alt_R)
435 /* SDL function definitions */
437 boolean SDLSetNativeSurface(SDL_Surface **);
438 SDL_Surface *SDLGetNativeSurface(SDL_Surface *);
440 #if defined(TARGET_SDL2)
441 SDL_Surface *SDL_DisplayFormat(SDL_Surface *);
442 void SDLSetWindowScaling(int);
443 void SDLSetWindowScalingQuality(char *);
444 void SDLSetWindowFullscreen(boolean);
445 void SDLRedrawWindow();
448 void SDLSetWindowTitle(void);
450 void SDLLimitScreenUpdates(boolean);
451 void SDLInitVideoDisplay(void);
452 void SDLInitVideoBuffer(DrawBuffer **, DrawWindow **, boolean);
453 boolean SDLSetVideoMode(DrawBuffer **, boolean);
454 void SDLCreateBitmapContent(Bitmap *, int, int, int);
455 void SDLFreeBitmapPointers(Bitmap *);
456 void SDLCopyArea(Bitmap *, Bitmap *, int, int, int, int, int, int, int);
457 void SDLFillRectangle(Bitmap *, int, int, int, int, Uint32);
458 void SDLFadeRectangle(Bitmap *, int, int, int, int, int, int, int,
459 void (*draw_border_function)(void));
460 void SDLDrawSimpleLine(Bitmap *, int, int, int, int, Uint32);
461 void SDLDrawLine(Bitmap *, int, int, int, int, Uint32);
462 Pixel SDLGetPixel(Bitmap *, int, int);
463 void SDLPutPixel(Bitmap *, int, int, Pixel);
465 void SDLInvertArea(Bitmap *, int, int, int, int, Uint32);
466 void SDLCopyInverseMasked(Bitmap *, Bitmap *, int, int, int, int, int, int);
468 Bitmap *SDLZoomBitmap(Bitmap *, int, int);
470 Bitmap *SDLLoadImage(char *);
472 void SDLSetMouseCursor(struct MouseCursorInfo *);
474 void SDLOpenAudio(void);
475 void SDLCloseAudio(void);
477 void SDLNextEvent(Event *);
478 void SDLHandleWindowManagerEvent(Event *);
480 void HandleJoystickEvent(Event *);
481 void SDLInitJoysticks(void);
482 boolean SDLReadJoystick(int, int *, int *, boolean *, boolean *);