pcsxr-1.9.92
[pcsx_rearmed.git] / macosx / plugins / DFInput / SDL / src / SDL.c
1 /*
2     SDL - Simple DirectMedia Layer
3     Copyright (C) 1997-2010 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 // 7/31/2010 Wei Mingzhi
23 // Removed everything unrated to Mac OS X Joystick support
24
25 #include "SDL_config.h"
26
27 /* Initialization code for SDL */
28
29 #include "SDL.h"
30 #include "haptic/SDL_haptic_c.h"
31 #include "joystick/SDL_joystick_c.h"
32
33 /* The initialized subsystems */
34 static Uint32 SDL_initialized = 0;
35
36 int
37 SDL_InitSubSystem(Uint32 flags)
38 {
39     /* Initialize the joystick subsystem */
40     if ((flags & SDL_INIT_JOYSTICK) && !(SDL_initialized & SDL_INIT_JOYSTICK)) {
41         if (SDL_JoystickInit() < 0) {
42             return (-1);
43         }
44         SDL_initialized |= SDL_INIT_JOYSTICK;
45     }
46
47     /* Initialize the haptic subsystem */
48     if ((flags & SDL_INIT_HAPTIC) && !(SDL_initialized & SDL_INIT_HAPTIC)) {
49         if (SDL_HapticInit() < 0) {
50             return (-1);
51         }
52         SDL_initialized |= SDL_INIT_HAPTIC;
53     }
54
55     return (0);
56 }
57
58 int
59 SDL_Init(Uint32 flags)
60 {
61     /* Clear the error message */
62     SDL_ClearError();
63
64     /* Initialize the desired subsystems */
65     if (SDL_InitSubSystem(flags) < 0) {
66         return (-1);
67     }
68
69     return (0);
70 }
71
72 void
73 SDL_QuitSubSystem(Uint32 flags)
74 {
75     /* Shut down requested initialized subsystems */
76     if ((flags & SDL_initialized & SDL_INIT_JOYSTICK)) {
77         SDL_JoystickQuit();
78         SDL_initialized &= ~SDL_INIT_JOYSTICK;
79     }
80
81     if ((flags & SDL_initialized & SDL_INIT_HAPTIC)) {
82         SDL_HapticQuit();
83         SDL_initialized &= ~SDL_INIT_HAPTIC;
84     }
85 }
86
87 Uint32
88 SDL_WasInit(Uint32 flags)
89 {
90     if (!flags) {
91         flags = SDL_INIT_EVERYTHING;
92     }
93     return (SDL_initialized & flags);
94 }
95
96 void
97 SDL_Quit(void)
98 {
99     /* Quit all subsystems */
100     SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
101 }