/[pcsx2_0.9.7]/trunk/3rdparty/SDL-1.3.0-5387/src/SDL.c
ViewVC logotype

Contents of /trunk/3rdparty/SDL-1.3.0-5387/src/SDL.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 401 - (show annotations) (download)
Fri Feb 25 17:31:09 2011 UTC (9 years, 11 months ago) by william
File MIME type: text/plain
File size: 7517 byte(s)
Auto Commited Import of: pcsx2-0.9.7-DEBUG (upstream: v0.9.7.4358 local: v0.9.7.313-latest) in ./trunk
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2011 Sam Lantinga
4
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.
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
13 Lesser General Public License for more details.
14
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
18
19 Sam Lantinga
20 slouken@libsdl.org
21 */
22 #include "SDL_config.h"
23
24 /* Initialization code for SDL */
25
26 #include "SDL.h"
27 #include "SDL_revision.h"
28 #include "SDL_fatal.h"
29 #include "SDL_assert_c.h"
30 #include "haptic/SDL_haptic_c.h"
31 #include "joystick/SDL_joystick_c.h"
32
33 /* Initialization/Cleanup routines */
34 #if !SDL_TIMERS_DISABLED
35 extern void SDL_StartTicks(void);
36 extern int SDL_TimerInit(void);
37 extern void SDL_TimerQuit(void);
38 #endif
39 #if defined(__WIN32__)
40 extern int SDL_HelperWindowCreate(void);
41 extern int SDL_HelperWindowDestroy(void);
42 #endif
43
44
45 /* The initialized subsystems */
46 static Uint32 SDL_initialized = 0;
47 static Uint32 ticks_started = 0;
48
49
50 int
51 SDL_InitSubSystem(Uint32 flags)
52 {
53 #if !SDL_VIDEO_DISABLED
54 /* Initialize the video/event subsystem */
55 if ((flags & SDL_INIT_VIDEO) && !(SDL_initialized & SDL_INIT_VIDEO)) {
56 if (SDL_VideoInit(NULL) < 0) {
57 return (-1);
58 }
59 SDL_initialized |= SDL_INIT_VIDEO;
60 }
61 #else
62 if (flags & SDL_INIT_VIDEO) {
63 SDL_SetError("SDL not built with video support");
64 return (-1);
65 }
66 #endif
67
68 #if !SDL_AUDIO_DISABLED
69 /* Initialize the audio subsystem */
70 if ((flags & SDL_INIT_AUDIO) && !(SDL_initialized & SDL_INIT_AUDIO)) {
71 if (SDL_AudioInit(NULL) < 0) {
72 return (-1);
73 }
74 SDL_initialized |= SDL_INIT_AUDIO;
75 }
76 #else
77 if (flags & SDL_INIT_AUDIO) {
78 SDL_SetError("SDL not built with audio support");
79 return (-1);
80 }
81 #endif
82
83 #if !SDL_TIMERS_DISABLED
84 /* Initialize the timer subsystem */
85 if (!ticks_started) {
86 SDL_StartTicks();
87 ticks_started = 1;
88 }
89 if ((flags & SDL_INIT_TIMER) && !(SDL_initialized & SDL_INIT_TIMER)) {
90 if (SDL_TimerInit() < 0) {
91 return (-1);
92 }
93 SDL_initialized |= SDL_INIT_TIMER;
94 }
95 #else
96 if (flags & SDL_INIT_TIMER) {
97 SDL_SetError("SDL not built with timer support");
98 return (-1);
99 }
100 #endif
101
102 #if !SDL_JOYSTICK_DISABLED
103 /* Initialize the joystick subsystem */
104 if ((flags & SDL_INIT_JOYSTICK) && !(SDL_initialized & SDL_INIT_JOYSTICK)) {
105 if (SDL_JoystickInit() < 0) {
106 return (-1);
107 }
108 SDL_initialized |= SDL_INIT_JOYSTICK;
109 }
110 #else
111 if (flags & SDL_INIT_JOYSTICK) {
112 SDL_SetError("SDL not built with joystick support");
113 return (-1);
114 }
115 #endif
116
117 #if !SDL_HAPTIC_DISABLED
118 /* Initialize the haptic subsystem */
119 if ((flags & SDL_INIT_HAPTIC) && !(SDL_initialized & SDL_INIT_HAPTIC)) {
120 if (SDL_HapticInit() < 0) {
121 return (-1);
122 }
123 SDL_initialized |= SDL_INIT_HAPTIC;
124 }
125 #else
126 if (flags & SDL_INIT_HAPTIC) {
127 SDL_SetError("SDL not built with haptic (force feedback) support");
128 return (-1);
129 }
130 #endif
131 return (0);
132 }
133
134 int
135 SDL_Init(Uint32 flags)
136 {
137 if (SDL_AssertionsInit() < 0) {
138 return -1;
139 }
140
141 /* Clear the error message */
142 SDL_ClearError();
143
144 #if defined(__WIN32__)
145 if (SDL_HelperWindowCreate() < 0) {
146 return -1;
147 }
148 #endif
149
150 /* Initialize the desired subsystems */
151 if (SDL_InitSubSystem(flags) < 0) {
152 return (-1);
153 }
154
155 /* Everything is initialized */
156 if (!(flags & SDL_INIT_NOPARACHUTE)) {
157 SDL_InstallParachute();
158 }
159
160 return (0);
161 }
162
163 void
164 SDL_QuitSubSystem(Uint32 flags)
165 {
166 /* Shut down requested initialized subsystems */
167 #if !SDL_JOYSTICK_DISABLED
168 if ((flags & SDL_initialized & SDL_INIT_JOYSTICK)) {
169 SDL_JoystickQuit();
170 SDL_initialized &= ~SDL_INIT_JOYSTICK;
171 }
172 #endif
173 #if !SDL_HAPTIC_DISABLED
174 if ((flags & SDL_initialized & SDL_INIT_HAPTIC)) {
175 SDL_HapticQuit();
176 SDL_initialized &= ~SDL_INIT_HAPTIC;
177 }
178 #endif
179 #if !SDL_TIMERS_DISABLED
180 if ((flags & SDL_initialized & SDL_INIT_TIMER)) {
181 SDL_TimerQuit();
182 SDL_initialized &= ~SDL_INIT_TIMER;
183 }
184 #endif
185 #if !SDL_AUDIO_DISABLED
186 if ((flags & SDL_initialized & SDL_INIT_AUDIO)) {
187 SDL_AudioQuit();
188 SDL_initialized &= ~SDL_INIT_AUDIO;
189 }
190 #endif
191 #if !SDL_VIDEO_DISABLED
192 if ((flags & SDL_initialized & SDL_INIT_VIDEO)) {
193 SDL_VideoQuit();
194 SDL_initialized &= ~SDL_INIT_VIDEO;
195 }
196 #endif
197 }
198
199 Uint32
200 SDL_WasInit(Uint32 flags)
201 {
202 if (!flags) {
203 flags = SDL_INIT_EVERYTHING;
204 }
205 return (SDL_initialized & flags);
206 }
207
208 void
209 SDL_Quit(void)
210 {
211 /* Quit all subsystems */
212 #if defined(__WIN32__)
213 SDL_HelperWindowDestroy();
214 #endif
215 SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
216
217 /* Uninstall any parachute signal handlers */
218 SDL_UninstallParachute();
219
220 SDL_ClearHints();
221 SDL_AssertionsQuit();
222 SDL_LogResetPriorities();
223 }
224
225 /* Get the library version number */
226 void
227 SDL_GetVersion(SDL_version * ver)
228 {
229 SDL_VERSION(ver);
230 }
231
232 /* Get the library source revision */
233 const char *
234 SDL_GetRevision(void)
235 {
236 return SDL_REVISION;
237 }
238
239 /* Get the library source revision number */
240 int
241 SDL_GetRevisionNumber(void)
242 {
243 return SDL_REVISION_NUMBER;
244 }
245
246 /* Get the name of the platform */
247 const char *
248 SDL_GetPlatform()
249 {
250 #if __AIX__
251 return "AIX";
252 #elif __HAIKU__
253 /* Haiku must appear here before BeOS, since it also defines __BEOS__ */
254 return "Haiku";
255 #elif __BEOS__
256 return "BeOS";
257 #elif __BSDI__
258 return "BSDI";
259 #elif __DREAMCAST__
260 return "Dreamcast";
261 #elif __FREEBSD__
262 return "FreeBSD";
263 #elif __HPUX__
264 return "HP-UX";
265 #elif __IRIX__
266 return "Irix";
267 #elif __LINUX__
268 return "Linux";
269 #elif __MINT__
270 return "Atari MiNT";
271 #elif __MACOS__
272 return "MacOS Classic";
273 #elif __MACOSX__
274 return "Mac OS X";
275 #elif __NETBSD__
276 return "NetBSD";
277 #elif __NDS__
278 return "Nintendo DS";
279 #elif __OPENBSD__
280 return "OpenBSD";
281 #elif __OS2__
282 return "OS/2";
283 #elif __OSF__
284 return "OSF/1";
285 #elif __QNXNTO__
286 return "QNX Neutrino";
287 #elif __RISCOS__
288 return "RISC OS";
289 #elif __SOLARIS__
290 return "Solaris";
291 #elif __WIN32__
292 #ifdef _WIN32_WCE
293 return "Windows CE";
294 #else
295 return "Windows";
296 #endif
297 #elif __IPHONEOS__
298 return "iPhone OS";
299 #else
300 return "Unknown (see SDL_platform.h)";
301 #endif
302 }
303
304 #if defined(__WIN32__)
305
306 #if !defined(HAVE_LIBC) || (defined(__WATCOMC__) && defined(BUILD_DLL))
307 /* Need to include DllMain() on Watcom C for some reason.. */
308 #include "core/windows/SDL_windows.h"
309
310 BOOL APIENTRY
311 _DllMainCRTStartup(HANDLE hModule,
312 DWORD ul_reason_for_call, LPVOID lpReserved)
313 {
314 switch (ul_reason_for_call) {
315 case DLL_PROCESS_ATTACH:
316 case DLL_THREAD_ATTACH:
317 case DLL_THREAD_DETACH:
318 case DLL_PROCESS_DETACH:
319 break;
320 }
321 return TRUE;
322 }
323 #endif /* building DLL with Watcom C */
324
325 #endif /* __WIN32__ */
326
327 /* vi: set ts=4 sw=4 expandtab: */

  ViewVC Help
Powered by ViewVC 1.1.22