1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-25 12:12:50 +01:00

uDraw emulation

This commit is contained in:
Florin9doi 2022-11-18 10:15:50 +02:00 committed by Megamouse
parent 40eda1b972
commit 463826bf13
14 changed files with 353 additions and 4 deletions

View File

@ -21,6 +21,7 @@
#include "Emu/Io/ghltar_config.h"
#include "Emu/Io/Buzz.h"
#include "Emu/Io/buzz_config.h"
#include "Emu/Io/GameTablet.h"
#include "Emu/Io/Turntable.h"
#include "Emu/Io/turntable_config.h"
#include "Emu/Io/RB3MidiKeyboard.h"
@ -478,6 +479,12 @@ usb_handler_thread::usb_handler_thread()
sys_usbd.notice("Adding emulated Buzz! buzzer (5-7 players)");
usb_devices.push_back(std::make_shared<usb_device_buzz>(4, 6, get_new_location()));
}
if (g_cfg.io.gametablet == gametablet_handler::enabled)
{
sys_usbd.notice("Adding emulated uDraw GameTablet");
usb_devices.push_back(std::make_shared<usb_device_gametablet>(get_new_location()));
}
}
usb_handler_thread::~usb_handler_thread()

274
rpcs3/Emu/Io/GameTablet.cpp Normal file
View File

