Mercurial > sdl-ios-xcode
comparison src/joystick/amigaos/SDL_sysjoystick.c @ 1662:782fd950bd46 SDL-1.3
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.
The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce
The headers are being converted to automatically generate doxygen documentation.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 28 May 2006 13:04:16 +0000 |
parents | 92947e3a18db |
children | 4da1ee79c9af |
comparison
equal
deleted
inserted
replaced
1661:281d3f4870e5 | 1662:782fd950bd46 |
---|---|
50 * It should return 0, or -1 on an unrecoverable fatal error. | 50 * It should return 0, or -1 on an unrecoverable fatal error. |
51 */ | 51 */ |
52 | 52 |
53 | 53 |
54 /* Amiga specific datas */ | 54 /* Amiga specific datas */ |
55 struct Library *LowLevelBase=NULL; | 55 struct Library *LowLevelBase = NULL; |
56 | 56 |
57 ULONG joybut[]= | 57 ULONG joybut[] = { |
58 { | 58 JPF_BUTTON_RED, |
59 JPF_BUTTON_RED, | 59 JPF_BUTTON_BLUE, |
60 JPF_BUTTON_BLUE, | 60 JPF_BUTTON_PLAY, |
61 JPF_BUTTON_PLAY, | 61 JPF_BUTTON_YELLOW, |
62 JPF_BUTTON_YELLOW, | 62 JPF_BUTTON_GREEN, |
63 JPF_BUTTON_GREEN, | 63 JPF_BUTTON_FORWARD, |
64 JPF_BUTTON_FORWARD, | 64 JPF_BUTTON_REVERSE, |
65 JPF_BUTTON_REVERSE, | |
66 }; | 65 }; |
67 | 66 |
68 struct joystick_hwdata | 67 struct joystick_hwdata |
69 { | 68 { |
70 ULONG joystate; | 69 ULONG joystate; |
71 }; | 70 }; |
72 | 71 |
73 int SDL_SYS_JoystickInit(void) | 72 int |
74 { | 73 SDL_SYS_JoystickInit (void) |
75 if(!LowLevelBase) | 74 { |
76 { | 75 if (!LowLevelBase) { |
77 if(LowLevelBase=OpenLibrary("lowlevel.library",37)) | 76 if (LowLevelBase = OpenLibrary ("lowlevel.library", 37)) |
78 return 2; | 77 return 2; |
79 } | 78 } else |
80 else | 79 return 2; |
81 return 2; | 80 |
82 | 81 D (bug ("%ld joysticks available.\n", SDL_numjoysticks)); |
83 D(bug("%ld joysticks available.\n",SDL_numjoysticks)); | 82 |
84 | 83 return 0; |
85 return 0; | |
86 } | 84 } |
87 | 85 |
88 /* Function to get the device-dependent name of a joystick */ | 86 /* Function to get the device-dependent name of a joystick */ |
89 const char *SDL_SYS_JoystickName(int index) | 87 const char * |
90 { | 88 SDL_SYS_JoystickName (int index) |
91 if(index<2&&LowLevelBase) | 89 { |
92 { | 90 if (index < 2 && LowLevelBase) { |
93 switch(index) | 91 switch (index) { |
94 { | 92 case 0: |
95 case 0: | 93 return "Port 1 Amiga Joystick/Joypad"; |
96 return "Port 1 Amiga Joystick/Joypad"; | 94 case 1: |
97 case 1: | 95 return "Port 2 Amiga Joystick/Joypad"; |
98 return "Port 2 Amiga Joystick/Joypad"; | 96 } |
99 } | 97 } |
100 } | 98 |
101 | 99 SDL_SetError ("No joystick available with that index"); |
102 SDL_SetError("No joystick available with that index"); | 100 return (NULL); |
103 return(NULL); | |
104 } | 101 } |
105 | 102 |
106 /* Function to open a joystick for use. | 103 /* Function to open a joystick for use. |
107 The joystick to open is specified by the index field of the joystick. | 104 The joystick to open is specified by the index field of the joystick. |
108 This should fill the nbuttons and naxes fields of the joystick structure. | 105 This should fill the nbuttons and naxes fields of the joystick structure. |
109 It returns 0, or -1 if there is an error. | 106 It returns 0, or -1 if there is an error. |
110 */ | 107 */ |
111 | 108 |
112 int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) | 109 int |
113 { | 110 SDL_SYS_JoystickOpen (SDL_Joystick * joystick) |
114 ULONG temp,i; | 111 { |
115 D(bug("Opening joystick %ld\n",joystick->index)); | 112 ULONG temp, i; |
116 | 113 D (bug ("Opening joystick %ld\n", joystick->index)); |
117 if(!(joystick->hwdata=SDL_malloc(sizeof(struct joystick_hwdata)))) | 114 |
118 return -1; | 115 if (!(joystick->hwdata = SDL_malloc (sizeof (struct joystick_hwdata)))) |
116 return -1; | |
119 | 117 |
120 /* This loop is to check if the controller is a joypad */ | 118 /* This loop is to check if the controller is a joypad */ |
121 | 119 |
122 for(i=0;i<20;i++) | 120 for (i = 0; i < 20; i++) { |
123 { | 121 temp = ReadJoyPort (joystick->index ^ 1); // fix to invert amiga joyports |
124 temp=ReadJoyPort(joystick->index^1); // fix to invert amiga joyports | 122 WaitTOF (); |
125 WaitTOF(); | 123 } |
126 } | 124 |
127 | 125 if ((temp & JP_TYPE_MASK) == JP_TYPE_GAMECTLR) |
128 if((temp&JP_TYPE_MASK)==JP_TYPE_GAMECTLR) | 126 joystick->nbuttons = 7; |
129 joystick->nbuttons=7; | 127 else |
130 else | 128 joystick->nbuttons = 3; |
131 joystick->nbuttons=3; | 129 |
132 | 130 joystick->nhats = 0; |
133 joystick->nhats=0; | 131 joystick->nballs = 0; |
134 joystick->nballs=0; | 132 joystick->naxes = 2; |
135 joystick->naxes=2; | 133 joystick->hwdata->joystate = 0L; |
136 joystick->hwdata->joystate=0L; | 134 |
137 | 135 return 0; |
138 return 0; | |
139 } | 136 } |
140 | 137 |
141 /* Function to update the state of a joystick - called as a device poll. | 138 /* Function to update the state of a joystick - called as a device poll. |
142 * This function shouldn't update the joystick structure directly, | 139 * This function shouldn't update the joystick structure directly, |
143 * but instead should call SDL_PrivateJoystick*() to deliver events | 140 * but instead should call SDL_PrivateJoystick*() to deliver events |
144 * and update joystick device state. | 141 * and update joystick device state. |
145 */ | 142 */ |
146 void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) | 143 void |
147 { | 144 SDL_SYS_JoystickUpdate (SDL_Joystick * joystick) |
148 ULONG data; | 145 { |
149 int i; | 146 ULONG data; |
150 | 147 int i; |
151 if(joystick->index<2) | 148 |
152 { | 149 if (joystick->index < 2) { |
153 data=ReadJoyPort(joystick->index); | 150 data = ReadJoyPort (joystick->index); |
154 | 151 |
155 if(data&JP_DIRECTION_MASK) | 152 if (data & JP_DIRECTION_MASK) { |
156 { | 153 if (data & JPF_JOY_DOWN) { |
157 if(data&JPF_JOY_DOWN) | 154 if (!(joystick->hwdata->joystate & JPF_JOY_DOWN)) |
158 { | 155 SDL_PrivateJoystickAxis (joystick, 0, 127); |
159 if(!(joystick->hwdata->joystate&JPF_JOY_DOWN)) | 156 } else if (data & JPF_JOY_UP) { |
160 SDL_PrivateJoystickAxis(joystick,0,127); | 157 if (!(joystick->hwdata->joystate & JPF_JOY_UP)) |
161 } | 158 SDL_PrivateJoystickAxis (joystick, 0, -127); |
162 else if(data&JPF_JOY_UP) | 159 } else if (joystick->hwdata-> |
163 { | 160 joystate & (JPF_JOY_UP | JPF_JOY_DOWN)) |
164 if(!(joystick->hwdata->joystate&JPF_JOY_UP)) | 161 SDL_PrivateJoystickAxis (joystick, 0, 0); |
165 SDL_PrivateJoystickAxis(joystick,0,-127); | 162 |
166 } | 163 if (data & JPF_JOY_LEFT) { |
167 else if(joystick->hwdata->joystate&(JPF_JOY_UP|JPF_JOY_DOWN)) | 164 if (!(joystick->hwdata->joystate & JPF_JOY_LEFT)) |
168 SDL_PrivateJoystickAxis(joystick,0,0); | 165 SDL_PrivateJoystickAxis (joystick, 1, -127); |
169 | 166 } else if (data & JPF_JOY_RIGHT) { |
170 if(data&JPF_JOY_LEFT) | 167 if (!(joystick->hwdata->joystate & JPF_JOY_RIGHT)) |
171 { | 168 SDL_PrivateJoystickAxis (joystick, 1, 127); |
172 if(!(joystick->hwdata->joystate&JPF_JOY_LEFT)) | 169 } else if (joystick->hwdata-> |
173 SDL_PrivateJoystickAxis(joystick,1,-127); | 170 joystate & (JPF_JOY_LEFT | JPF_JOY_RIGHT)) |
174 } | 171 SDL_PrivateJoystickAxis (joystick, 1, 0); |
175 else if(data&JPF_JOY_RIGHT) | 172 } else if (joystick->hwdata-> |
176 { | 173 joystate & (JPF_JOY_LEFT | JPF_JOY_RIGHT)) { |
177 if(!(joystick->hwdata->joystate&JPF_JOY_RIGHT)) | 174 SDL_PrivateJoystickAxis (joystick, 1, 0); |
178 SDL_PrivateJoystickAxis(joystick,1,127); | 175 } else if (joystick->hwdata->joystate & (JPF_JOY_UP | JPF_JOY_DOWN)) { |
179 } | 176 SDL_PrivateJoystickAxis (joystick, 0, 0); |
180 else if(joystick->hwdata->joystate&(JPF_JOY_LEFT|JPF_JOY_RIGHT)) | 177 } |
181 SDL_PrivateJoystickAxis(joystick,1,0); | 178 |
182 } | 179 for (i = 0; i < joystick->nbuttons; i++) { |
183 else if(joystick->hwdata->joystate&(JPF_JOY_LEFT|JPF_JOY_RIGHT)) | 180 if ((data & joybut[i])) { |
184 { | 181 if (i == 1) |
185 SDL_PrivateJoystickAxis(joystick,1,0); | 182 data &= (~(joybut[2])); |
186 } | 183 |
187 else if(joystick->hwdata->joystate&(JPF_JOY_UP|JPF_JOY_DOWN)) | 184 if (!(joystick->hwdata->joystate & joybut[i])) |
188 { | 185 SDL_PrivateJoystickButton (joystick, i, SDL_PRESSED); |
189 SDL_PrivateJoystickAxis(joystick,0,0); | 186 } else if (joystick->hwdata->joystate & joybut[i]) |
190 } | 187 SDL_PrivateJoystickButton (joystick, i, SDL_RELEASED); |
191 | 188 } |
192 for(i=0;i<joystick->nbuttons;i++) | 189 |
193 { | 190 joystick->hwdata->joystate = data; |
194 if( (data&joybut[i]) ) | 191 } |
195 { | 192 |
196 if(i==1) | 193 return; |
197 data&=(~(joybut[2])); | |
198 | |
199 if(!(joystick->hwdata->joystate&joybut[i])) | |
200 SDL_PrivateJoystickButton(joystick,i,SDL_PRESSED); | |
201 } | |
202 else if(joystick->hwdata->joystate&joybut[i]) | |
203 SDL_PrivateJoystickButton(joystick,i,SDL_RELEASED); | |
204 } | |
205 | |
206 joystick->hwdata->joystate=data; | |
207 } | |
208 | |
209 return; | |
210 } | 194 } |
211 | 195 |
212 /* Function to close a joystick after use */ | 196 /* Function to close a joystick after use */ |
213 void SDL_SYS_JoystickClose(SDL_Joystick *joystick) | 197 void |
214 { | 198 SDL_SYS_JoystickClose (SDL_Joystick * joystick) |
215 if(joystick->hwdata) | 199 { |
216 SDL_free(joystick->hwdata); | 200 if (joystick->hwdata) |
217 return; | 201 SDL_free (joystick->hwdata); |
202 return; | |
218 } | 203 } |
219 | 204 |
220 /* Function to perform any system-specific joystick related cleanup */ | 205 /* Function to perform any system-specific joystick related cleanup */ |
221 | 206 |
222 void SDL_SYS_JoystickQuit(void) | 207 void |
223 { | 208 SDL_SYS_JoystickQuit (void) |
224 if(LowLevelBase) | 209 { |
225 { | 210 if (LowLevelBase) { |
226 CloseLibrary(LowLevelBase); | 211 CloseLibrary (LowLevelBase); |
227 LowLevelBase=NULL; | 212 LowLevelBase = NULL; |
228 SDL_numjoysticks=0; | 213 SDL_numjoysticks = 0; |
229 } | 214 } |
230 return; | 215 return; |
231 } | 216 } |
232 | 217 |
233 #endif /* SDL_JOYSTICK_AMIGA */ | 218 #endif /* SDL_JOYSTICK_AMIGA */ |
219 /* vi: set ts=4 sw=4 expandtab: */ |