Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
adlerosn committed Oct 22, 2022
0 parents commit 50840ae
Show file tree
Hide file tree
Showing 14 changed files with 1,271 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*
!/.gitignore
!/README.md
!/Makefile
!/joysrv.c
!/moduleloader.c
!/moduleloader.h
!/myoplnetparser.c
!/myoplnetparser.h
!/pad.c
!/pad.h
!/ps2ipcfg.c
!/ps2ipcfg.h
!/ps2ipcfglib.c
!/ps2ipcfglib.h
57 changes: 57 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# _____ ___ ____ ___ ____
# ____| | ____| | | |____|
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
#-----------------------------------------------------------------------
# Copyright 2001-2004, ps2dev - http://www.ps2dev.org
# Licenced under Academic Free License version 2.0
# Review ps2sdk README & LICENSE files for further details.

IRXS = ps2dev9 netman smap
IRX_SRCS = $(shell for i in $(IRXS); do echo irx_$${i}.c; done)
IRX_OBJS = $(shell for i in $(IRXS); do echo irx_$${i}.o; done)
EE_BIN_PKD = JOYSRV.ELF
EE_BIN_STR = joysrv-str.elf
EE_BIN = joysrv-unc.elf
EE_OBJS = joysrv.o pad.o moduleloader.o myoplnetparser.o ps2ipcfg.o ps2ipcfglib.o $(IRX_OBJS)
EE_LIBS = -lmc -lpad -lpadx -lnetman -ldebug -lps2ip -ldebug -lpatches
BIN2C = $(PS2SDK)/bin/bin2c
PS2IP ?= 192.168.83.74

ifndef PS2SDK
ps2sdk-not-setup:
@echo "PS2SDK is not setup. Please setup PS2SDK before building this project"
endif

all: $(EE_BIN_PKD)

$(EE_BIN_PKD): $(EE_BIN_STR)
ps2-packer $< $@

$(EE_BIN_STR): $(EE_BIN)
$(EE_STRIP) --strip-all $< -o $@

clean:
rm -f $(EE_BIN_PKD) $(EE_BIN_STR) $(EE_BIN) $(EE_OBJS) $(IRX_SRCS)

irx_%.c: $(PS2SDK)/iop/irx/%.irx
$(BIN2C) $< irx_$*.c $*_irx

DEV9_irx.c: $(PS2SDK)/iop/irx/ps2dev9.irx
$(BIN2C) $< DEV9_irx.c DEV9_irx

NETMAN_irx.c: $(PS2SDK)/iop/irx/netman.irx
$(BIN2C) $< NETMAN_irx.c NETMAN_irx

SMAP_irx.c: $(PS2SDK)/iop/irx/smap.irx
$(BIN2C) $< SMAP_irx.c SMAP_irx

run: $(EE_BIN_PKD)
ps2client -h $(PS2IP) execee host:$(EE_BIN_PKD)

reset:
ps2client -h $(PS2IP) reset

ifdef PS2SDK
include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.eeglobal
endif
83 changes: 83 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# PS2 Joypad Server

Use PlayStation 2 input accessories that cheap "PS2 to USB" dongles don't recognize by dumping gamepad input into UDP packets.

## Building from source

(Tested only on Linux)