@ -0,0 +1,274 @@
#include "stdafx.h"
#include "GameTablet.h"
#include "MouseHandler.h"
#include "Emu/IdManager.h"
#include "Emu/Cell/lv2/sys_usbd.h"
#include "Emu/system_config.h"
#include "Input/pad_thread.h"
LOG_CHANNEL(gametablet_log);
usb_device_gametablet::usb_device_gametablet(const std::array<u8, 7>& location)
: usb_device_emulated(location)
{
device = UsbDescriptorNode(USB_DESCRIPTOR_DEVICE,
UsbDeviceDescriptor {
.bcdUSB = 0x0200,
.bDeviceClass = 0x00,
.bDeviceSubClass = 0x00,
.bDeviceProtocol = 0x00,
.bMaxPacketSize0 = 0x08,
.idVendor = 0x20d6,
.idProduct = 0xcb17,
.bcdDevice = 0x0108,
.iManufacturer = 0x01,
.iProduct = 0x02,
.iSerialNumber = 0x00,
.bNumConfigurations = 0x01});
auto& config0 = device.add_node(UsbDescriptorNode(USB_DESCRIPTOR_CONFIG,
UsbDeviceConfiguration {
.wTotalLength = 0x0029,
.bNumInterfaces = 0x01,
.bConfigurationValue = 0x01,
.iConfiguration = 0x00,
.bmAttributes = 0x80,
.bMaxPower = 0x32}));
config0.add_node(UsbDescriptorNode(USB_DESCRIPTOR_INTERFACE,
UsbDeviceInterface {
.bInterfaceNumber = 0x00,
.bAlternateSetting = 0x00,
.bNumEndpoints = 0x02,
.bInterfaceClass = 0x03,
.bInterfaceSubClass = 0x00,
.bInterfaceProtocol = 0x00,
.iInterface = 0x00}));
config0.add_node(UsbDescriptorNode(USB_DESCRIPTOR_HID,
UsbDeviceHID {
.bcdHID = 0x0110,
.bCountryCode = 0x00,
.bNumDescriptors = 0x01,
.bDescriptorType = 0x22,
.wDescriptorLength = 0x0089}));
config0.add_node(UsbDescriptorNode(USB_DESCRIPTOR_ENDPOINT,
UsbDeviceEndpoint {
.bEndpointAddress = 0x83,
.bmAttributes = 0x03,
.wMaxPacketSize = 0x0040,
.bInterval = 0x0A}));
config0.add_node(UsbDescriptorNode(USB_DESCRIPTOR_ENDPOINT,
UsbDeviceEndpoint {
.bEndpointAddress = 0x04,
.bmAttributes = 0x03,
.wMaxPacketSize = 0x0040,
.bInterval = 0x0A}));
add_string("THQ Inc");
add_string("THQ uDraw Game Tablet for PS3");
}
usb_device_gametablet::~usb_device_gametablet()
{
}
void usb_device_gametablet::control_transfer(u8 bmRequestType, u8 bRequest, u16 wValue, u16 wIndex, u16 wLength, u32 buf_size, u8* buf, UsbTransfer* transfer)
{
transfer->fake = true;
transfer->expected_count = buf_size;
transfer->expected_result = HC_CC_NOERR;
transfer->expected_time = get_timestamp() + 100;
// Control transfers are nearly instant
switch (bmRequestType)
{
case 0U /*silences warning*/ | LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE: // 0x21
switch (bRequest)
{
case 0x09: // SET_REPORT
ensure(buf_size > 2);
gametablet_log.trace("Leds: %s/%s/%s/%s",
buf[2] & 1 ? "ON" : "OFF",
buf[2] & 2 ? "ON" : "OFF",
buf[2] & 4 ? "ON" : "OFF",
buf[2] & 8 ? "ON" : "OFF");
break;
default:
gametablet_log.error("Unhandled Request: 0x%02X/0x%02X", bmRequestType, bRequest);
break;
}
break;
default:
usb_device_emulated::control_transfer(bmRequestType, bRequest, wValue, wIndex, wLength, buf_size, buf, transfer);
break;
}
}
extern bool is_input_allowed();
void usb_device_gametablet::interrupt_transfer(u32 buf_size, u8* buf, u32 /*endpoint*/, UsbTransfer* transfer)
{
ensure(buf_size > 0x1a);
transfer->fake = true;
transfer->expected_count = 27;
transfer->expected_result = HC_CC_NOERR;
// Interrupt transfers are slow (6ms, TODO accurate measurement)
transfer->expected_time = get_timestamp() + 6000;
std::memset(buf, 0, buf_size);
buf[0x02] = 0x0f; // dpad
buf[0x03] = 0x80;
buf[0x04] = 0x80;
buf[0x05] = 0x80;
buf[0x06] = 0x80;
buf[0x0d] = 0x72; // pressure
buf[0x0f] = 0x0f; // pos X
buf[0x10] = 0x0f; // pos Y
buf[0x11] = 0xff;
buf[0x12] = 0xff;
buf[0x13] = 0x01; // accel X
buf[0x14] = 0x02;
buf[0x15] = 0x00; // accel Y
buf[0x16] = 0x02;
buf[0x17] = 0xea; // accel Z
buf[0x18] = 0x01;
buf[0x1a] = 0x02;
if (!is_input_allowed())
{
return;
}
if (g_cfg.io.mouse != mouse_handler::basic)
{
gametablet_log.warning("GameTablet requires mouse_handler configured to basic");
return;
}
std::lock_guard lock(pad::g_pad_mutex);
const auto gamepad_handler = pad::get_current_handler();
const auto& pads = gamepad_handler->GetPads();
bool up = false, right = false, down = false, left = false;
const int pad_index = 1; // Player2
const auto& pad = pads[pad_index];
if (pad->m_port_status & CELL_PAD_STATUS_CONNECTED)
{
for (Button& button : pad->m_buttons)
{
if (!button.m_pressed)
{
continue;
}
if (button.m_offset == CELL_PAD_BTN_OFFSET_DIGITAL1)
{
switch (button.m_outKeyCode)
{
case CELL_PAD_CTRL_SELECT:
buf[1] |= (1 << 0);
break;
case CELL_PAD_CTRL_START:
buf[1] |= (1 << 1);
break;
case CELL_PAD_CTRL_UP:
up = true;
break;
case CELL_PAD_CTRL_RIGHT:
right = true;
break;
case CELL_PAD_CTRL_DOWN:
down = true;
break;
case CELL_PAD_CTRL_LEFT:
left = true;
break;
default:
break;
}
}
else if (button.m_offset == CELL_PAD_BTN_OFFSET_DIGITAL2)
{
switch (button.m_outKeyCode)
{
case CELL_PAD_CTRL_SQUARE:
buf[0] |= (1 << 0);
break;
case CELL_PAD_CTRL_CROSS:
buf[0] |= (1 << 1);
break;
case CELL_PAD_CTRL_CIRCLE:
buf[0] |= (1 << 2);
break;
case CELL_PAD_CTRL_TRIANGLE:
buf[0] |= (1 << 3);
break;
case CELL_PAD_CTRL_PS:
buf[1] |= (1 << 4);
break;
default:
break;
}
}
}
}
if (!up && !right && !down && !left)
buf[0x02] = 0x0f;
else if (up && !left && !right)
buf[0x02] = 0x00;
else if (up && right)
buf[0x02] = 0x01;
else if (right && !up && !down)
buf[0x02] = 0x02;
else if (down && right)
buf[0x02] = 0x03;
else if (down && !left && !right)
buf[0x02] = 0x04;
else if (down && left)
buf[0x02] = 0x05;
else if (left && !up && !down)
buf[0x02] = 0x06;
else if (up && left)
buf[0x02] = 0x07;
auto& mouse_handler = g_fxo->get<MouseHandlerBase>();
std::lock_guard mouse_lock(mouse_handler.mutex);
mouse_handler.Init(1);
const uint8_t mouse_index = 0;
if (mouse_index >= mouse_handler.GetMice().size())
{
return;
}
const Mouse& mouse_data = ::at32(mouse_handler.GetMice(), mouse_index);
if (mouse_data.x_max <= 0 || mouse_data.y_max <= 0)
{
return;
}
static uint8_t noise_x = 0; // Toggle the LSB to simulate a noisy signal, Instant Artist dislikes a pen held perfectly still
static uint8_t noise_y = 0;
const int tablet_max_x = 1920;
const int tablet_max_y = 1080;
const long tablet_x_pos = (mouse_data.x_pos * tablet_max_x / mouse_data.x_max) ^ noise_x;
const long tablet_y_pos = (mouse_data.y_pos * tablet_max_y / mouse_data.y_max) ^ noise_y;
noise_x = !noise_x;
noise_y = !noise_y;
buf[0x0b] = 0x40; // pen
buf[0x0d] = mouse_data.buttons & CELL_MOUSE_BUTTON_1 ? 0xbb : 0x72; // pressure
buf[0x0f] = tablet_x_pos / 0x100;
buf[0x10] = tablet_y_pos / 0x100;
buf[0x11] = tablet_x_pos % 0x100;
buf[0x12] = tablet_y_pos % 0x100;
}

