From 935e088ca1708ecd6867f86c5d29c2e7359a3ea4 Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Wed, 2 Jul 2025 21:56:12 +0300 Subject: [PATCH] More CPP fixes --- include/services/ir/circlepad_pro.hpp | 6 ++++++ include/services/ir/ir_user.hpp | 5 +++++ src/core/PICA/gpu.cpp | 2 +- src/core/services/ir/ir_user.cpp | 12 +++--------- src/panda_qt/main_window.cpp | 21 +++++++++++++++++++++ 5 files changed, 36 insertions(+), 10 deletions(-) diff --git a/include/services/ir/circlepad_pro.hpp b/include/services/ir/circlepad_pro.hpp index 56ec2259..2202c1cf 100644 --- a/include/services/ir/circlepad_pro.hpp +++ b/include/services/ir/circlepad_pro.hpp @@ -28,8 +28,14 @@ namespace IR { ButtonState() { // Response header for button state reads cStick.header = static_cast(CPPResponseID::PollButtons); + cStick.x = static_cast(CirclePadPro::ButtonState::C_STICK_CENTER); + cStick.y = static_cast(CirclePadPro::ButtonState::C_STICK_CENTER); + // Fully charged buttons.batteryLevel = 0x1F; + buttons.zrNotPressed = 1; + buttons.zlNotPressed = 1; + buttons.rNotPressed = 1; unknown = 0; } }; diff --git a/include/services/ir/ir_user.hpp b/include/services/ir/ir_user.hpp index a9b9ad09..221367f9 100644 --- a/include/services/ir/ir_user.hpp +++ b/include/services/ir/ir_user.hpp @@ -79,6 +79,11 @@ class IRUserService { IRUserService(Memory& mem, const EmulatorConfig& config, Kernel& kernel) : mem(mem), config(config), kernel(kernel), cpp([&](IR::Device::Payload payload) { sendPayload(payload); }) {} + void setZRPressed(bool pressed) { cpp.state.buttons.zrNotPressed = pressed ? 0 : 1; } + void setZLPressed(bool pressed) { cpp.state.buttons.zrNotPressed = pressed ? 0 : 1; } + void setCStickX(s16 value) { cpp.state.cStick.x = value; } + void setCStickY(s16 value) { cpp.state.cStick.y = value; } + void reset(); void handleSyncRequest(u32 messagePointer); void updateCirclePadPro(); diff --git a/src/core/PICA/gpu.cpp b/src/core/PICA/gpu.cpp index 838d3fb3..f5d26784 100644 --- a/src/core/PICA/gpu.cpp +++ b/src/core/PICA/gpu.cpp @@ -441,7 +441,7 @@ void GPU::fireDMA(u32 dest, u32 source, u32 size) { u8* fcram = mem.getFCRAM(); std::memcpy(&vram[dest - vramStart], &fcram[source - fcramStart], size); } else { - printf("Non-trivially optimizable GPU DMA. Falling back to byte-by-byte transfer\n"); + log("Non-trivially optimizable GPU DMA. Falling back to byte-by-byte transfer\n"); for (u32 i = 0; i < size; i++) { mem.write8(dest + i, mem.read8(source + i)); diff --git a/src/core/services/ir/ir_user.cpp b/src/core/services/ir/ir_user.cpp index 0c7b4df3..05bc513a 100644 --- a/src/core/services/ir/ir_user.cpp +++ b/src/core/services/ir/ir_user.cpp @@ -333,13 +333,7 @@ void IRUserService::updateCirclePadPro() { return; } - auto& response = cpp.state; - response.cStick.x = rand() & 0xFFF; - response.cStick.y = static_cast(CirclePadPro::ButtonState::C_STICK_CENTER); - response.buttons.zlNotPressed = 1; - response.buttons.rNotPressed = 1; - - std::vector responsePayload(sizeof(response)); - std::memcpy(responsePayload.data(), &response, sizeof(response)); - sendPayload(responsePayload); + std::vector response(sizeof(cpp.state)); + std::memcpy(response.data(), &cpp.state, sizeof(cpp.state)); + sendPayload(response); } \ No newline at end of file diff --git a/src/panda_qt/main_window.cpp b/src/panda_qt/main_window.cpp index ed6c2852..9b4db334 100644 --- a/src/panda_qt/main_window.cpp +++ b/src/panda_qt/main_window.cpp @@ -613,6 +613,27 @@ void MainWindow::pollControllers() { } else { hid.setCirclepadY(-(stickY / div)); } + + auto& ir = emu->getServiceManager().getIRUser(); + const s16 l2 = SDL_GameControllerGetAxis(gameController, SDL_CONTROLLER_AXIS_TRIGGERLEFT); + const s16 r2 = SDL_GameControllerGetAxis(gameController, SDL_CONTROLLER_AXIS_TRIGGERRIGHT); + const s16 cstickX = SDL_GameControllerGetAxis(gameController, SDL_CONTROLLER_AXIS_RIGHTX); + const s16 cstickY = SDL_GameControllerGetAxis(gameController, SDL_CONTROLLER_AXIS_RIGHTY); + + ir.setZLPressed(l2 > 16000); + ir.setZRPressed(r2 > 16000); + + if (std::abs(cstickX) < deadzone) { + ir.setCStickX(IR::CirclePadPro::ButtonState::C_STICK_CENTER); + } else { + ir.setCStickX(cstickX / 8); + } + + if (std::abs(cstickY) < deadzone) { + ir.setCStickY(IR::CirclePadPro::ButtonState::C_STICK_CENTER); + } else { + ir.setCStickY(-(cstickY / 8)); + } } SDL_Event event;