Removed old touchscreen system, starting to implement mouse-based touchscreen. Also, more work on a non-software-rendering video driver
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2006 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 #if !SDL_VIDEO_DISABLED
29 #include "video/SDL_leaks.h"
36 /* Initialization/Cleanup routines */
37 #if !SDL_JOYSTICK_DISABLED
38 extern int SDL_JoystickInit(void);
39 extern void SDL_JoystickQuit(void);
41 #if !SDL_CDROM_DISABLED
42 extern int SDL_CDROMInit(void);
43 extern void SDL_CDROMQuit(void);
45 #if !SDL_TIMERS_DISABLED
46 extern void SDL_StartTicks(void);
47 extern int SDL_TimerInit(void);
48 extern void SDL_TimerQuit(void);
51 /* The initialized subsystems */
52 static Uint32 SDL_initialized = 0;
53 static Uint32 ticks_started = 0;
56 int surfaces_allocated = 0;
60 SDL_InitSubSystem(Uint32 flags)
62 #if !SDL_VIDEO_DISABLED
63 /* Initialize the video/event subsystem */
64 if ((flags & SDL_INIT_VIDEO) && !(SDL_initialized & SDL_INIT_VIDEO)) {
65 if (SDL_VideoInit(NULL, (flags & SDL_INIT_EVENTTHREAD)) < 0) {
68 SDL_initialized |= SDL_INIT_VIDEO;
71 if (flags & SDL_INIT_VIDEO) {
72 SDL_SetError("SDL not built with video support");
77 #if !SDL_AUDIO_DISABLED
78 /* Initialize the audio subsystem */
79 if ((flags & SDL_INIT_AUDIO) && !(SDL_initialized & SDL_INIT_AUDIO)) {
80 if (SDL_AudioInit(NULL) < 0) {
83 SDL_initialized |= SDL_INIT_AUDIO;
86 if (flags & SDL_INIT_AUDIO) {
87 SDL_SetError("SDL not built with audio support");
92 #if !SDL_TIMERS_DISABLED
93 /* Initialize the timer subsystem */
98 if ((flags & SDL_INIT_TIMER) && !(SDL_initialized & SDL_INIT_TIMER)) {
99 if (SDL_TimerInit() < 0) {
102 SDL_initialized |= SDL_INIT_TIMER;
105 if (flags & SDL_INIT_TIMER) {
106 SDL_SetError("SDL not built with timer support");
111 #if !SDL_JOYSTICK_DISABLED
112 /* Initialize the joystick subsystem */
113 if ((flags & SDL_INIT_JOYSTICK) && !(SDL_initialized & SDL_INIT_JOYSTICK)) {
114 if (SDL_JoystickInit() < 0) {
117 SDL_initialized |= SDL_INIT_JOYSTICK;
120 if (flags & SDL_INIT_JOYSTICK) {
121 SDL_SetError("SDL not built with joystick support");
126 #if !SDL_CDROM_DISABLED
127 /* Initialize the CD-ROM subsystem */
128 if ((flags & SDL_INIT_CDROM) && !(SDL_initialized & SDL_INIT_CDROM)) {
129 if (SDL_CDROMInit() < 0) {
132 SDL_initialized |= SDL_INIT_CDROM;
135 if (flags & SDL_INIT_CDROM) {
136 SDL_SetError("SDL not built with cdrom support");
144 SDL_Init(Uint32 flags)
146 #if !SDL_THREADS_DISABLED && SDL_THREAD_PTH
152 /* Clear the error message */
155 /* Initialize the desired subsystems */
156 if (SDL_InitSubSystem(flags) < 0) {
160 /* Everything is initialized */
161 if (!(flags & SDL_INIT_NOPARACHUTE)) {
162 SDL_InstallParachute();
168 SDL_QuitSubSystem(Uint32 flags)
170 /* Shut down requested initialized subsystems */
171 #if !SDL_CDROM_DISABLED
172 if ((flags & SDL_initialized & SDL_INIT_CDROM)) {
174 SDL_initialized &= ~SDL_INIT_CDROM;
177 #if !SDL_JOYSTICK_DISABLED
178 if ((flags & SDL_initialized & SDL_INIT_JOYSTICK)) {
180 SDL_initialized &= ~SDL_INIT_JOYSTICK;
183 #if !SDL_TIMERS_DISABLED
184 if ((flags & SDL_initialized & SDL_INIT_TIMER)) {
186 SDL_initialized &= ~SDL_INIT_TIMER;
189 #if !SDL_AUDIO_DISABLED
190 if ((flags & SDL_initialized & SDL_INIT_AUDIO)) {
192 SDL_initialized &= ~SDL_INIT_AUDIO;
195 #if !SDL_VIDEO_DISABLED
196 if ((flags & SDL_initialized & SDL_INIT_VIDEO)) {
198 SDL_initialized &= ~SDL_INIT_VIDEO;
204 SDL_WasInit(Uint32 flags)
207 flags = SDL_INIT_EVERYTHING;
209 return (SDL_initialized & flags);
215 /* Quit all subsystems */
217 printf("[SDL_Quit] : Enter! Calling QuitSubSystem()\n");
220 SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
224 printf("[SDL_Quit] : CHECK_LEAKS\n");
228 /* Print the number of surfaces not freed */
229 if (surfaces_allocated != 0) {
230 fprintf(stderr, "SDL Warning: %d SDL surfaces extant\n",
235 printf("[SDL_Quit] : SDL_UninstallParachute()\n");
239 /* Uninstall any parachute signal handlers */
240 SDL_UninstallParachute();
242 #if !SDL_THREADS_DISABLED && SDL_THREAD_PTH
246 printf("[SDL_Quit] : Returning!\n");
252 /* Get the library version number */
254 SDL_GetVersion(SDL_version * ver)
260 /* Building for OS/2 */
263 #define INCL_DOSERRORS
264 #define INCL_DOSEXCEPTIONS
267 /* Exception handler to prevent the Audio thread hanging, making a zombie process! */
269 SDL_Main_ExceptionHandler(PEXCEPTIONREPORTRECORD pERepRec,
270 PEXCEPTIONREGISTRATIONRECORD pERegRec,
271 PCONTEXTRECORD pCtxRec, PVOID p)
273 if (pERepRec->fHandlerFlags & EH_EXIT_UNWIND)
274 return XCPT_CONTINUE_SEARCH;
275 if (pERepRec->fHandlerFlags & EH_UNWINDING)
276 return XCPT_CONTINUE_SEARCH;
277 if (pERepRec->fHandlerFlags & EH_NESTED_CALL)
278 return XCPT_CONTINUE_SEARCH;
280 /* Do cleanup at every fatal exception! */
281 if (((pERepRec->ExceptionNum & XCPT_SEVERITY_CODE) ==
282 XCPT_FATAL_EXCEPTION) && (pERepRec->ExceptionNum != XCPT_BREAKPOINT)
283 && (pERepRec->ExceptionNum != XCPT_SINGLE_STEP)) {
284 if (SDL_initialized & SDL_INIT_AUDIO) {
285 /* This removes the zombie audio thread in case of emergency. */
288 ("[SDL_Main_ExceptionHandler] : Calling SDL_CloseAudio()!\n");
293 return (XCPT_CONTINUE_SEARCH);
297 EXCEPTIONREGISTRATIONRECORD SDL_Main_xcpthand =
298 { 0, SDL_Main_ExceptionHandler };
300 /* The main DLL entry for DLL Initialization and Uninitialization: */
302 LibMain(unsigned hmod, unsigned termination)
306 /* printf("[SDL DLL Unintialization] : Removing exception handler\n"); */
308 DosUnsetExceptionHandler(&SDL_Main_xcpthand);
312 /* Make stdout and stderr unbuffered! */
313 setbuf(stdout, NULL);
314 setbuf(stderr, NULL);
316 /* Fire up exception handler */
318 /* printf("[SDL DLL Initialization] : Setting exception handler\n"); */
320 /* Set exception handler */
321 DosSetExceptionHandler(&SDL_Main_xcpthand);
326 #endif /* __WATCOMC__ */
328 #elif defined(__WIN32__)
330 #if !defined(HAVE_LIBC) || (defined(__WATCOMC__) && defined(BUILD_DLL))
331 /* Need to include DllMain() on Watcom C for some reason.. */
332 #define WIN32_LEAN_AND_MEAN
336 _DllMainCRTStartup(HANDLE hModule,
337 DWORD ul_reason_for_call, LPVOID lpReserved)
339 switch (ul_reason_for_call) {
340 case DLL_PROCESS_ATTACH:
341 case DLL_THREAD_ATTACH:
342 case DLL_THREAD_DETACH:
343 case DLL_PROCESS_DETACH:
348 #endif /* building DLL with Watcom C */
350 #endif /* OS/2 elif __WIN32__ */
352 /* vi: set ts=4 sw=4 expandtab: */