13
rpcs3/Emu/Io/GameTablet.h Normal file
View File

@ -0,0 +1,13 @@
#pragma once
#include "Emu/Io/usb_device.h"
class usb_device_gametablet : public usb_device_emulated
{
public:
usb_device_gametablet(const std::array<u8, 7>& location);
~usb_device_gametablet();
void control_transfer(u8 bmRequestType, u8 bRequest, u16 wValue, u16 wIndex, u16 wLength, u32 buf_size, u8* buf, UsbTransfer* transfer) override;
void interrupt_transfer(u32 buf_size, u8* buf, u32 endpoint, UsbTransfer* transfer) override;
};

View File

@ -274,6 +274,7 @@ struct cfg_root : cfg::node
cfg::_enum<buzz_handler> buzz{ this, "Buzz emulated controller", buzz_handler::null };
cfg::_enum<turntable_handler> turntable{this, "Turntable emulated controller", turntable_handler::null};
cfg::_enum<ghltar_handler> ghltar{this, "GHLtar emulated controller", ghltar_handler::null};
cfg::_enum<gametablet_handler> gametablet{this, "GameTablet emulated controller", gametablet_handler::disabled};
cfg::_enum<pad_handler_mode> pad_mode{this, "Pad handler mode", pad_handler_mode::single_threaded, true};
cfg::_bool keep_pads_connected{this, "Keep pads connected", false, true};
cfg::uint<0, 100'000> pad_sleep{this, "Pad handler sleep (microseconds)", 1'000, true};

