2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2010 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "SDL_config.h"
24 /* Initialization code for SDL */
27 #include "SDL_fatal.h"
28 #include "SDL_assert.h"
30 #if !SDL_VIDEO_DISABLED
31 #include "video/SDL_leaks.h"
34 /* Initialization/Cleanup routines */
35 #if !SDL_JOYSTICK_DISABLED
36 extern int SDL_JoystickInit(void);
37 extern void SDL_JoystickQuit(void);
39 #if !SDL_HAPTIC_DISABLED
40 extern int SDL_HapticInit(void);
41 extern int SDL_HapticQuit(void);
43 #if !SDL_TIMERS_DISABLED
44 extern void SDL_StartTicks(void);
45 extern int SDL_TimerInit(void);
46 extern void SDL_TimerQuit(void);
48 #if defined(__WIN32__)
49 extern int SDL_HelperWindowCreate(void);
50 extern int SDL_HelperWindowDestroy(void);
53 extern int SDL_AssertionsInit(void);
54 extern void SDL_AssertionsQuit(void);
56 /* The initialized subsystems */
57 static Uint32 SDL_initialized = 0;
58 static Uint32 ticks_started = 0;
61 int surfaces_allocated = 0;
65 SDL_InitSubSystem(Uint32 flags)
67 #if !SDL_VIDEO_DISABLED
68 /* Initialize the video/event subsystem */
69 if ((flags & SDL_INIT_VIDEO) && !(SDL_initialized & SDL_INIT_VIDEO)) {
70 if (SDL_VideoInit(NULL, (flags & SDL_INIT_EVENTTHREAD)) < 0) {
73 SDL_initialized |= SDL_INIT_VIDEO;
76 if (flags & SDL_INIT_VIDEO) {
77 SDL_SetError("SDL not built with video support");
82 #if !SDL_AUDIO_DISABLED
83 /* Initialize the audio subsystem */
84 if ((flags & SDL_INIT_AUDIO) && !(SDL_initialized & SDL_INIT_AUDIO)) {
85 if (SDL_AudioInit(NULL) < 0) {
88 SDL_initialized |= SDL_INIT_AUDIO;
91 if (flags & SDL_INIT_AUDIO) {
92 SDL_SetError("SDL not built with audio support");
97 #if !SDL_TIMERS_DISABLED
98 /* Initialize the timer subsystem */
103 if ((flags & SDL_INIT_TIMER) && !(SDL_initialized & SDL_INIT_TIMER)) {
104 if (SDL_TimerInit() < 0) {
107 SDL_initialized |= SDL_INIT_TIMER;
110 if (flags & SDL_INIT_TIMER) {
111 SDL_SetError("SDL not built with timer support");
116 #if !SDL_JOYSTICK_DISABLED
117 /* Initialize the joystick subsystem */
118 if ((flags & SDL_INIT_JOYSTICK) && !(SDL_initialized & SDL_INIT_JOYSTICK)) {
119 if (SDL_JoystickInit() < 0) {
122 SDL_initialized |= SDL_INIT_JOYSTICK;
125 if (flags & SDL_INIT_JOYSTICK) {
126 SDL_SetError("SDL not built with joystick support");
131 #if !SDL_HAPTIC_DISABLED
132 /* Initialize the haptic subsystem */
133 if ((flags & SDL_INIT_HAPTIC) && !(SDL_initialized & SDL_INIT_HAPTIC)) {
134 if (SDL_HapticInit() < 0) {
137 SDL_initialized |= SDL_INIT_HAPTIC;
140 if (flags & SDL_INIT_HAPTIC) {
141 SDL_SetError("SDL not built with haptic (force feedback) support");
149 SDL_Init(Uint32 flags)
151 if (SDL_AssertionsInit() < 0) {
155 /* Clear the error message */
158 #if defined(__WIN32__)
159 if (SDL_HelperWindowCreate() < 0) {
164 /* Initialize the desired subsystems */
165 if (SDL_InitSubSystem(flags) < 0) {
169 /* Everything is initialized */
170 if (!(flags & SDL_INIT_NOPARACHUTE)) {
171 SDL_InstallParachute();
178 SDL_QuitSubSystem(Uint32 flags)
180 /* Shut down requested initialized subsystems */
181 #if !SDL_JOYSTICK_DISABLED
182 if ((flags & SDL_initialized & SDL_INIT_JOYSTICK)) {
184 SDL_initialized &= ~SDL_INIT_JOYSTICK;
187 #if !SDL_HAPTIC_DISABLED
188 if ((flags & SDL_initialized & SDL_INIT_HAPTIC)) {
190 SDL_initialized &= ~SDL_INIT_HAPTIC;
193 #if !SDL_TIMERS_DISABLED
194 if ((flags & SDL_initialized & SDL_INIT_TIMER)) {
196 SDL_initialized &= ~SDL_INIT_TIMER;
199 #if !SDL_AUDIO_DISABLED
200 if ((flags & SDL_initialized & SDL_INIT_AUDIO)) {
202 SDL_initialized &= ~SDL_INIT_AUDIO;
205 #if !SDL_VIDEO_DISABLED
206 if ((flags & SDL_initialized & SDL_INIT_VIDEO)) {
208 SDL_initialized &= ~SDL_INIT_VIDEO;
214 SDL_WasInit(Uint32 flags)
217 flags = SDL_INIT_EVERYTHING;
219 return (SDL_initialized & flags);
225 /* Quit all subsystems */
227 printf("[SDL_Quit] : Enter! Calling QuitSubSystem()\n");
231 #if defined(__WIN32__)
232 SDL_HelperWindowDestroy();
234 SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
238 printf("[SDL_Quit] : CHECK_LEAKS\n");
242 /* !!! FIXME: make this an assertion. */
243 /* Print the number of surfaces not freed */
244 if (surfaces_allocated != 0) {
245 fprintf(stderr, "SDL Warning: %d SDL surfaces extant\n",
250 printf("[SDL_Quit] : SDL_UninstallParachute()\n");
254 /* Uninstall any parachute signal handlers */
255 SDL_UninstallParachute();
257 SDL_AssertionsQuit();
260 printf("[SDL_Quit] : Returning!\n");
266 /* Get the library version number */
268 SDL_GetVersion(SDL_version * ver)
273 /* Get the library source revision */
275 SDL_GetRevision(void)
280 /* Get the name of the platform */
287 /* Haiku must appear here before BeOS, since it also defines __BEOS__ */
306 return "MacOS Classic";
318 return "QNX Neutrino";
332 return "Unknown (see SDL_platform.h)";
336 #if defined(__WIN32__)
338 #if !defined(HAVE_LIBC) || (defined(__WATCOMC__) && defined(BUILD_DLL))
339 /* Need to include DllMain() on Watcom C for some reason.. */
340 #define WIN32_LEAN_AND_MEAN
344 _DllMainCRTStartup(HANDLE hModule,
345 DWORD ul_reason_for_call, LPVOID lpReserved)
347 switch (ul_reason_for_call) {
348 case DLL_PROCESS_ATTACH:
349 case DLL_THREAD_ATTACH:
350 case DLL_THREAD_DETACH:
351 case DLL_PROCESS_DETACH:
356 #endif /* building DLL with Watcom C */
358 #endif /* __WIN32__ */
360 /* vi: set ts=4 sw=4 expandtab: */