(PS3) Attempt again to 'fix' analog input - starts to somewhat

'work' but still can't hold left/right of the stick in a a certain
direction ahd have the character run. PS3 analog values are 'short'
but only 0-255 is actually used. Doing u8 to s16 conversion now
but it still doesn't work alright - pressing in a certain axis will
make the character 'move' only briefly. Any help would be GREATLY appreciated
so we can finally have 'working' analog controls
This commit is contained in:
twinaphex 2014-02-27 17:43:19 +01:00
parent f49f16b7fb
commit b5b8a07a17

View File

@ -36,8 +36,8 @@
#define MAX_PADS 7
#endif
#define DEADZONE_LOW 55
#define DEADZONE_HIGH 210
#define DEADZONE_LOW 105
#define DEADZONE_HIGH 145
typedef struct
{
@ -170,6 +170,16 @@ static void ps3_input_set_keybinds(void *data, unsigned device,
}
}
static void convert_u8_to_s16(int16_t *to, uint8_t *from, uint32_t samples)
{
for (uint32_t ix = 0; ix < samples; ix++)
{
int16_t diff = (*from++ << 8);
diff -= INT16_MAX;
*to++ = diff;
}
}
static void ps3_input_poll(void *data)
{
CellPadInfo2 pad_info;
@ -241,10 +251,28 @@ static void ps3_input_poll(void *data)
*state_cur |= (state_tmp.button[CELL_PAD_BTN_OFFSET_DIGITAL2] & CELL_PAD_CTRL_L2) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_L2) : 0;
*state_cur |= (state_tmp.button[CELL_PAD_BTN_OFFSET_DIGITAL2] & CELL_PAD_CTRL_L2) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_L2) : 0;
//RARCH_LOG("lsx : %d (%hd) lsy : %d (%hd) rsx : %d (%hd) rsy : %d (%hd)\n", lsx, ls_x, lsy, ls_y, rsx, rs_x, rsy, rs_y);
ps3->analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT ][RETRO_DEVICE_ID_ANALOG_X] = (int16_t)(state_tmp.button[CELL_PAD_BTN_OFFSET_ANALOG_LEFT_X] - 128) * 256;
ps3->analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT ][RETRO_DEVICE_ID_ANALOG_Y] = (int16_t)(state_tmp.button[CELL_PAD_BTN_OFFSET_ANALOG_LEFT_Y] - 128) * 256;
ps3->analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_X] = (int16_t)(state_tmp.button[CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X] - 128) * 256;
ps3->analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_Y] = (int16_t)(state_tmp.button[CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_Y] - 128) * 256;
uint8_t lsx = (uint8_t)(state_tmp.button[CELL_PAD_BTN_OFFSET_ANALOG_LEFT_X]);
uint8_t lsy = (uint8_t)(state_tmp.button[CELL_PAD_BTN_OFFSET_ANALOG_LEFT_Y]);
uint8_t rsx = (uint8_t)(state_tmp.button[CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X]);
uint8_t rsy = (uint8_t)(state_tmp.button[CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_Y]);
int16_t lsx_s16, lsy_s16, rsx_s16, rsy_s16;
if (!(lsx < DEADZONE_LOW || DEADZONE_HIGH < lsx))
lsx = 128;
if (!(lsy < DEADZONE_LOW || DEADZONE_HIGH < lsy))
lsy = 128;
if (!(rsx < DEADZONE_LOW || DEADZONE_HIGH < rsx))
rsx = 128;
if (!(rsy < DEADZONE_LOW || DEADZONE_HIGH < rsy))
rsy = 128;
convert_u8_to_s16(&lsx_s16, &lsx, 1);
convert_u8_to_s16(&lsy_s16, &lsy, 1);
convert_u8_to_s16(&rsx_s16, &rsx, 1);
convert_u8_to_s16(&rsy_s16, &rsy, 1);
ps3->analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT ][RETRO_DEVICE_ID_ANALOG_X] = lsx_s16;
ps3->analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT ][RETRO_DEVICE_ID_ANALOG_Y] = lsy_s16;
ps3->analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_X] = rsx_s16;
ps3->analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_Y] = rsy_s16;
ps3->accelerometer_state[port].x = state_tmp.button[CELL_PAD_BTN_OFFSET_SENSOR_X];
ps3->accelerometer_state[port].y = state_tmp.button[CELL_PAD_BTN_OFFSET_SENSOR_Y];
ps3->accelerometer_state[port].z = state_tmp.button[CELL_PAD_BTN_OFFSET_SENSOR_Z];