View File

@ -507,6 +507,21 @@ void fmt_class_string<ghltar_handler>::format(std::string& out, u64 arg)
});
}
template <>
void fmt_class_string<gametablet_handler>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto value)
{
switch (value)
{
case gametablet_handler::disabled: return "Disabled";
case gametablet_handler::enabled: return "Enabled";
}
return unknown;
});
}
template <>
void fmt_class_string<ppu_decoder_type>::format(std::string& out, u64 arg)
{

View File

@ -167,6 +167,12 @@ enum class ghltar_handler
two_controllers,
};
enum class gametablet_handler
{
disabled,
enabled,
};
enum class microphone_handler
{
null,

View File

@ -78,6 +78,7 @@
<ClCompile Include="Emu\Io\RB3MidiKeyboard.cpp" />
<ClCompile Include="Emu\Io\recording_config.cpp" />
<ClCompile Include="Emu\Io\Turntable.cpp" />
<ClCompile Include="Emu\Io\GameTablet.cpp" />
<ClCompile Include="Emu\Io\GHLtar.cpp" />
<ClCompile Include="Emu\Io\Buzz.cpp" />
<ClCompile Include="Emu\Io\usio.cpp" />
@ -544,6 +545,7 @@
<ClInclude Include="Emu\Io\RB3MidiKeyboard.h" />
<ClInclude Include="Emu\Io\recording_config.h" />
<ClInclude Include="Emu\Io\Turntable.h" />
<ClInclude Include="Emu\Io\GameTablet.h" />
<ClInclude Include="Emu\Io\GHLtar.h" />
<ClInclude Include="Emu\Io\Buzz.h" />
<ClInclude Include="Emu\Io\turntable_config.h" />

View File

@ -924,6 +924,9 @@
<ClCompile Include="Emu\RSX\Overlays\Shaders\shader_loading_dialog.cpp">
<Filter>Emu\GPU\RSX\Overlays\Shaders</Filter>
</ClCompile>
<ClCompile Include="Emu\Io\GameTablet.cpp">
<Filter>Emu\Io</Filter>
</ClCompile>
<ClCompile Include="Emu\Io\GHLtar.cpp">
<Filter>Emu\Io</Filter>
</ClCompile>
@ -2055,6 +2058,9 @@
<ClInclude Include="Emu\RSX\Overlays\overlay_compile_notification.h">
<Filter>Emu\GPU\RSX\Overlays</Filter>
</ClInclude>
<ClInclude Include="Emu\Io\GameTablet.h">
<Filter>Emu\Io</Filter>
</ClInclude>
<ClInclude Include="Emu\Io\GHLtar.h">
<Filter>Emu\Io</Filter>
</ClInclude>

View File

@ -1088,6 +1088,13 @@ QString emu_settings::GetLocalizedSetting(const QString& original, emu_settings_
case ghltar_handler::two_controllers: return tr("2 controllers", "GHLtar handler");
}
break;
case emu_settings_type::GameTablet:
switch (static_cast<gametablet_handler>(index))
{
case gametablet_handler::disabled: return tr("Disabled", "GameTablet handler");
case gametablet_handler::enabled: return tr("Enabled", "GameTablet handler");
}
break;
case emu_settings_type::InternetStatus:
switch (static_cast<np_internet_status>(index))
{

View File

@ -161,6 +161,7 @@ enum class emu_settings_type
Buzz,
Turntable,
GHLtar,
GameTablet,
MidiDevices,
SDLMappings,
@ -350,6 +351,7 @@ inline static const QMap<emu_settings_type, cfg_location> settings_location =
{ emu_settings_type::Buzz, { "Input/Output", "Buzz emulated controller" }},
{ emu_settings_type::Turntable, { "Input/Output", "Turntable emulated controller" }},
{ emu_settings_type::GHLtar, { "Input/Output", "GHLtar emulated controller" }},
{ emu_settings_type::GameTablet, { "Input/Output", "GameTablet emulated controller" }},
{ emu_settings_type::MidiDevices, { "Input/Output", "Emulated Midi devices" }},
{ emu_settings_type::SDLMappings, { "Input/Output", "Load SDL GameController Mappings" }},

View File

@ -1070,7 +1070,7 @@ void gs_frame::take_screenshot(std::vector<u8> data, u32 sshot_width, u32 sshot_
void gs_frame::mouseDoubleClickEvent(QMouseEvent* ev)
{
if (m_disable_mouse || g_cfg.io.move == move_handler::mouse) return;
if (m_disable_mouse || g_cfg.io.move == move_handler::mouse || g_cfg.io.gametablet == gametablet_handler::enabled) return;
#ifdef HAVE_LIBEVDEV
if (g_cfg.io.move == move_handler::gun) return;
#endif

View File

@ -1217,6 +1217,9 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
m_emu_settings->EnhanceComboBox(ui->ghltarBox, emu_settings_type::GHLtar);
SubscribeTooltip(ui->gb_ghltar_emulated, tooltips.settings.ghltar);
m_emu_settings->EnhanceComboBox(ui->gameTabletBox, emu_settings_type::GameTablet);
SubscribeTooltip(ui->gametablet_emulated, tooltips.settings.gametablet);
m_emu_settings->EnhanceCheckBox(ui->backgroundInputBox, emu_settings_type::BackgroundInput);
SubscribeTooltip(ui->backgroundInputBox, tooltips.settings.background_input);

View File

@ -1731,6 +1731,18 @@
</layout>
</widget>
</item>
<item row="4" column="1">
<widget class="QGroupBox" name="gametablet_emulated">
<property name="title">
<string>GameTablet</string>
</property>
<layout class="QVBoxLayout" name="gametablet_emulated_layout">
<item>
<widget class="QComboBox" name="gameTabletBox"/>
</item>
</layout>
</widget>
</item>
<item row="3" column="2">
<widget class="QGroupBox" name="gb_midi_1">
<property name="title">
@ -1750,7 +1762,7 @@
</layout>
</widget>
</item>
<item row="6" column="2">
<item row="5" column="2">
<widget class="QGroupBox" name="gb_midi_3">
<property name="title">
<string>Emulated MIDI Device 3</string>
@ -1769,7 +1781,7 @@
</layout>
</widget>
</item>
<item row="5" column="2">
<item row="4" column="2">
<widget class="QGroupBox" name="gb_midi_2">
<property name="title">
<string>Emulated MIDI Device 2</string>
@ -1788,7 +1800,7 @@
</layout>
</widget>
</item>
<item row="5" column="0" rowspan="2">
<item row="4" column="0" rowspan="2">
<widget class="QGroupBox" name="gb_additional_io_settings">
<property name="title">
<string>Additional Settings</string>

View File

@ -231,6 +231,7 @@ public:
const QString buzz = tr("Buzz! support.\nSelect 1 or 2 controllers if the game requires Buzz! controllers and you don't have real controllers.\nSelect Null if the game has support for DualShock or if you have real Buzz! controllers.");
const QString turntable = tr("DJ Hero Turntable controller support.\nSelect 1 or 2 controllers if the game requires DJ Hero Turntable controllers and you don't have real turntable controllers.\nSelect Null if the game has support for DualShock or if you have real turntable controllers.\nA real turntable controller can be used at the same time as an emulated turntable controller.");
const QString ghltar = tr("Guitar Hero Live (GHL) Guitar controller support.\nSelect 1 or 2 controllers if the game requires GHL Guitar controllers and you don't have real guitar controllers.\nSelect Null if the game has support for DualShock or if you have real guitar controllers.\nA real guitar controller can be used at the same time as an emulated guitar controller.");
const QString gametablet = tr("GameTablet emulated controller support.\nDisable to use a physical GameTablet device");
const QString background_input = tr("Allows pad and keyboard input while the game window is unfocused.");
const QString show_move_cursor = tr("Shows the raw position of the PS Move input.\nThis can be very helpful during calibration screens.");
const QString midi_devices = tr("Select up to 3 emulated MIDI devices and their types.");