0. Set up [PS2SDK](https://github.com/ps2dev/ps2dev)
1. Run `make`

## Configuration

- Set up OPL networking within OPL and save;
- Copy the ELF to somewhere accessible (e.g.: MC1:/APPS/JOYSRV.ELF);
- Configure FMCB shortcuts.

## The client

There must be a UDP listener at:
- Same IP as configured in OPL;
- The port for SMB in OPL plus 1024:
- If you used the default port 445, it'll direct UDP towards port 1469.
- Capable of parsing and creating input in the system.


### Known ready-to-use implementations

- [ps2joycln](https://github.com/adlerosn/ps2joycln)

### Data format

Expect 71 bytes per datagram. The last byte will always be a '`\n`'. Therefore looking like:

`1006200079FFFF8080808000000000000000000000000000000000000000000000005A` - DualShock 2

`2002200041FFFF0000000000000000000000000000000000000000000000000000005A` - 2011 generic Dance Mat

After converting the trimmed hex string into a ByteArray:

- 1st byte: where is the controller connected
- 1st nibble: Controller connected to port 1 or 2
- 2nd nibble: [unused] The slot of the multitap that the gamepad is connected to
- 2nd byte: Pad state. Usable if either 2 or 6; unusable otherwise ([documentation on PAD_STATE_*](https://ps2dev.github.io/ps2sdk/libpad_8h.html))
- 3rd byte: Pad read status. Usable if non-zero; unusable otherwise ([documentation on padRead()](https://ps2dev.github.io/ps2sdk/libpad_8h.html#a3ce97ac47e0c081994494f37280c0bcb))
- 4th to 35th byte: [struct pad_button_status](https://ps2dev.github.io/ps2sdk/libpad_8h.html#structpad_button_status)
- 4th byte: `u8 ok` - zero is good
- 5th byte: `u8 mode` - ???
- 6th and 7th bytes: `u16le btns` - bit array for digital input for buttons; 1 = released, 0 = pressed.
- The field itself stores little endian, but here I show big endian for clarity:
- `0x0001` - `0b0000000000000001` - PAD_SELECT
- `0x0002` - `0b0000000000000010` - PAD_L3
- `0x0004` - `0b0000000000000100` - PAD_R3
- `0x0008` - `0b0000000000001000` - PAD_START
- `0x0010` - `0b0000000000010000` - PAD_UP
- `0x0020` - `0b0000000000100000` - PAD_RIGHT
- `0x0040` - `0b0000000001000000` - PAD_DOWN
- `0x0080` - `0b0000000010000000` - PAD_LEFT
- `0x0100` - `0b0000000100000000` - PAD_L2
- `0x0200` - `0b0000001000000000` - PAD_R2
- `0x0400` - `0b0000010000000000` - PAD_L1
- `0x0800` - `0b0000100000000000` - PAD_R1
- `0x1000` - `0b0001000000000000` - PAD_TRIANGLE
- `0x2000` - `0b0010000000000000` - PAD_CIRCLE
- `0x4000` - `0b0100000000000000` - PAD_CROSS
- `0x8000` - `0b1000000000000000` - PAD_SQUARE
- 8th byte: `u8 rjoy_h` - `00=left, FF=right, 80=neutral` - Right analog stick
- 9th byte: `u8 rjoy_v` - `00=up,__ FF=down,_ 80=neutral` - Right analog stick
- 10th byte: `u8 ljoy_h` - `00=left, FF=right, 80=neutral` - Left analog stick
- 11th byte: `u8 ljoy_v` - `00=up,__ FF=down,_ 80=neutral` - Left analog stick
- 12th byte: `u8 right_p` - Pressure senstivity for right directional - `00=released, FF=full pressure`
- 13th byte: `u8 left_p` - Pressure senstivity for left directional - `00=released, FF=full pressure`
- 14th byte: `u8 up_p` - Pressure senstivity for up directional - `00=released, FF=full pressure`
- 15th byte: `u8 down_p` - Pressure senstivity for down directional - `00=released, FF=full pressure`
- 16th byte: `u8 triangle_p` - Pressure senstivity for triangle - `00=released, FF=full pressure`
- 17th byte: `u8 circle_p` - Pressure senstivity for circle - `00=released, FF=full pressure`
- 18th byte: `u8 cross_p` - Pressure senstivity for cross - `00=released, FF=full pressure`
- 19th byte: `u8 square_p` - Pressure senstivity for circle - `00=released, FF=full pressure`
- 20th byte: `u8 l1_p` - Pressure senstivity for L1 - `00=released, FF=full pressure`
- 21th byte: `u8 r1_p` - Pressure senstivity for R1 - `00=released, FF=full pressure`
- 22th byte: `u8 l2_p` - Pressure senstivity for L2 - `00=released, FF=full pressure`
- 23th byte: `u8 r2_p` - Pressure senstivity for R2 - `00=released, FF=full pressure`
- 24th to 35th byte - ???
Loading

0 comments on commit 50840ae

Please sign in to comment.