Fix cellPadGetData

* Remove complete buffer clear
* If pressure sensitivity option is not specified, write zeroes (should this be handled from our actual controller handler?)
* Check sensor setting before reporting changes
This commit is contained in:
eladash 2018-11-05 21:34:40 +02:00 committed by kd-11
parent 3332a10052
commit 90f816595a
1 changed files with 50 additions and 44 deletions

View File

@ -237,6 +237,8 @@ error_code cellPadGetData(u32 port_no, vm::ptr<CellPadData> data)
} }
} }
if (pad->m_port_setting & CELL_PAD_SETTING_SENSOR_ON)
{
for (const AnalogSensor& sensor : pad->m_sensors) for (const AnalogSensor& sensor : pad->m_sensors)
{ {
switch (sensor.m_offset) switch (sensor.m_offset)
@ -260,13 +262,13 @@ error_code cellPadGetData(u32 port_no, vm::ptr<CellPadData> data)
default: break; default: break;
} }
} }
}
if (d1Initial != pad->m_digital_1 || d2Initial != pad->m_digital_2) if (d1Initial != pad->m_digital_1 || d2Initial != pad->m_digital_2)
{ {
btnChanged = true; btnChanged = true;
} }
// the real hardware only fills the buffer up to "len" elements (16 bit each)
if (pad->m_port_setting & CELL_PAD_SETTING_SENSOR_ON) if (pad->m_port_setting & CELL_PAD_SETTING_SENSOR_ON)
{ {
// report back new data every ~10 ms even if the input doesn't change // report back new data every ~10 ms even if the input doesn't change
@ -300,8 +302,6 @@ error_code cellPadGetData(u32 port_no, vm::ptr<CellPadData> data)
// only update parts of the output struct depending on the controller setting // only update parts of the output struct depending on the controller setting
if (data->len > CELL_PAD_LEN_NO_CHANGE) if (data->len > CELL_PAD_LEN_NO_CHANGE)
{ {
memset(data->button, 0, sizeof(data->button));
data->button[0] = 0x0; // always 0 data->button[0] = 0x0; // always 0
// bits 15-8 reserved, 7-4 = 0x7, 3-0: data->len/2; // bits 15-8 reserved, 7-4 = 0x7, 3-0: data->len/2;
data->button[1] = (0x7 << 4) | std::min(data->len / 2, 15); data->button[1] = (0x7 << 4) | std::min(data->len / 2, 15);
@ -312,14 +312,13 @@ error_code cellPadGetData(u32 port_no, vm::ptr<CellPadData> data)
data->button[CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_Y] = pad->m_analog_right_y; data->button[CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_Y] = pad->m_analog_right_y;
data->button[CELL_PAD_BTN_OFFSET_ANALOG_LEFT_X] = pad->m_analog_left_x; data->button[CELL_PAD_BTN_OFFSET_ANALOG_LEFT_X] = pad->m_analog_left_x;
data->button[CELL_PAD_BTN_OFFSET_ANALOG_LEFT_Y] = pad->m_analog_left_y; data->button[CELL_PAD_BTN_OFFSET_ANALOG_LEFT_Y] = pad->m_analog_left_y;
if (pad->m_port_setting & CELL_PAD_SETTING_PRESS_ON)
{
data->button[CELL_PAD_BTN_OFFSET_PRESS_RIGHT] = pad->m_press_right; data->button[CELL_PAD_BTN_OFFSET_PRESS_RIGHT] = pad->m_press_right;
data->button[CELL_PAD_BTN_OFFSET_PRESS_LEFT] = pad->m_press_left; data->button[CELL_PAD_BTN_OFFSET_PRESS_LEFT] = pad->m_press_left;
data->button[CELL_PAD_BTN_OFFSET_PRESS_UP] = pad->m_press_up; data->button[CELL_PAD_BTN_OFFSET_PRESS_UP] = pad->m_press_up;
data->button[CELL_PAD_BTN_OFFSET_PRESS_DOWN] = pad->m_press_down; data->button[CELL_PAD_BTN_OFFSET_PRESS_DOWN] = pad->m_press_down;
}
if (data->len >= CELL_PAD_LEN_CHANGE_PRESS_ON)
{
data->button[CELL_PAD_BTN_OFFSET_PRESS_TRIANGLE] = pad->m_press_triangle; data->button[CELL_PAD_BTN_OFFSET_PRESS_TRIANGLE] = pad->m_press_triangle;
data->button[CELL_PAD_BTN_OFFSET_PRESS_CIRCLE] = pad->m_press_circle; data->button[CELL_PAD_BTN_OFFSET_PRESS_CIRCLE] = pad->m_press_circle;
data->button[CELL_PAD_BTN_OFFSET_PRESS_CROSS] = pad->m_press_cross; data->button[CELL_PAD_BTN_OFFSET_PRESS_CROSS] = pad->m_press_cross;
@ -329,6 +328,12 @@ error_code cellPadGetData(u32 port_no, vm::ptr<CellPadData> data)
data->button[CELL_PAD_BTN_OFFSET_PRESS_R1] = pad->m_press_R1; data->button[CELL_PAD_BTN_OFFSET_PRESS_R1] = pad->m_press_R1;
data->button[CELL_PAD_BTN_OFFSET_PRESS_R2] = pad->m_press_R2; data->button[CELL_PAD_BTN_OFFSET_PRESS_R2] = pad->m_press_R2;
} }
else
{
// Clear area if setting is not used
constexpr u32 area_lengh = (CELL_PAD_LEN_CHANGE_PRESS_ON - CELL_PAD_LEN_CHANGE_DEFAULT) * sizeof(u16);
std::memset(&data->button[CELL_PAD_LEN_CHANGE_DEFAULT], 0, area_lengh);
}
if (data->len == CELL_PAD_LEN_CHANGE_SENSOR_ON) if (data->len == CELL_PAD_LEN_CHANGE_SENSOR_ON)
{ {
@ -337,6 +342,7 @@ error_code cellPadGetData(u32 port_no, vm::ptr<CellPadData> data)
data->button[CELL_PAD_BTN_OFFSET_SENSOR_Z] = pad->m_sensor_z; data->button[CELL_PAD_BTN_OFFSET_SENSOR_Z] = pad->m_sensor_z;
data->button[CELL_PAD_BTN_OFFSET_SENSOR_G] = pad->m_sensor_g; data->button[CELL_PAD_BTN_OFFSET_SENSOR_G] = pad->m_sensor_g;
} }
}
return CELL_OK; return CELL_OK;
} }