From 3ddcf60a114417202686e8b326d7add295dc5f39 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Fri, 30 Jul 2021 00:32:41 +0200 Subject: [PATCH] cellGem: add some more error checks --- rpcs3/Emu/Cell/Modules/cellGem.cpp | 91 ++++++++++++++++++++++++++++-- 1 file changed, 87 insertions(+), 4 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/cellGem.cpp b/rpcs3/Emu/Cell/Modules/cellGem.cpp index 67121dce38..8ee58d9894 100644 --- a/rpcs3/Emu/Cell/Modules/cellGem.cpp +++ b/rpcs3/Emu/Cell/Modules/cellGem.cpp @@ -88,6 +88,7 @@ struct gem_config bool enabled_filtering = false; // Whether filtering is enabled bool enabled_tracking = false; // Whether tracking is enabled bool enabled_LED = false; // Whether the LED is enabled + bool hue_set = false; // Whether the hue was set u8 rumble = 0; // Rumble intensity gem_color sphere_rgb = {}; // RGB color of the sphere LED u32 hue = 0; // Tracking hue of the motion controller @@ -101,6 +102,7 @@ struct gem_config std::array controllers; u32 connected_controllers = 0; + bool video_conversion_started{}; bool update_started{}; u32 camera_frame{}; u32 memory_ptr{}; @@ -454,6 +456,13 @@ error_code cellGemConvertVideoFinish() return CELL_GEM_ERROR_UNINITIALIZED; } + if (!std::exchange(gem.video_conversion_started, false)) + { + return CELL_GEM_ERROR_CONVERT_NOT_STARTED; + } + + // TODO: wait until image is converted + return CELL_OK; } @@ -468,6 +477,18 @@ error_code cellGemConvertVideoStart(vm::cptr video_frame) return CELL_GEM_ERROR_UNINITIALIZED; } + if (!video_frame) + { + return CELL_GEM_ERROR_INVALID_PARAMETER; + } + + if (std::exchange(gem.video_conversion_started, true)) + { + return CELL_GEM_ERROR_CONVERT_NOT_FINISHED; + } + + // TODO: start image conversion of video_frame async to gem.vc_attribute.video_data_out + return CELL_OK; } @@ -592,9 +613,22 @@ error_code cellGemForceRGB(u32 gem_num, float r, float g, float b) return CELL_OK; } -error_code cellGemGetAccelerometerPositionInDevice() +error_code cellGemGetAccelerometerPositionInDevice(u32 gem_num, vm::ptr pos) { - UNIMPLEMENTED_FUNC(cellGem); + cellGem.todo("cellGemGetAccelerometerPositionInDevice(gem_num=%d, pos=*0x%x)", gem_num, pos); + + auto& gem = g_fxo->get(); + + if (!gem.state) + { + return CELL_GEM_ERROR_UNINITIALIZED; + } + + if (!check_gem_num(gem_num) || !pos) + { + return CELL_GEM_ERROR_INVALID_PARAMETER; + } + return CELL_OK; } @@ -609,6 +643,11 @@ error_code cellGemGetAllTrackableHues(vm::ptr hues) return CELL_GEM_ERROR_UNINITIALIZED; } + if (!hues) + { + return CELL_GEM_ERROR_INVALID_PARAMETER; + } + for (u32 i = 0; i < 360; i++) { hues[i] = true; @@ -879,12 +918,37 @@ error_code cellGemGetState(u32 gem_num, u32 flag, u64 time_parameter, vm::ptrext); gem_state->tracking_flags = CELL_GEM_TRACKING_FLAG_POSITION_TRACKED | CELL_GEM_TRACKING_FLAG_VISIBLE; gem_state->timestamp = (get_guest_system_time() - gem.start_timestamp); + gem_state->camera_pitch_angle = 0.f; gem_state->quat[3] = 1.f; if (g_cfg.io.move == move_handler::fake) @@ -1201,9 +1265,26 @@ error_code cellGemSetRumble(u32 gem_num, u8 rumble) return CELL_OK; } -error_code cellGemSetYaw() +error_code cellGemSetYaw(u32 gem_num, vm::ptr z_direction) { - UNIMPLEMENTED_FUNC(cellGem); + cellGem.todo("cellGemSetYaw(gem_num=%d, z_direction=*0x%x)", gem_num, z_direction); + + auto& gem = g_fxo->get(); + + std::scoped_lock lock(gem.mtx); + + if (!gem.state) + { + return CELL_GEM_ERROR_UNINITIALIZED; + } + + if (!z_direction) + { + return CELL_GEM_ERROR_INVALID_PARAMETER; + } + + // TODO + return CELL_OK; } @@ -1280,6 +1361,8 @@ error_code cellGemTrackHues(vm::cptr req_hues, vm::ptr res_hues) res_hues[i] = gem.controllers[i].hue; } } + + gem.controllers[i].hue_set = true; } return CELL_OK;