Skip to content

Commit

Permalink
WIP raphnet PSX to USB support
Browse files Browse the repository at this point in the history
  • Loading branch information
isage committed Mar 28, 2023
1 parent 05a6423 commit 86cbb67
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 1 deletion.
86 changes: 86 additions & 0 deletions src/controllers/dinput/raphnetpsx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#ifndef __DINPUT_RAPHNETPSX_H__
#define __DINPUT_RAPHNETPSX_H__
#include <psp2kern/ctrl.h>

uint8_t raphnetpsx_processReport(Controller *c, size_t length)
{
if (length >= 15)
{
// dpad
if (bit(c->buffer + 14, 4))
c->controlData.buttons |= SCE_CTRL_UP;
if (bit(c->buffer + 14, 5))
c->controlData.buttons |= SCE_CTRL_DOWN;
if (bit(c->buffer + 14, 6))
c->controlData.buttons |= SCE_CTRL_LEFT;
if (bit(c->buffer + 14, 7))
c->controlData.buttons |= SCE_CTRL_RIGHT;

if (bit(c->buffer + 13, 0))
c->controlData.buttons |= SCE_CTRL_SQUARE;
if (bit(c->buffer + 13, 1))
c->controlData.buttons |= SCE_CTRL_CROSS;
if (bit(c->buffer + 13, 2))
c->controlData.buttons |= SCE_CTRL_CIRCLE;
if (bit(c->buffer + 13, 3))
c->controlData.buttons |= SCE_CTRL_TRIANGLE;

if (bit(c->buffer + 13, 4))
c->controlData.buttons |= SCE_CTRL_START;
if (bit(c->buffer + 13, 5))
c->controlData.buttons |= SCE_CTRL_SELECT;

if (bit(c->buffer + 13, 6))
c->controlData.buttons |= SCE_CTRL_L1;
if (bit(c->buffer + 13, 7))
c->controlData.buttons |= SCE_CTRL_R1;

if (bit(c->buffer + 14, 2))
c->controlData.buttons |= SCE_CTRL_L3;
if (bit(c->buffer + 14, 3))
c->controlData.buttons |= SCE_CTRL_R3;

// triggers
int16_t ltx = *(int16_t*)(c->buffer + 11);
c->controlData.lt = ((int32_t)ltx - 16000) * 255 / 16000;
int16_t rtx = *(int16_t*)(c->buffer + 9);
c->controlData.rt = ((int32_t)rtx - 16000) * 255 / 16000;

// set buttons with little deadzone
if (c->controlData.lt > 10)
c->controlData.buttons |= SCE_CTRL_LTRIGGER;
if (c->controlData.rt > 10)
c->controlData.buttons |= SCE_CTRL_RTRIGGER;

if (bit(c->buffer + 14, 0))
{
c->controlData.buttons |= SCE_CTRL_LTRIGGER;
c->controlData.lt = 0xFF;
}
if (bit(c->buffer + 14, 1))
{
c->controlData.buttons |= SCE_CTRL_RTRIGGER;
c->controlData.rt = 0xFF;
}

// axes
int16_t lx = *(int16_t*)(c->buffer + 1);
c->controlData.leftX = (int32_t)lx * 255 / 32000;
int16_t ly = *(int16_t*)(c->buffer + 3);
c->controlData.leftY = (int32_t)ly * 255 / 32000;

int16_t rx = *(int16_t*)(c->buffer + 5);
c->controlData.rightX = (int32_t)rx * 255 / 32000;
int16_t ry = *(int16_t*)(c->buffer + 7);
c->controlData.rightY = (int32_t)ry * 255 / 32000;

if (bit(c->buffer + 13, 6) && bit(c->buffer + 13, 7) && bit(c->buffer + 13, 4)) // L+R+START combo
{
c->controlData.buttons |= SCE_CTRL_PSBUTTON;
c->controlData.buttons &= ~SCE_CTRL_START;
}
}
return 1;
}

#endif
5 changes: 5 additions & 0 deletions src/controllers/dinput_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "dinput/logitech.h"
#include "dinput/psclassic.h"
#include "dinput/horidiva.h"
#include "dinput/raphnetpsx.h"

uint8_t DinputController_probe(Controller *c, int device_id, int port, int vendor, int product)
{
Expand Down Expand Up @@ -112,6 +113,10 @@ uint8_t DinputController_processReport(Controller *c, size_t length)
{
return logitech_processReport(c, length);
}
else if (c->vendor == 0x289b && c->product == 0x0044) // raphnet
{
return raphnetpsx_processReport(c, length);
}
else
{
return 0;
Expand Down
3 changes: 2 additions & 1 deletion src/devicelist.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ gamepad_t _devices[] = {{PAD_XBOX360, 0x045e, 0x028e}, // Microsoft X-Box 360 p
{PAD_DINPUT, 0x046d, 0xc218}, // Logitech F510 Gamepad [DirectInput Mode] / Rumblepad 2
{PAD_DINPUT, 0x046d, 0xc216}, // Logitech F310 Gamepad [DirectInput Mode] / DualAction
{PAD_DINPUT, 0x054c, 0x0cda}, // Playstation Classic
{PAD_DINPUT, 0x0F0D, 0x0049}, // Hori ps3 mini diva
{PAD_DINPUT, 0x0f0d, 0x0049}, // Hori ps3 mini diva
{PAD_DINPUT, 0x289b, 0x0044}, // Raphnet Technologies PSX to USB v.1.0

{PAD_UNKNOWN, 0x0000, 0x0000}}; // Null

0 comments on commit 86cbb67

Please sign in to comment.