| @@ -117,6 +117,34 @@ static int sdl_input_update(nes_Input_Reader* reader, | |||||
| } | } | ||||
| } | } | ||||
| } else if (SDL_CONTROLLERAXISMOTION == event.type) { | |||||
| const uint8_t axis = event.caxis.axis; | |||||
| const int16_t value = event.caxis.value; | |||||
| uint8_t mask_set = 0; | |||||
| uint8_t mask_clear = 0; | |||||
| if (SDL_CONTROLLER_AXIS_LEFTX == axis) { | |||||
| mask_clear = (1 << Button_Left) | | |||||
| (1 << Button_Right); | |||||
| if (value <= -8192) { | |||||
| mask_set = (1 << Button_Left); | |||||
| } else if (value >= 8192) { | |||||
| mask_set = (1 << Button_Right); | |||||
| } | |||||
| } else if (SDL_CONTROLLER_AXIS_LEFTY == axis) { | |||||
| mask_clear = (1 << Button_Down) | | |||||
| (1 << Button_Up); | |||||
| if (value <= -8192) { | |||||
| mask_set = (1 << Button_Up); | |||||
| } else if (value >= 8192) { | |||||
| mask_set = (1 << Button_Down); | |||||
| } | |||||
| } | |||||
| input->controllers[0].buttons &= ~mask_clear; | |||||
| input->controllers[0].buttons |= mask_set; | |||||
| } else if (SDL_CONTROLLERDEVICEADDED == event.type) { | } else if (SDL_CONTROLLERDEVICEADDED == event.type) { | ||||
| if (NULL == reader->data) { | if (NULL == reader->data) { | ||||
| reader->data = sdl_find_gamepad(); | reader->data = sdl_find_gamepad(); | ||||