Mercurial > sdl-ios-xcode
annotate src/SDL.c @ 1371:e2641c13bf33
Added a reminder on where to put libSDL.so
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 18 Feb 2006 07:21:42 +0000 |
parents | 19418e4422cb |
children | d910939febfa |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
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 | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
36
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 /* Initialization code for SDL */ | |
24 | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
25 #include "SDL.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
26 #include "SDL_fatal.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
27 #if !SDL_VIDEO_DISABLED |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
28 #include "video/SDL_leaks.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
29 #endif |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
30 |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
31 #if SDL_THREAD_PTH |
557
0ce5a68278fd
Updated Atari port for new system headers (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
32 #include <pth.h> |
0ce5a68278fd
Updated Atari port for new system headers (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
33 #endif |
0 | 34 |
35 /* Initialization/Cleanup routines */ | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
36 #if !SDL_JOYSTICK_DISABLED |
0 | 37 extern int SDL_JoystickInit(void); |
38 extern void SDL_JoystickQuit(void); | |
39 #endif | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
40 #if !SDL_CDROM_DISABLED |
0 | 41 extern int SDL_CDROMInit(void); |
42 extern void SDL_CDROMQuit(void); | |
43 #endif | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
44 #if !SDL_TIMERS_DISABLED |
0 | 45 extern void SDL_StartTicks(void); |
46 extern int SDL_TimerInit(void); | |
47 extern void SDL_TimerQuit(void); | |
48 #endif | |
49 | |
50 /* The current SDL version */ | |
51 static SDL_version version = | |
52 { SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL }; | |
53 | |
54 /* The initialized subsystems */ | |
55 static Uint32 SDL_initialized = 0; | |
56 static Uint32 ticks_started = 0; | |
57 | |
58 #ifdef CHECK_LEAKS | |
59 int surfaces_allocated = 0; | |
60 #endif | |
61 | |
62 int SDL_InitSubSystem(Uint32 flags) | |
63 { | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
64 #if !SDL_VIDEO_DISABLED |
0 | 65 /* Initialize the video/event subsystem */ |
66 if ( (flags & SDL_INIT_VIDEO) && !(SDL_initialized & SDL_INIT_VIDEO) ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
67 if ( SDL_VideoInit(SDL_getenv("SDL_VIDEODRIVER"), |
0 | 68 (flags&SDL_INIT_EVENTTHREAD)) < 0 ) { |
69 return(-1); | |
70 } | |
71 SDL_initialized |= SDL_INIT_VIDEO; | |
72 } | |
73 #else | |
74 if ( flags & SDL_INIT_VIDEO ) { | |
75 SDL_SetError("SDL not built with video support"); | |
76 return(-1); | |
77 } | |
78 #endif | |
79 | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
80 #if !SDL_AUDIO_DISABLED |
0 | 81 /* Initialize the audio subsystem */ |
82 if ( (flags & SDL_INIT_AUDIO) && !(SDL_initialized & SDL_INIT_AUDIO) ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
83 if ( SDL_AudioInit(SDL_getenv("SDL_AUDIODRIVER")) < 0 ) { |
0 | 84 return(-1); |
85 } | |
86 SDL_initialized |= SDL_INIT_AUDIO; | |
87 } | |
88 #else | |
89 if ( flags & SDL_INIT_AUDIO ) { | |
90 SDL_SetError("SDL not built with audio support"); | |
91 return(-1); | |
92 } | |
93 #endif | |
94 | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
95 #if !SDL_TIMERS_DISABLED |
0 | 96 /* Initialize the timer subsystem */ |
97 if ( ! ticks_started ) { | |
98 SDL_StartTicks(); | |
99 ticks_started = 1; | |
100 } | |
101 if ( (flags & SDL_INIT_TIMER) && !(SDL_initialized & SDL_INIT_TIMER) ) { | |
102 if ( SDL_TimerInit() < 0 ) { | |
103 return(-1); | |
104 } | |
105 SDL_initialized |= SDL_INIT_TIMER; | |
106 } | |
107 #else | |
108 if ( flags & SDL_INIT_TIMER ) { | |
109 SDL_SetError("SDL not built with timer support"); | |
110 return(-1); | |
111 } | |
112 #endif | |
113 | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
114 #if !SDL_JOYSTICK_DISABLED |
0 | 115 /* Initialize the joystick subsystem */ |
116 if ( (flags & SDL_INIT_JOYSTICK) && | |
117 !(SDL_initialized & SDL_INIT_JOYSTICK) ) { | |
118 if ( SDL_JoystickInit() < 0 ) { | |
119 return(-1); | |
120 } | |
121 SDL_initialized |= SDL_INIT_JOYSTICK; | |
122 } | |
123 #else | |
124 if ( flags & SDL_INIT_JOYSTICK ) { | |
125 SDL_SetError("SDL not built with joystick support"); | |
126 return(-1); | |
127 } | |
128 #endif | |
129 | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
130 #if !SDL_CDROM_DISABLED |
0 | 131 /* Initialize the CD-ROM subsystem */ |
132 if ( (flags & SDL_INIT_CDROM) && !(SDL_initialized & SDL_INIT_CDROM) ) { | |
133 if ( SDL_CDROMInit() < 0 ) { | |
134 return(-1); | |
135 } | |
136 SDL_initialized |= SDL_INIT_CDROM; | |
137 } | |
138 #else | |
139 if ( flags & SDL_INIT_CDROM ) { | |
140 SDL_SetError("SDL not built with cdrom support"); | |
141 return(-1); | |
142 } | |
143 #endif | |
144 return(0); | |
145 } | |
146 | |
147 int SDL_Init(Uint32 flags) | |
148 { | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
149 #if !SDL_THREADS_DISABLED && SDL_THREAD_PTH |
397 | 150 if (!pth_init()) { |
151 return -1; | |
152 } | |
153 #endif | |
154 | |
0 | 155 /* Clear the error message */ |
156 SDL_ClearError(); | |
157 | |
158 /* Initialize the desired subsystems */ | |
159 if ( SDL_InitSubSystem(flags) < 0 ) { | |
160 return(-1); | |
161 } | |
162 | |
163 /* Everything is initialized */ | |
164 if ( !(flags & SDL_INIT_NOPARACHUTE) ) { | |
165 SDL_InstallParachute(); | |
166 } | |
167 return(0); | |
168 } | |
169 | |
170 void SDL_QuitSubSystem(Uint32 flags) | |
171 { | |
172 /* Shut down requested initialized subsystems */ | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
173 #if !SDL_CDROM_DISABLED |
0 | 174 if ( (flags & SDL_initialized & SDL_INIT_CDROM) ) { |
175 SDL_CDROMQuit(); | |
176 SDL_initialized &= ~SDL_INIT_CDROM; | |
177 } | |
178 #endif | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
179 #if !SDL_JOYSTICK_DISABLED |
0 | 180 if ( (flags & SDL_initialized & SDL_INIT_JOYSTICK) ) { |
181 SDL_JoystickQuit(); | |
182 SDL_initialized &= ~SDL_INIT_JOYSTICK; | |
183 } | |
184 #endif | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
185 #if !SDL_TIMERS_DISABLED |
0 | 186 if ( (flags & SDL_initialized & SDL_INIT_TIMER) ) { |
187 SDL_TimerQuit(); | |
188 SDL_initialized &= ~SDL_INIT_TIMER; | |
189 } | |
190 #endif | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
191 #if !SDL_AUDIO_DISABLED |
0 | 192 if ( (flags & SDL_initialized & SDL_INIT_AUDIO) ) { |
193 SDL_AudioQuit(); | |
194 SDL_initialized &= ~SDL_INIT_AUDIO; | |
195 } | |
196 #endif | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
197 #if !SDL_VIDEO_DISABLED |
0 | 198 if ( (flags & SDL_initialized & SDL_INIT_VIDEO) ) { |
199 SDL_VideoQuit(); | |
200 SDL_initialized &= ~SDL_INIT_VIDEO; | |
201 } | |
202 #endif | |
203 } | |
204 | |
205 Uint32 SDL_WasInit(Uint32 flags) | |
206 { | |
207 if ( ! flags ) { | |
208 flags = SDL_INIT_EVERYTHING; | |
209 } | |
210 return (SDL_initialized&flags); | |
211 } | |
212 | |
213 void SDL_Quit(void) | |
214 { | |
215 /* Quit all subsystems */ | |
1190 | 216 #ifdef DEBUG_BUILD |
217 printf("[SDL_Quit] : Enter! Calling QuitSubSystem()\n"); fflush(stdout); | |
218 #endif | |
0 | 219 SDL_QuitSubSystem(SDL_INIT_EVERYTHING); |
220 | |
221 #ifdef CHECK_LEAKS | |
1190 | 222 #ifdef DEBUG_BUILD |
223 printf("[SDL_Quit] : CHECK_LEAKS\n"); fflush(stdout); | |
224 #endif | |
225 | |
0 | 226 /* Print the number of surfaces not freed */ |
227 if ( surfaces_allocated != 0 ) { | |
228 fprintf(stderr, "SDL Warning: %d SDL surfaces extant\n", | |
229 surfaces_allocated); | |
230 } | |
231 #endif | |
1190 | 232 #ifdef DEBUG_BUILD |
233 printf("[SDL_Quit] : SDL_UninstallParachute()\n"); fflush(stdout); | |
234 #endif | |
0 | 235 |
236 /* Uninstall any parachute signal handlers */ | |
237 SDL_UninstallParachute(); | |
397 | 238 |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
239 #if !SDL_THREADS_DISABLED && SDL_THREAD_PTH |
397 | 240 pth_kill(); |
241 #endif | |
1190 | 242 #ifdef DEBUG_BUILD |
243 printf("[SDL_Quit] : Returning!\n"); fflush(stdout); | |
244 #endif | |
245 | |
0 | 246 } |
247 | |
248 /* Return the library version number */ | |
249 const SDL_version * SDL_Linked_Version(void) | |
250 { | |
251 return(&version); | |
252 } | |
253 | |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
254 #if defined(__OS2__) |
1190 | 255 // Building for OS/2 |
256 #ifdef __WATCOMC__ | |
257 | |
258 #define INCL_DOSERRORS | |
259 #define INCL_DOSEXCEPTIONS | |
260 #include <os2.h> | |
261 | |
262 // Exception handler to prevent the Audio thread hanging, making a zombie process! | |
263 ULONG _System SDL_Main_ExceptionHandler(PEXCEPTIONREPORTRECORD pERepRec, | |
264 PEXCEPTIONREGISTRATIONRECORD pERegRec, | |
265 PCONTEXTRECORD pCtxRec, | |
266 PVOID p) | |
267 { | |
268 if (pERepRec->fHandlerFlags & EH_EXIT_UNWIND) | |
269 return XCPT_CONTINUE_SEARCH; | |
270 if (pERepRec->fHandlerFlags & EH_UNWINDING) | |
271 return XCPT_CONTINUE_SEARCH; | |
272 if (pERepRec->fHandlerFlags & EH_NESTED_CALL) | |
273 return XCPT_CONTINUE_SEARCH; | |
274 | |
275 // Do cleanup at every fatal exception! | |
276 if (((pERepRec->ExceptionNum & XCPT_SEVERITY_CODE) == XCPT_FATAL_EXCEPTION) && | |
277 (pERepRec->ExceptionNum != XCPT_BREAKPOINT) && | |
278 (pERepRec->ExceptionNum != XCPT_SINGLE_STEP) | |
279 ) | |
280 { | |
281 if (SDL_initialized & SDL_INIT_AUDIO) | |
282 { | |
283 // This removes the zombie audio thread in case of emergency. | |
284 #ifdef DEBUG_BUILD | |
285 printf("[SDL_Main_ExceptionHandler] : Calling SDL_CloseAudio()!\n"); | |
286 #endif | |
287 SDL_CloseAudio(); | |
288 } | |
289 } | |
290 return (XCPT_CONTINUE_SEARCH); | |
291 } | |
292 | |
293 | |
294 EXCEPTIONREGISTRATIONRECORD SDL_Main_xcpthand = {0, SDL_Main_ExceptionHandler}; | |
295 | |
296 // The main DLL entry for DLL Initialization and Uninitialization: | |
297 unsigned _System LibMain(unsigned hmod, unsigned termination) | |
298 { | |
299 if (termination) | |
300 { | |
301 #ifdef DEBUG_BUILD | |
302 // printf("[SDL DLL Unintialization] : Removing exception handler\n"); | |
303 #endif | |
304 DosUnsetExceptionHandler(&SDL_Main_xcpthand); | |
305 return 1; | |
306 } else | |
307 { | |
308 #ifdef DEBUG_BUILD | |
309 // Make stdout and stderr unbuffered! | |
310 setbuf(stdout, NULL); | |
311 setbuf(stderr, NULL); | |
312 #endif | |
313 // Fire up exception handler | |
314 #ifdef DEBUG_BUILD | |
315 // printf("[SDL DLL Initialization] : Setting exception handler\n"); | |
316 #endif | |
317 // Set exception handler | |
318 DosSetExceptionHandler(&SDL_Main_xcpthand); | |
319 | |
320 return 1; | |
321 } | |
322 } | |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
323 #endif /* __WATCOMC__ */ |
1190 | 324 |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
325 #elif defined(_WIN32) |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
326 |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
327 #if !defined(HAVE_LIBC) || defined(_WIN32_WCE) || (defined(__WATCOMC__) && defined(BUILD_DLL)) |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
328 /* Need to include DllMain() on Windows CE and Watcom C for some reason.. */ |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
329 #include "SDL_windows.h" |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
330 |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
331 BOOL APIENTRY _DllMainCRTStartup( HANDLE hModule, |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
332 DWORD ul_reason_for_call, |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
333 LPVOID lpReserved ) |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
334 { |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
335 switch (ul_reason_for_call) { |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
336 case DLL_PROCESS_ATTACH: |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
337 case DLL_THREAD_ATTACH: |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
338 case DLL_THREAD_DETACH: |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
339 case DLL_PROCESS_DETACH: |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
340 break; |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
341 } |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
342 return TRUE; |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
343 } |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
344 #endif /* _WIN32_WCE and building DLL with Watcom C */ |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
345 |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
346 #endif /* OS/2 elif _WIN32 */ |