diff --git a/rpcs3/Emu/Cell/Modules/cellPad.cpp b/rpcs3/Emu/Cell/Modules/cellPad.cpp index 8cab894278..11f08bba77 100644 --- a/rpcs3/Emu/Cell/Modules/cellPad.cpp +++ b/rpcs3/Emu/Cell/Modules/cellPad.cpp @@ -3,7 +3,7 @@ #include "Emu/IdManager.h" #include "Emu/Cell/PPUModule.h" -#include "Emu/Io/PadHandler.h" +#include "pad_thread.h" #include "cellPad.h" extern logs::channel sys_io; @@ -12,7 +12,7 @@ s32 cellPadInit(u32 max_connect) { sys_io.warning("cellPadInit(max_connect=%d)", max_connect); - const auto handler = fxm::import(Emu.GetCallbacks().get_pad_handler); + const auto handler = fxm::import(Emu.GetCallbacks().get_pad_handler); if (!handler) return CELL_PAD_ERROR_ALREADY_INITIALIZED; @@ -26,7 +26,7 @@ s32 cellPadEnd() { sys_io.notice("cellPadEnd()"); - if (!fxm::remove()) + if (!fxm::remove()) return CELL_PAD_ERROR_UNINITIALIZED; return CELL_OK; @@ -36,7 +36,7 @@ s32 cellPadClearBuf(u32 port_no) { sys_io.trace("cellPadClearBuf(port_no=%d)", port_no); - const auto handler = fxm::get(); + const auto handler = fxm::get(); if (!handler) return CELL_PAD_ERROR_UNINITIALIZED; @@ -51,20 +51,20 @@ s32 cellPadClearBuf(u32 port_no) //Set 'm_buffer_cleared' to force a resend of everything //might as well also reset everything in our pad 'buffer' to nothing as well - std::vector& pads = handler->GetPads(); - Pad& pad = pads[port_no]; + auto& pads = handler->GetPads(); + auto pad = pads[port_no]; - pad.m_buffer_cleared = true; - pad.m_analog_left_x = pad.m_analog_left_y = pad.m_analog_right_x = pad.m_analog_right_y = 128; + pad->m_buffer_cleared = true; + pad->m_analog_left_x = pad->m_analog_left_y = pad->m_analog_right_x = pad->m_analog_right_y = 128; - pad.m_digital_1 = pad.m_digital_2 = 0; - pad.m_press_right = pad.m_press_left = pad.m_press_up = pad.m_press_down = 0; - pad.m_press_triangle = pad.m_press_circle = pad.m_press_cross = pad.m_press_square = 0; - pad.m_press_L1 = pad.m_press_L2 = pad.m_press_R1 = pad.m_press_R2 = 0; + pad->m_digital_1 = pad->m_digital_2 = 0; + pad->m_press_right = pad->m_press_left = pad->m_press_up = pad->m_press_down = 0; + pad->m_press_triangle = pad->m_press_circle = pad->m_press_cross = pad->m_press_square = 0; + pad->m_press_L1 = pad->m_press_L2 = pad->m_press_R1 = pad->m_press_R2 = 0; //~399 on sensor y is a level non moving controller - pad.m_sensor_y = 399; - pad.m_sensor_x = pad.m_sensor_z = pad.m_sensor_g = 512; + pad->m_sensor_y = 399; + pad->m_sensor_x = pad->m_sensor_z = pad->m_sensor_g = 512; return CELL_OK; } @@ -73,12 +73,12 @@ s32 cellPadGetData(u32 port_no, vm::ptr data) { sys_io.trace("cellPadGetData(port_no=%d, data=*0x%x)", port_no, data); - const auto handler = fxm::get(); + const auto handler = fxm::get(); if (!handler) return CELL_PAD_ERROR_UNINITIALIZED; - std::vector& pads = handler->GetPads(); + auto& pads = handler->GetPads(); const PadInfo& rinfo = handler->GetInfo(); @@ -89,39 +89,39 @@ s32 cellPadGetData(u32 port_no, vm::ptr data) if (port_no >= rinfo.now_connect) return CELL_PAD_ERROR_NO_DEVICE; - Pad& pad = pads[port_no]; + auto pad = pads[port_no]; u16 d1Initial, d2Initial; - d1Initial = pad.m_digital_1; - d2Initial = pad.m_digital_2; + d1Initial = pad->m_digital_1; + d2Initial = pad->m_digital_2; bool btnChanged = false; - for(Button& button : pad.m_buttons) + for(Button& button : pad->m_buttons) { //here we check btns, and set pad accordingly, //if something changed, set btnChanged if (button.m_offset == CELL_PAD_BTN_OFFSET_DIGITAL1) { - if (button.m_pressed) pad.m_digital_1 |= button.m_outKeyCode; - else pad.m_digital_1 &= ~button.m_outKeyCode; + if (button.m_pressed) pad->m_digital_1 |= button.m_outKeyCode; + else pad->m_digital_1 &= ~button.m_outKeyCode; switch (button.m_outKeyCode) { case CELL_PAD_CTRL_LEFT: - if (pad.m_press_left != button.m_value) btnChanged = true; - pad.m_press_left = button.m_value; + if (pad->m_press_left != button.m_value) btnChanged = true; + pad->m_press_left = button.m_value; break; case CELL_PAD_CTRL_DOWN: - if (pad.m_press_down != button.m_value) btnChanged = true; - pad.m_press_down = button.m_value; + if (pad->m_press_down != button.m_value) btnChanged = true; + pad->m_press_down = button.m_value; break; case CELL_PAD_CTRL_RIGHT: - if (pad.m_press_right != button.m_value) btnChanged = true; - pad.m_press_right = button.m_value; + if (pad->m_press_right != button.m_value) btnChanged = true; + pad->m_press_right = button.m_value; break; case CELL_PAD_CTRL_UP: - if (pad.m_press_up != button.m_value) btnChanged = true; - pad.m_press_up = button.m_value; + if (pad->m_press_up != button.m_value) btnChanged = true; + pad->m_press_up = button.m_value; break; //These arent pressure btns case CELL_PAD_CTRL_R3: @@ -133,42 +133,42 @@ s32 cellPadGetData(u32 port_no, vm::ptr data) } else if (button.m_offset == CELL_PAD_BTN_OFFSET_DIGITAL2) { - if (button.m_pressed) pad.m_digital_2 |= button.m_outKeyCode; - else pad.m_digital_2 &= ~button.m_outKeyCode; + if (button.m_pressed) pad->m_digital_2 |= button.m_outKeyCode; + else pad->m_digital_2 &= ~button.m_outKeyCode; switch (button.m_outKeyCode) { case CELL_PAD_CTRL_SQUARE: - if (pad.m_press_square != button.m_value) btnChanged = true; - pad.m_press_square = button.m_value; + if (pad->m_press_square != button.m_value) btnChanged = true; + pad->m_press_square = button.m_value; break; case CELL_PAD_CTRL_CROSS: - if (pad.m_press_cross != button.m_value) btnChanged = true; - pad.m_press_cross = button.m_value; + if (pad->m_press_cross != button.m_value) btnChanged = true; + pad->m_press_cross = button.m_value; break; case CELL_PAD_CTRL_CIRCLE: - if (pad.m_press_circle != button.m_value) btnChanged = true; - pad.m_press_circle = button.m_value; + if (pad->m_press_circle != button.m_value) btnChanged = true; + pad->m_press_circle = button.m_value; break; case CELL_PAD_CTRL_TRIANGLE: - if (pad.m_press_triangle != button.m_value) btnChanged = true; - pad.m_press_triangle = button.m_value; + if (pad->m_press_triangle != button.m_value) btnChanged = true; + pad->m_press_triangle = button.m_value; break; case CELL_PAD_CTRL_R1: - if (pad.m_press_R1 != button.m_value) btnChanged = true; - pad.m_press_R1 = button.m_value; + if (pad->m_press_R1 != button.m_value) btnChanged = true; + pad->m_press_R1 = button.m_value; break; case CELL_PAD_CTRL_L1: - if (pad.m_press_L1 != button.m_value) btnChanged = true; - pad.m_press_L1 = button.m_value; + if (pad->m_press_L1 != button.m_value) btnChanged = true; + pad->m_press_L1 = button.m_value; break; case CELL_PAD_CTRL_R2: - if (pad.m_press_R2 != button.m_value) btnChanged = true; - pad.m_press_R2 = button.m_value; + if (pad->m_press_R2 != button.m_value) btnChanged = true; + pad->m_press_R2 = button.m_value; break; case CELL_PAD_CTRL_L2: - if (pad.m_press_L2 != button.m_value) btnChanged = true; - pad.m_press_L2 = button.m_value; + if (pad->m_press_L2 != button.m_value) btnChanged = true; + pad->m_press_L2 = button.m_value; break; default: break; } @@ -182,55 +182,55 @@ s32 cellPadGetData(u32 port_no, vm::ptr data) } } - for (const AnalogStick& stick : pad.m_sticks) + for (const AnalogStick& stick : pad->m_sticks) { switch (stick.m_offset) { case CELL_PAD_BTN_OFFSET_ANALOG_LEFT_X: - if (pad.m_analog_left_x != stick.m_value) btnChanged = true; - pad.m_analog_left_x = stick.m_value; + if (pad->m_analog_left_x != stick.m_value) btnChanged = true; + pad->m_analog_left_x = stick.m_value; break; case CELL_PAD_BTN_OFFSET_ANALOG_LEFT_Y: - if (pad.m_analog_left_y != stick.m_value) btnChanged = true; - pad.m_analog_left_y = stick.m_value; + if (pad->m_analog_left_y != stick.m_value) btnChanged = true; + pad->m_analog_left_y = stick.m_value; break; case CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X: - if (pad.m_analog_right_x != stick.m_value) btnChanged = true; - pad.m_analog_right_x = stick.m_value; + if (pad->m_analog_right_x != stick.m_value) btnChanged = true; + pad->m_analog_right_x = stick.m_value; break; case CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_Y: - if (pad.m_analog_right_y != stick.m_value) btnChanged = true; - pad.m_analog_right_y = stick.m_value; + if (pad->m_analog_right_y != stick.m_value) btnChanged = true; + pad->m_analog_right_y = stick.m_value; break; default: break; } } - for (const AnalogSensor& sensor : pad.m_sensors) + for (const AnalogSensor& sensor : pad->m_sensors) { switch (sensor.m_offset) { case CELL_PAD_BTN_OFFSET_SENSOR_X: - if (pad.m_sensor_x != sensor.m_value) btnChanged = true; - pad.m_sensor_x = sensor.m_value; + if (pad->m_sensor_x != sensor.m_value) btnChanged = true; + pad->m_sensor_x = sensor.m_value; break; case CELL_PAD_BTN_OFFSET_SENSOR_Y: - if (pad.m_sensor_y != sensor.m_value) btnChanged = true; - pad.m_sensor_y = sensor.m_value; + if (pad->m_sensor_y != sensor.m_value) btnChanged = true; + pad->m_sensor_y = sensor.m_value; break; case CELL_PAD_BTN_OFFSET_SENSOR_Z: - if (pad.m_sensor_z != sensor.m_value) btnChanged = true; - pad.m_sensor_z = sensor.m_value; + if (pad->m_sensor_z != sensor.m_value) btnChanged = true; + pad->m_sensor_z = sensor.m_value; break; case CELL_PAD_BTN_OFFSET_SENSOR_G: - if (pad.m_sensor_g != sensor.m_value) btnChanged = true; - pad.m_sensor_g = sensor.m_value; + if (pad->m_sensor_g != sensor.m_value) btnChanged = true; + pad->m_sensor_g = sensor.m_value; 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; } @@ -238,9 +238,9 @@ s32 cellPadGetData(u32 port_no, vm::ptr data) //not sure if this should officially change with capabilities/portsettings :( data->len = 24; - if (pad.m_buffer_cleared) + if (pad->m_buffer_cleared) { - pad.m_buffer_cleared = false; + pad->m_buffer_cleared = false; } else if (!btnChanged) { @@ -250,28 +250,28 @@ s32 cellPadGetData(u32 port_no, vm::ptr data) // bits 15-8 reserved, 7-4 = 0x7, 3-0: data->len/2; data->button[1] = (0x7 << 4) | std::min(data->len / 2, 15); //lets still send new data anyway, not sure whats expected still - data->button[CELL_PAD_BTN_OFFSET_DIGITAL1] = pad.m_digital_1; - data->button[CELL_PAD_BTN_OFFSET_DIGITAL2] = pad.m_digital_2; - data->button[CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X] = pad.m_analog_right_x; - 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_Y] = pad.m_analog_left_y; - 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_UP] = pad.m_press_up; - data->button[CELL_PAD_BTN_OFFSET_PRESS_DOWN] = pad.m_press_down; - 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_CROSS] = pad.m_press_cross; - data->button[CELL_PAD_BTN_OFFSET_PRESS_SQUARE] = pad.m_press_square; - data->button[CELL_PAD_BTN_OFFSET_PRESS_L1] = pad.m_press_L1; - data->button[CELL_PAD_BTN_OFFSET_PRESS_L2] = pad.m_press_L2; - 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_SENSOR_X] = pad.m_sensor_x; - data->button[CELL_PAD_BTN_OFFSET_SENSOR_Y] = pad.m_sensor_y; - 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_DIGITAL1] = pad->m_digital_1; + data->button[CELL_PAD_BTN_OFFSET_DIGITAL2] = pad->m_digital_2; + data->button[CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X] = pad->m_analog_right_x; + 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_Y] = pad->m_analog_left_y; + 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_UP] = pad->m_press_up; + data->button[CELL_PAD_BTN_OFFSET_PRESS_DOWN] = pad->m_press_down; + 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_CROSS] = pad->m_press_cross; + data->button[CELL_PAD_BTN_OFFSET_PRESS_SQUARE] = pad->m_press_square; + data->button[CELL_PAD_BTN_OFFSET_PRESS_L1] = pad->m_press_L1; + data->button[CELL_PAD_BTN_OFFSET_PRESS_L2] = pad->m_press_L2; + 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_SENSOR_X] = pad->m_sensor_x; + data->button[CELL_PAD_BTN_OFFSET_SENSOR_Y] = pad->m_sensor_y; + data->button[CELL_PAD_BTN_OFFSET_SENSOR_Z] = pad->m_sensor_z; + data->button[CELL_PAD_BTN_OFFSET_SENSOR_G] = pad->m_sensor_g; return CELL_OK; } @@ -280,7 +280,7 @@ s32 cellPadPeriphGetInfo(vm::ptr info) { sys_io.trace("cellPadPeriphGetInfo(info=*0x%x)", info); - const auto handler = fxm::get(); + const auto handler = fxm::get(); if (!handler) return CELL_PAD_ERROR_UNINITIALIZED; @@ -293,7 +293,7 @@ s32 cellPadPeriphGetInfo(vm::ptr info) info->now_connect = rinfo.now_connect; info->system_info = rinfo.system_info; - std::vector& pads = handler->GetPads(); + auto& pads = handler->GetPads(); // TODO: Support other types of controllers for (u32 i = 0; i < CELL_PAD_MAX_PORT_NUM; ++i) @@ -301,10 +301,10 @@ s32 cellPadPeriphGetInfo(vm::ptr info) if (i >= pads.size()) break; - info->port_status[i] = pads[i].m_port_status; - info->port_setting[i] = pads[i].m_port_setting; - info->device_capability[i] = pads[i].m_device_capability; - info->device_type[i] = pads[i].m_device_type; + info->port_status[i] = pads[i]->m_port_status; + info->port_setting[i] = pads[i]->m_port_setting; + info->device_capability[i] = pads[i]->m_device_capability; + info->device_type[i] = pads[i]->m_device_type; info->pclass_type[i] = CELL_PAD_PCLASS_TYPE_STANDARD; info->pclass_profile[i] = 0x0; } @@ -315,7 +315,7 @@ s32 cellPadPeriphGetInfo(vm::ptr info) s32 cellPadPeriphGetData(u32 port_no, vm::ptr data) { sys_io.trace("cellPadPeriphGetData(port_no=%d, data=*0x%x)", port_no, data); - const auto handler = fxm::get(); + const auto handler = fxm::get(); if (!handler) return CELL_PAD_ERROR_UNINITIALIZED; @@ -342,7 +342,7 @@ s32 cellPadGetDataExtra(u32 port_no, vm::ptr device_type, vm::ptr(); + const auto handler = fxm::get(); if (!handler) return CELL_PAD_ERROR_UNINITIALIZED; @@ -370,7 +370,7 @@ s32 cellPadSetActDirect(u32 port_no, vm::ptr param) { sys_io.trace("cellPadSetActDirect(port_no=%d, param=*0x%x)", port_no, param); - const auto handler = fxm::get(); + const auto handler = fxm::get(); if (!handler) return CELL_PAD_ERROR_UNINITIALIZED; @@ -391,7 +391,7 @@ s32 cellPadGetInfo(vm::ptr info) { sys_io.trace("cellPadGetInfo(info=*0x%x)", info); - const auto handler = fxm::get(); + const auto handler = fxm::get(); if (!handler) return CELL_PAD_ERROR_UNINITIALIZED; @@ -403,15 +403,15 @@ s32 cellPadGetInfo(vm::ptr info) info->now_connect = rinfo.now_connect; info->system_info = rinfo.system_info; - std::vector& pads = handler->GetPads(); + auto& pads = handler->GetPads(); for (u32 i=0; i= pads.size()) break; - info->status[i] = pads[i].m_port_status; - pads[i].m_port_status &= ~CELL_PAD_STATUS_ASSIGN_CHANGES; + info->status[i] = pads[i]->m_port_status; + pads[i]->m_port_status &= ~CELL_PAD_STATUS_ASSIGN_CHANGES; info->product_id[i] = 0x0268; info->vendor_id[i] = 0x054C; } @@ -423,7 +423,7 @@ s32 cellPadGetInfo2(vm::ptr info) { sys_io.trace("cellPadGetInfo2(info=*0x%x)", info); - const auto handler = fxm::get(); + const auto handler = fxm::get(); if (!handler) return CELL_PAD_ERROR_UNINITIALIZED; @@ -435,18 +435,18 @@ s32 cellPadGetInfo2(vm::ptr info) info->now_connect = rinfo.now_connect; info->system_info = rinfo.system_info; - std::vector& pads = handler->GetPads(); + auto& pads = handler->GetPads(); for (u32 i=0; i= pads.size()) break; - info->port_status[i] = pads[i].m_port_status; - pads[i].m_port_status &= ~CELL_PAD_STATUS_ASSIGN_CHANGES; - info->port_setting[i] = pads[i].m_port_setting; - info->device_capability[i] = pads[i].m_device_capability; - info->device_type[i] = pads[i].m_device_type; + info->port_status[i] = pads[i]->m_port_status; + pads[i]->m_port_status &= ~CELL_PAD_STATUS_ASSIGN_CHANGES; + info->port_setting[i] = pads[i]->m_port_setting; + info->device_capability[i] = pads[i]->m_device_capability; + info->device_type[i] = pads[i]->m_device_type; } return CELL_OK; @@ -456,7 +456,7 @@ s32 cellPadGetCapabilityInfo(u32 port_no, vm::ptr info) { sys_io.trace("cellPadGetCapabilityInfo(port_no=%d, data_addr:=0x%x)", port_no, info.addr()); - const auto handler = fxm::get(); + const auto handler = fxm::get(); if (!handler) return CELL_PAD_ERROR_UNINITIALIZED; @@ -468,10 +468,10 @@ s32 cellPadGetCapabilityInfo(u32 port_no, vm::ptr info) if (port_no >= rinfo.now_connect) return CELL_PAD_ERROR_NO_DEVICE; - const std::vector& pads = handler->GetPads(); + const auto& pads = handler->GetPads(); - //Should return the same as device capability mask, psl1ght has it backwards in pad.h - info->info[0] = pads[port_no].m_device_capability; + //Should return the same as device capability mask, psl1ght has it backwards in pad->h + info->info[0] = pads[port_no]->m_device_capability; return CELL_OK; } @@ -480,7 +480,7 @@ s32 cellPadSetPortSetting(u32 port_no, u32 port_setting) { sys_io.trace("cellPadSetPortSetting(port_no=%d, port_setting=0x%x)", port_no, port_setting); - const auto handler = fxm::get(); + const auto handler = fxm::get(); if (!handler) return CELL_PAD_ERROR_UNINITIALIZED; @@ -492,8 +492,8 @@ s32 cellPadSetPortSetting(u32 port_no, u32 port_setting) if (port_no >= rinfo.now_connect) return CELL_PAD_ERROR_NO_DEVICE; - std::vector& pads = handler->GetPads(); - pads[port_no].m_port_setting = port_setting; + auto& pads = handler->GetPads(); + pads[port_no]->m_port_setting = port_setting; return CELL_OK; } @@ -502,7 +502,7 @@ s32 cellPadInfoPressMode(u32 port_no) { sys_io.trace("cellPadInfoPressMode(port_no=%d)", port_no); - const auto handler = fxm::get(); + const auto handler = fxm::get(); if (!handler) return CELL_PAD_ERROR_UNINITIALIZED; @@ -514,16 +514,16 @@ s32 cellPadInfoPressMode(u32 port_no) if (port_no >= rinfo.now_connect) return CELL_PAD_ERROR_NO_DEVICE; - const std::vector& pads = handler->GetPads(); + const auto& pads = handler->GetPads(); - return (pads[port_no].m_device_capability & CELL_PAD_CAPABILITY_PRESS_MODE) > 0; + return (pads[port_no]->m_device_capability & CELL_PAD_CAPABILITY_PRESS_MODE) > 0; } s32 cellPadInfoSensorMode(u32 port_no) { sys_io.trace("cellPadInfoSensorMode(port_no=%d)", port_no); - const auto handler = fxm::get(); + const auto handler = fxm::get(); if (!handler) return CELL_PAD_ERROR_UNINITIALIZED; @@ -535,16 +535,16 @@ s32 cellPadInfoSensorMode(u32 port_no) if (port_no >= rinfo.now_connect) return CELL_PAD_ERROR_NO_DEVICE; - const std::vector& pads = handler->GetPads(); + const auto& pads = handler->GetPads(); - return (pads[port_no].m_device_capability & CELL_PAD_CAPABILITY_SENSOR_MODE) > 0; + return (pads[port_no]->m_device_capability & CELL_PAD_CAPABILITY_SENSOR_MODE) > 0; } s32 cellPadSetPressMode(u32 port_no, u32 mode) { sys_io.trace("cellPadSetPressMode(port_no=%d, mode=%d)", port_no, mode); - const auto handler = fxm::get(); + const auto handler = fxm::get(); if (!handler) return CELL_PAD_ERROR_UNINITIALIZED; @@ -559,12 +559,12 @@ s32 cellPadSetPressMode(u32 port_no, u32 mode) if (port_no >= rinfo.now_connect) return CELL_PAD_ERROR_NO_DEVICE; - std::vector& pads = handler->GetPads(); + auto& pads = handler->GetPads(); if (mode) - pads[port_no].m_port_setting |= CELL_PAD_SETTING_PRESS_ON; + pads[port_no]->m_port_setting |= CELL_PAD_SETTING_PRESS_ON; else - pads[port_no].m_port_setting &= ~CELL_PAD_SETTING_PRESS_ON; + pads[port_no]->m_port_setting &= ~CELL_PAD_SETTING_PRESS_ON; return CELL_OK; } @@ -573,7 +573,7 @@ s32 cellPadSetSensorMode(u32 port_no, u32 mode) { sys_io.trace("cellPadSetSensorMode(port_no=%d, mode=%d)", port_no, mode); - const auto handler = fxm::get(); + const auto handler = fxm::get(); if (!handler) return CELL_PAD_ERROR_UNINITIALIZED; @@ -588,12 +588,12 @@ s32 cellPadSetSensorMode(u32 port_no, u32 mode) if (port_no >= rinfo.now_connect) return CELL_PAD_ERROR_NO_DEVICE; - std::vector& pads = handler->GetPads(); + auto& pads = handler->GetPads(); if (mode) - pads[port_no].m_port_setting |= CELL_PAD_SETTING_SENSOR_ON; + pads[port_no]->m_port_setting |= CELL_PAD_SETTING_SENSOR_ON; else - pads[port_no].m_port_setting &= ~CELL_PAD_SETTING_SENSOR_ON; + pads[port_no]->m_port_setting &= ~CELL_PAD_SETTING_SENSOR_ON; return CELL_OK; } @@ -602,7 +602,7 @@ s32 cellPadLddRegisterController() { sys_io.todo("cellPadLddRegisterController()"); - const auto handler = fxm::get(); + const auto handler = fxm::get(); if (!handler) return CELL_PAD_ERROR_UNINITIALIZED; @@ -614,7 +614,7 @@ s32 cellPadLddDataInsert(s32 handle, vm::ptr data) { sys_io.todo("cellPadLddDataInsert(handle=%d, data=*0x%x)", handle, data); - const auto handler = fxm::get(); + const auto handler = fxm::get(); if (!handler) return CELL_PAD_ERROR_UNINITIALIZED; @@ -626,7 +626,7 @@ s32 cellPadLddGetPortNo(s32 handle) { sys_io.todo("cellPadLddGetPortNo(handle=%d)", handle); - const auto handler = fxm::get(); + const auto handler = fxm::get(); if (!handler) return CELL_PAD_ERROR_UNINITIALIZED; @@ -638,7 +638,7 @@ s32 cellPadLddUnregisterController(s32 handle) { sys_io.todo("cellPadLddUnregisterController(handle=%d)", handle); - const auto handler = fxm::get(); + const auto handler = fxm::get(); if (!handler) return CELL_PAD_ERROR_UNINITIALIZED; diff --git a/rpcs3/Emu/Io/Null/NullPadHandler.h b/rpcs3/Emu/Io/Null/NullPadHandler.h index 2f72cf7607..7fb25a487f 100644 --- a/rpcs3/Emu/Io/Null/NullPadHandler.h +++ b/rpcs3/Emu/Io/Null/NullPadHandler.h @@ -5,10 +5,25 @@ class NullPadHandler final : public PadHandlerBase { public: - void Init(const u32 max_connect) override + bool Init() override { - memset(&m_info, 0, sizeof(PadInfo)); - m_info.max_connect = max_connect; - m_pads.clear(); + return true; } + + std::vector ListDevices() override + { + std::vector nulllist; + nulllist.push_back("Default Null Device"); + return nulllist; + } + + bool bindPadToDevice(std::shared_ptr pad, const std::string& device) override + { + return true; + } + + void ThreadProc() override + { + } + }; diff --git a/rpcs3/Emu/Io/PadHandler.h b/rpcs3/Emu/Io/PadHandler.h index b28eee99f8..288665180a 100644 --- a/rpcs3/Emu/Io/PadHandler.h +++ b/rpcs3/Emu/Io/PadHandler.h @@ -1,5 +1,9 @@ #pragma once +#include +#include +#include "../../Utilities/types.h" + // TODO: HLE info (constants, structs, etc.) should not be available here enum PortStatus @@ -190,6 +194,14 @@ struct Pad u16 m_sensor_z; u16 m_sensor_g; + void Init(u32 port_status, u32 port_setting, u32 device_capability, u32 device_type) + { + m_port_status = port_status; + m_port_setting = port_setting; + m_device_capability = device_capability; + m_device_type = device_type; + } + Pad(u32 port_status, u32 port_setting, u32 device_capability, u32 device_type) : m_buffer_cleared(true) , m_port_status(port_status) @@ -226,79 +238,23 @@ struct Pad } }; -struct PadInfo -{ - u32 max_connect; - u32 now_connect; - u32 system_info; -}; - class PadHandlerBase { protected: - PadInfo m_info; - std::vector m_pads; + bool b_has_config = false; public: - virtual void Init(const u32 max_connect) = 0; + virtual bool Init() { return true; }; virtual ~PadHandlerBase() = default; - //Set value to set pressure/axi to certain level, otherwise 0/255 default - void Key(const u32 code, bool pressed, u16 value=255) - { - for(Pad& pad : m_pads) - { - for (Button& button : pad.m_buttons) - { - if (button.m_keyCode != code) - continue; - - if (value >= 256){ value = 255; } - - //Todo: Is this flush necessary once games hit decent speeds? - if (button.m_pressed && !pressed) - { - button.m_flush = true; - - } - else - { - button.m_pressed = pressed; - if (pressed) - button.m_value = value; - else - button.m_value = 0; - } - } - - for(AnalogStick& stick : pad.m_sticks) - { - if (stick.m_keyCodeMax != code && stick.m_keyCodeMin != code) - continue; - - //slightly less hack job for key based analog stick - // should also fix/make transitions when using keys smoother - // the logic here is that when a key is released, - // if we are at the opposite end of the axis, dont reset to middle - if (stick.m_keyCodeMax == code) - { - if (pressed) stick.m_value = 255; - else if (stick.m_value==0) stick.m_value = 0; - else stick.m_value = 128; - } - if (stick.m_keyCodeMin == code) - { - if (pressed) stick.m_value = 0; - else if (stick.m_value == 255) stick.m_value = 255; - else stick.m_value = 128; - } - } - } - } - - virtual PadInfo& GetInfo() { return m_info; } - virtual std::vector& GetPads() { return m_pads; } - virtual void SetRumble(const u32 pad, u8 largeMotor, bool smallMotor) {}; - std::vector