diff --git a/rpcs3/Emu/Cell/Modules/cellGem.cpp b/rpcs3/Emu/Cell/Modules/cellGem.cpp index fa48caabce..f84a67e45d 100644 --- a/rpcs3/Emu/Cell/Modules/cellGem.cpp +++ b/rpcs3/Emu/Cell/Modules/cellGem.cpp @@ -235,7 +235,7 @@ static bool ds3_input_to_pad(const u32 port_no, be_t& digital_buttons, be_t } /** - * \brief Maps external Move controller data to DS3 input + * \brief Maps external Move controller data to DS3 input. (This can be input from any physical pad, not just the DS3) * Implementation detail: CellGemExtPortData's digital/analog fields map the same way as * libPad, so no translation is needed. * \param port_no DS3 port number to use @@ -322,12 +322,12 @@ static bool mouse_pos_to_gem_image_state(const u32 mouse_no, vm::ptr(rsx::get_current_renderer()); const auto width = renderer->get_frame()->client_width(); - const auto hight = renderer->get_frame()->client_height(); + const auto height = renderer->get_frame()->client_height(); const f32 scaling_width = width / 640.f; - const f32 scaling_hight = hight / 480.f; + const f32 scaling_height = height / 480.f; const f32 x = static_cast(mouse.x_pos) / scaling_width; - const f32 y = static_cast(mouse.y_pos) / scaling_hight; + const f32 y = static_cast(mouse.y_pos) / scaling_height; gem_image_state->u = 133.f + (x / 1.50f); gem_image_state->v = 160.f + (y / 1.67f); @@ -352,12 +352,12 @@ static bool mouse_pos_to_gem_state(const u32 mouse_no, vm::ptr& ge const auto renderer = static_cast(rsx::get_current_renderer()); const auto width = renderer->get_frame()->client_width(); - const auto hight = renderer->get_frame()->client_height(); + const auto height = renderer->get_frame()->client_height(); const f32 scaling_width = width / 640.f; - const f32 scaling_hight = hight / 480.f; + const f32 scaling_height = height / 480.f; const f32 x = static_cast(mouse.x_pos) / scaling_width; - const f32 y = static_cast(mouse.y_pos) / scaling_hight; + const f32 y = static_cast(mouse.y_pos) / scaling_height; gem_state->pos[0] = x; gem_state->pos[1] = -y; @@ -682,18 +682,6 @@ error_code cellGemGetImageState(u32 gem_num, vm::ptr gem_imag auto& shared_data = g_fxo->get(); - if (g_cfg.io.move == move_handler::fake) - { - gem_image_state->u = 0; - gem_image_state->v = 0; - gem_image_state->projectionx = 1; - gem_image_state->projectiony = 1; - } - else if (g_cfg.io.move == move_handler::mouse) - { - mouse_pos_to_gem_image_state(gem_num, gem_image_state); - } - if (g_cfg.io.move == move_handler::fake || g_cfg.io.move == move_handler::mouse) { gem_image_state->frame_timestamp = shared_data.frame_timestamp.load(); @@ -702,6 +690,18 @@ error_code cellGemGetImageState(u32 gem_num, vm::ptr gem_imag gem_image_state->distance = 2 * 1000; // 2 meters away from camera gem_image_state->visible = true; gem_image_state->r_valid = true; + + if (g_cfg.io.move == move_handler::fake) + { + gem_image_state->u = 0; + gem_image_state->v = 0; + gem_image_state->projectionx = 1; + gem_image_state->projectiony = 1; + } + else if (g_cfg.io.move == move_handler::mouse) + { + mouse_pos_to_gem_image_state(gem_num, gem_image_state); + } } return CELL_OK; @@ -725,15 +725,6 @@ error_code cellGemGetInertialState(u32 gem_num, u32 state_flag, u64 timestamp, v return CELL_GEM_ERROR_INVALID_PARAMETER; } - if (g_cfg.io.move == move_handler::fake) - { - ds3_input_to_pad(gem_num, inertial_state->pad.digitalbuttons, inertial_state->pad.analog_T); - } - else if (g_cfg.io.move == move_handler::mouse) - { - mouse_input_to_pad(gem_num, inertial_state->pad.digitalbuttons, inertial_state->pad.analog_T); - } - if (g_cfg.io.move == move_handler::fake || g_cfg.io.move == move_handler::mouse) { ds3_input_to_ext(gem_num, inertial_state->ext); @@ -741,6 +732,15 @@ error_code cellGemGetInertialState(u32 gem_num, u32 state_flag, u64 timestamp, v inertial_state->timestamp = (get_guest_system_time() - gem.start_timestamp); inertial_state->counter = gem.inertial_counter++; inertial_state->accelerometer[0] = 10; + + if (g_cfg.io.move == move_handler::fake) + { + ds3_input_to_pad(gem_num, inertial_state->pad.digitalbuttons, inertial_state->pad.analog_T); + } + else if (g_cfg.io.move == move_handler::mouse) + { + mouse_input_to_pad(gem_num, inertial_state->pad.digitalbuttons, inertial_state->pad.analog_T); + } } return CELL_OK; @@ -861,16 +861,6 @@ error_code cellGemGetState(u32 gem_num, u32 flag, u64 time_parameter, vm::ptrpad.digitalbuttons, gem_state->pad.analog_T); - } - else if (g_cfg.io.move == move_handler::mouse) - { - mouse_input_to_pad(gem_num, gem_state->pad.digitalbuttons, gem_state->pad.analog_T); - mouse_pos_to_gem_state(gem_num, gem_state); - } - if (g_cfg.io.move == move_handler::fake || g_cfg.io.move == move_handler::mouse) { ds3_input_to_ext(gem_num, gem_state->ext); @@ -879,6 +869,16 @@ error_code cellGemGetState(u32 gem_num, u32 flag, u64 time_parameter, vm::ptrtimestamp = (get_guest_system_time() - gem.start_timestamp); gem_state->quat[3] = 1.f; + if (g_cfg.io.move == move_handler::fake) + { + ds3_input_to_pad(gem_num, gem_state->pad.digitalbuttons, gem_state->pad.analog_T); + } + else if (g_cfg.io.move == move_handler::mouse) + { + mouse_input_to_pad(gem_num, gem_state->pad.digitalbuttons, gem_state->pad.analog_T); + mouse_pos_to_gem_state(gem_num, gem_state); + } + return CELL_OK; } @@ -1032,7 +1032,7 @@ error_code cellGemInvalidateCalibration(s32 gem_num) if (g_cfg.io.move == move_handler::fake || g_cfg.io.move == move_handler::mouse) { gem.controllers[gem_num].calibrated_magnetometer = false; - // TODO: gem.status_flags + // TODO: gem.status_flags (probably not changed) } return CELL_OK; diff --git a/rpcs3/Emu/Cell/Modules/cellGem.h b/rpcs3/Emu/Cell/Modules/cellGem.h index 34fd3005cb..71b714ea13 100644 --- a/rpcs3/Emu/Cell/Modules/cellGem.h +++ b/rpcs3/Emu/Cell/Modules/cellGem.h @@ -32,54 +32,105 @@ enum CellGemStatus : u32 CELL_GEM_NO_EXTERNAL_PORT_DEVICE = 9, }; +// CellGemInfo status flags. +enum +{ + CELL_GEM_STATUS_DISCONNECTED = 0, + CELL_GEM_STATUS_READY = 1, +}; + +// CellGemPadData defines for bit assignment of digital buttons. +enum +{ + CELL_GEM_CTRL_SELECT = 1 << 0, + CELL_GEM_CTRL_T = 1 << 1, + CELL_GEM_CTRL_MOVE = 1 << 2, + CELL_GEM_CTRL_START = 1 << 3, + CELL_GEM_CTRL_TRIANGLE = 1 << 4, + CELL_GEM_CTRL_CIRCLE = 1 << 5, + CELL_GEM_CTRL_CROSS = 1 << 6, + CELL_GEM_CTRL_SQUARE = 1 << 7, +}; + +// Bit assignments for CellGemExtPortData status member. +enum +{ + CELL_GEM_EXT_CONNECTED = 1 << 0, + CELL_GEM_EXT_EXT0 = 1 << 1, + CELL_GEM_EXT_EXT1 = 1 << 2, +}; + +// Values used to describe characteristics of the extension connector. +enum +{ + CELL_GEM_EXTERNAL_PORT_DEVICE_INFO_SIZE = 38, + CELL_GEM_EXTERNAL_PORT_OUTPUT_SIZE = 40, +}; + +// Limits for cellGemPrepareCamera max_exposure argument. +enum +{ + CELL_GEM_MIN_CAMERA_EXPOSURE = 40, + CELL_GEM_MAX_CAMERA_EXPOSURE = 511, +}; + +// Flags for cellGemGetState. +enum +{ + CELL_GEM_STATE_FLAG_CURRENT_TIME = 0, + CELL_GEM_STATE_FLAG_LATEST_IMAGE_TIME = 1, + CELL_GEM_STATE_FLAG_TIMESTAMP = 2, +}; + +// Flags for cellGemGetInertialState. +enum +{ + CELL_GEM_INERTIAL_STATE_FLAG_LATEST = 0, + CELL_GEM_INERTIAL_STATE_FLAG_PREVIOUS = 1, + CELL_GEM_INERTIAL_STATE_FLAG_NEXT = 2, +}; + +// Special values for cellGemTrackHues. +enum +{ + CELL_GEM_DONT_TRACK_HUE = 2 << 24, + CELL_GEM_DONT_CARE_HUE = 4 << 24, + CELL_GEM_DONT_CHANGE_HUE = 8 << 24, +}; + +// Masks for cellGemGetStatusFlags. +enum +{ + CELL_GEM_FLAG_CALIBRATION_OCCURRED = 1 << 0, + CELL_GEM_FLAG_CALIBRATION_SUCCEEDED = 1 << 1, + CELL_GEM_FLAG_CALIBRATION_FAILED_CANT_FIND_SPHERE = 1 << 2, + CELL_GEM_FLAG_CALIBRATION_FAILED_MOTION_DETECTED = 1 << 3, + CELL_GEM_FLAG_CALIBRATION_FAILED_BRIGHT_LIGHTING = 1 << 4, + CELL_GEM_FLAG_CALIBRATION_WARNING_MOTION_DETECTED = 1 << 5, + CELL_GEM_FLAG_CALIBRATION_WARNING_BRIGHT_LIGHTING = 1 << 6, + CELL_GEM_FLAG_LIGHTING_CHANGED = 1 << 7, + CELL_GEM_FLAG_WRONG_FIELD_OF_VIEW_SETTING = 1 << 8, + CELL_GEM_FLAG_CAMERA_PITCH_ANGLE_CHANGED = 1 << 9, + CELL_GEM_FLAG_VARIABLE_MAGNETIC_FIELD = 1 << 10, + CELL_GEM_FLAG_WEAK_MAGNETIC_FIELD = 1 << 11, + CELL_GEM_FLAG_VERY_COLORFUL_ENVIRONMENT = 1 << 12, + CELL_GEM_FLAG_CURRENT_HUE_CONFLICTS_WITH_ENVIRONMENT = 1 << 13, + CELL_GEM_ALL_FLAGS = 0xffffffffffffffffull +}; + +// Masks for CellGemState tracking_flags member +enum +{ + CELL_GEM_TRACKING_FLAG_POSITION_TRACKED = 1 << 0, + CELL_GEM_TRACKING_FLAG_VISIBLE = 1 << 1, +}; + // General constants enum { - CELL_GEM_CTRL_CIRCLE = 1 << 5, - CELL_GEM_CTRL_CROSS = 1 << 6, - CELL_GEM_CTRL_MOVE = 1 << 2, - CELL_GEM_CTRL_SELECT = 1 << 0, - CELL_GEM_CTRL_SQUARE = 1 << 7, - CELL_GEM_CTRL_START = 1 << 3, - CELL_GEM_CTRL_T = 1 << 1, - CELL_GEM_CTRL_TRIANGLE = 1 << 4, - CELL_GEM_DONT_CARE_HUE = 4 << 24, - CELL_GEM_DONT_CHANGE_HUE = 8 << 24, - CELL_GEM_DONT_TRACK_HUE = 2 << 24, - CELL_GEM_EXT_CONNECTED = 1 << 0, - CELL_GEM_EXT_EXT0 = 1 << 1, - CELL_GEM_EXT_EXT1 = 1 << 2, - CELL_GEM_EXTERNAL_PORT_DEVICE_INFO_SIZE = 38, - CELL_GEM_EXTERNAL_PORT_OUTPUT_SIZE = 40, - CELL_GEM_FLAG_CALIBRATION_FAILED_BRIGHT_LIGHTING = 1 << 4, - CELL_GEM_FLAG_CALIBRATION_FAILED_CANT_FIND_SPHERE = 1 << 2, - CELL_GEM_FLAG_CALIBRATION_FAILED_MOTION_DETECTED = 1 << 3, - CELL_GEM_FLAG_CALIBRATION_OCCURRED = 1 << 0, - CELL_GEM_FLAG_CALIBRATION_SUCCEEDED = 1 << 1, - CELL_GEM_FLAG_CALIBRATION_WARNING_BRIGHT_LIGHTING = 1 << 6, - CELL_GEM_FLAG_CALIBRATION_WARNING_MOTION_DETECTED = 1 << 5, - CELL_GEM_FLAG_CAMERA_PITCH_ANGLE_CHANGED = 1 << 9, - CELL_GEM_FLAG_CURRENT_HUE_CONFLICTS_WITH_ENVIRONMENT = 1 << 13, - CELL_GEM_FLAG_LIGHTING_CHANGED = 1 << 7, - CELL_GEM_FLAG_VARIABLE_MAGNETIC_FIELD = 1 << 10, - CELL_GEM_FLAG_VERY_COLORFUL_ENVIRONMENT = 1 << 12, - CELL_GEM_FLAG_WEAK_MAGNETIC_FIELD = 1 << 11, - CELL_GEM_FLAG_WRONG_FIELD_OF_VIEW_SETTING = 1 << 8, - CELL_GEM_INERTIAL_STATE_FLAG_LATEST = 0, - CELL_GEM_INERTIAL_STATE_FLAG_NEXT = 2, - CELL_GEM_INERTIAL_STATE_FLAG_PREVIOUS = 1, - CELL_GEM_LATENCY_OFFSET = -22000, - CELL_GEM_MAX_CAMERA_EXPOSURE = 511, - CELL_GEM_MAX_NUM = 4, - CELL_GEM_MIN_CAMERA_EXPOSURE = 40, - CELL_GEM_STATE_FLAG_CURRENT_TIME = 0, - CELL_GEM_STATE_FLAG_LATEST_IMAGE_TIME = 1, - CELL_GEM_STATE_FLAG_TIMESTAMP = 2, - CELL_GEM_STATUS_DISCONNECTED = 0, - CELL_GEM_STATUS_READY = 1, - CELL_GEM_TRACKING_FLAG_POSITION_TRACKED = 1 << 0, - CELL_GEM_TRACKING_FLAG_VISIBLE = 1 << 1, - CELL_GEM_VERSION = 2, + CELL_GEM_LATENCY_OFFSET = -22000, + CELL_GEM_MAX_NUM = 4, + CELL_GEM_VERSION = 2, }; // Video conversion flags