Mercurial > repos > simple16
comparison src/system_sdl.c @ 38:3b7910575a00
Implemented basic keyboard support
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 04 Apr 2016 09:13:14 -0700 |
parents | c677507682e3 |
children | 8e39a877c651 |
comparison
equal
deleted
inserted
replaced
37:44c057a640b2 | 38:3b7910575a00 |
---|---|
171 } | 171 } |
172 } | 172 } |
173 return NULL; | 173 return NULL; |
174 } | 174 } |
175 | 175 |
176 const uint16_t mapping[SDL_CONTROLLER_BUTTON_MAX] = { | 176 static const uint16_t mapping[SDL_CONTROLLER_BUTTON_MAX] = { |
177 [SDL_CONTROLLER_BUTTON_LEFTSHOULDER] = 0x001, | 177 [SDL_CONTROLLER_BUTTON_LEFTSHOULDER] = 0x001, |
178 [SDL_CONTROLLER_BUTTON_Y] = 0x002, | 178 [SDL_CONTROLLER_BUTTON_Y] = 0x002, |
179 [SDL_CONTROLLER_BUTTON_X] = 0x004, | 179 [SDL_CONTROLLER_BUTTON_X] = 0x004, |
180 [SDL_CONTROLLER_BUTTON_RIGHTSHOULDER] = 0x008, | 180 [SDL_CONTROLLER_BUTTON_RIGHTSHOULDER] = 0x008, |
181 [SDL_CONTROLLER_BUTTON_B] = 0x010, | 181 [SDL_CONTROLLER_BUTTON_B] = 0x010, |
186 [SDL_CONTROLLER_BUTTON_DPAD_LEFT] = 0x200, | 186 [SDL_CONTROLLER_BUTTON_DPAD_LEFT] = 0x200, |
187 [SDL_CONTROLLER_BUTTON_DPAD_DOWN] = 0x400, | 187 [SDL_CONTROLLER_BUTTON_DPAD_DOWN] = 0x400, |
188 [SDL_CONTROLLER_BUTTON_DPAD_UP] = 0x800, | 188 [SDL_CONTROLLER_BUTTON_DPAD_UP] = 0x800, |
189 }; | 189 }; |
190 | 190 |
191 static uint16_t keycode_to_bit(SDL_Keycode keycode) | |
192 { | |
193 switch(keycode) | |
194 { | |
195 case SDLK_a: | |
196 return 0x020; | |
197 case SDLK_s: | |
198 return 0x010; | |
199 case SDLK_d: | |
200 return 0x008; | |
201 case SDLK_q: | |
202 return 0x004; | |
203 case SDLK_w: | |
204 return 0x002; | |
205 case SDLK_e: | |
206 return 0x001; | |
207 case SDLK_f: | |
208 return 0x040; | |
209 case SDLK_RETURN: | |
210 return 0x080; | |
211 case SDLK_UP: | |
212 return 0x800; | |
213 case SDLK_DOWN: | |
214 return 0x400; | |
215 case SDLK_LEFT: | |
216 return 0x200; | |
217 case SDLK_RIGHT: | |
218 return 0x100; | |
219 } | |
220 return 0; | |
221 } | |
222 | |
191 void system_poll_events() | 223 void system_poll_events() |
192 { | 224 { |
193 SDL_Event event; | 225 SDL_Event event; |
194 while(SDL_PollEvent(&event)) | 226 while(SDL_PollEvent(&event)) |
195 { | 227 { |
202 controller_pressed(event.cbutton.which, mapping[event.cbutton.button]); | 234 controller_pressed(event.cbutton.which, mapping[event.cbutton.button]); |
203 break; | 235 break; |
204 case SDL_CONTROLLERBUTTONUP: | 236 case SDL_CONTROLLERBUTTONUP: |
205 controller_released(event.cbutton.which, mapping[event.cbutton.button]); | 237 controller_released(event.cbutton.which, mapping[event.cbutton.button]); |
206 break; | 238 break; |
207 //TODO: Keyboard input | 239 case SDL_KEYDOWN: |
240 controller_pressed(0, keycode_to_bit(event.key.keysym.sym)); | |
241 break; | |
242 case SDL_KEYUP: | |
243 controller_released(0, keycode_to_bit(event.key.keysym.sym)); | |
244 break; | |
208 //TODO: Controller hotplug | 245 //TODO: Controller hotplug |
209 } | 246 } |
210 } | 247 } |
211 } | 248 } |
212 | 249 |