From 85e11ca341319d9f695b14de8328e6cfba745c76 Mon Sep 17 00:00:00 2001 From: brian218 Date: Fri, 21 Oct 2022 01:50:14 +0800 Subject: [PATCH] USIO Input Enhancement --- rpcs3/Emu/Io/usio.cpp | 57 ++++++++++++++++++++++++++++++++++++++++--- rpcs3/Emu/Io/usio.h | 4 +++ 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/rpcs3/Emu/Io/usio.cpp b/rpcs3/Emu/Io/usio.cpp index abe1ff7ea5..fa7a22ae6f 100644 --- a/rpcs3/Emu/Io/usio.cpp +++ b/rpcs3/Emu/Io/usio.cpp @@ -145,8 +145,9 @@ void usb_device_usio::translate_input() const auto handler = pad::get_current_handler(); std::vector input_buf = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x60, 0x00, 0x60, 0x00, 0x60, 0x00, 0x60, 0x00, 0x60, 0x00, 0x60, 0x00, 0x60, 0x00, 0x60, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - constexpr le_t c_small_hit = 0x4A0; - constexpr le_t c_big_hit = 0xA40; + constexpr le_t c_small_hit = 0x4D0; + constexpr le_t c_big_hit = 0x1800; + le_t test_keys = 0x0000; auto translate_from_pad = [&](u8 pad_number, u8 player) { @@ -165,9 +166,50 @@ void usb_device_usio::translate_input() for (const Button& button : pad->m_buttons) { - if (button.m_pressed) + switch (button.m_offset) { - if (button.m_offset == CELL_PAD_BTN_OFFSET_DIGITAL2) + case CELL_PAD_BTN_OFFSET_DIGITAL1: + if (player == 0) + { + switch (button.m_outKeyCode) + { + case CELL_PAD_CTRL_SELECT: + if (button.m_pressed && !test_key_pressed) // Solve the need to hold the Test key + test_on = !test_on; + test_key_pressed = button.m_pressed; + break; + case CELL_PAD_CTRL_LEFT: + if (button.m_pressed && !coin_key_pressed) // Ensure only one coin is inserted each time the Coin key is pressed + coin_counter++; + coin_key_pressed = button.m_pressed; + break; + default: + if (button.m_pressed) + { + switch (button.m_outKeyCode) + { + case CELL_PAD_CTRL_START: + test_keys |= 0x200; // Enter + break; + case CELL_PAD_CTRL_UP: + test_keys |= 0x2000; // Up + break; + case CELL_PAD_CTRL_DOWN: + test_keys |= 0x1000; // Down + break; + case CELL_PAD_CTRL_RIGHT: + test_keys |= 0x4000; // Service + break; + default: + break; + } + } + break; + } + } + break; + case CELL_PAD_BTN_OFFSET_DIGITAL2: + if (button.m_pressed) { switch (button.m_outKeyCode) { @@ -207,6 +249,9 @@ void usb_device_usio::translate_input() break; } } + break; + default: + break; } } }; @@ -214,6 +259,10 @@ void usb_device_usio::translate_input() translate_from_pad(0, 0); translate_from_pad(1, 1); + test_keys |= test_on ? 0x80 : 0x00; + std::memcpy(input_buf.data(), &test_keys, sizeof(u16)); + std::memcpy(input_buf.data() + 16, &coin_counter, sizeof(u16)); + q_replies.push(input_buf); q_replies.push({0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}); } diff --git a/rpcs3/Emu/Io/usio.h b/rpcs3/Emu/Io/usio.h index 116ea23e1e..a6e6b9e660 100644 --- a/rpcs3/Emu/Io/usio.h +++ b/rpcs3/Emu/Io/usio.h @@ -21,6 +21,10 @@ private: void usio_read(u8 channel, u16 reg, u16 size); private: + bool test_on = false; + bool test_key_pressed = false; + bool coin_key_pressed = false; + le_t coin_counter = 0; std::string usio_backup_path; fs::file usio_backup_file; std::queue> q_replies;