📜 ⬆️ ⬇️

Programming for PlayStation 2: Controller Library - Part 2

image
In the last article I talked about the module exclusively for the EE mode. In this chapter I will talk about a rather complicated, difficult to understand, but giving many possibilities module

This module is recommended to be used for games where only one joystick is used.
There is multitap support, but I will not talk about it for this module.

There is a special library libpad2. The library uses the Emotion Engine (EE) and Input Output Processor (IOP) coprocessor.
')


To use it, at the moment, it is possible only for conventional digital controllers, DualShock and DualShock 2.
Libraries for connecting EE: “libdbc.a” and “libpad2.a”. Header files: “libdbc.h” and “libpad2.h”.
Modules for IOP connection: “sio2man.irx” (version 2.4 or higher), “sio2d.irx”, “dbcman.irx”, controller driver modules (***. Irx).

IOP modules are loaded using the sceSifLoadModule () function after loading the EE application.
Modules use virtual sockets.

The following modules are used to connect controller drivers:

Module nameDigital controllerDualshockDualshock 2
ds1u.irxSupportsSupportsDualShock emulation
ds2u.irxSupportsSupportsSupports
dgco.irxSupportsDigital controller emulationDigital controller emulation
ds1o.irxNot compatibleSupportsDualShock emulation
ds2o.irxNot compatibleNot compatibleSupports

Drivers switch automatically when certain controllers are connected.

Also, the number of loaded drivers must match the number of controllers used.

How to do it?



Each controller has its own driver.
For controller 1, there are: ds1u_s1.irx, ds2u_s1.irx, dgco_s1.irx, ds1o_s1.irx, ds2o_s1.irx.
For controller 2: ds1u_d.irx, ds2u_d.irx, dgco_d.irx, ds1o_d.irx, ds2o_d.irx.
Use a second controller is not desirable.

Module procedures



sceSifLoadModule () is used to load sio2man.irx, sio2d.irx and dbcman.irx in the same sequence.
sceDbcInit () and scePad2Init () are used to initialize libdbc and libpad2.
scePad2CreateSocket () - used to create a socket for working with the controller. The first parameter is the port number (or NULL for the first controller) and the second is a 64 byte profile through which data will be transmitted.
scePad2ButtonProfile () - reads data from the socket and passes to the buffer. Parameters are socket and buffer.
scePad2Read () - reads button data. Parameters are the same.
scePad2GetState () - checks the state of the controller. Parameters are the same.
scePad2DeleteSocket () - deletes a socket. The parameter is the socket number.
scePad2End () and sceDbcEnd () - terminate the work of libpad2 and libdbc, respectively.

The simplest program code will look like this:

<br>main(){<br> int socket_number;<br> unsigned char rdata[32];<br> unsigned char profile[10];<br> u_long128 pad_buff[SCE_PAD2_DMA_BUFFER_MAX]__attribute__((aligned(64)));<br> sceDbcInit();<br> scePad2Init();<br> socket_number = scePad2CreateSocket( NULL, pad_buff );<br> while (1) {<br> scePad2ButtonProfile( socket_number, profile );<br> scePad2Read( socket_number, rdata );<br> // <br> }<br> scePad2DeleteSocket( socket_number );<br> scePad2End();<br> sceDbcEnd();<br>}<br> <br> * This source code was highlighted with Source Code Highlighter .


Controller profiles



The profile shows the features of the controllers, i.e. all information about the connected controller, which buttons are present and the number.

Each bit of the profile describes an individual controller feature. If the controller has the required capability, then the bit will be set to 1 and 0 - for lack of support.

The profile is 4 bytes of information that Sony wanted to expand in the future.

ByteBitButtonNumber of bits allocated
00Selectone
oneL3 (pressing the left stick)one
2R3 (click on the right stick)one
3Startone
fourUp arrowone
fiveRight arrowone
6Arrow to downone
7Left arrowone
oneeightL2one
9R2one
tenL1one
elevenR1one
12Triangleone
13A circleone
14Xone
15Squareone
2sixteenAnalog mode:
Right stick translated X
eight
17Analog mode:
Right stick translated by Y
eight
18Analog mode:
Left stick translated X
eight
nineteenAnalog mode:
Left stick translated by Y
eight
20Analog mode:
Right arrow
eight
21Analog mode:
Left arrow
eight
22Analog mode:
Up arrow
eight
23Analog mode:
Arrow to down
eight
324Analog mode:
Triangle
eight
25Analog mode:
A circle
eight
26Analog mode:
Cross
eight
27Analog mode:
Square
eight
28Analog mode:
L1
eight
29Analog mode:
R1
eight
thirtyAnalog mode:
L2
eight
31Analog mode:
R2
eight

Analog mode implies sensitivity.

For a digital controller, all analogs, R3 and L3 will be zero. Therefore, the profile for him will look like this:
ByteBitButtonNumber of bits allocated
00Selectone
oneStartone
2Up arrowone
3Right arrowone
fourArrow to downone
fiveLeft arrowone
6L2one
7R2one
oneeightL1one
9R1one
tenTriangleone
elevenA circleone
12Xone
13Squareone
14-Pusto-one
15-Pusto-one


Cases



It may happen that the user turns off the digital controller and connects the analog one.
The driver will switch automatically. And you can incorrectly process the data.
In case the controller is disabled, the scePad2GetState () function will return scePad2StateNoLink. If the controller is connected back after this, the scePad2GetState () function will return scePad2StateStable. It is advisable to call the scePad2GetState () function to check the disconnection before each frame.

At the end.



This type of information on the controller buttons is suitable for both modes.
Monitor the controllers must constantly.

On this about the controllers only the library of vibration remains, but I will tell you later, i.e. in the end.

PS : I think that's enough for today.

Source: https://habr.com/ru/post/135737/


All Articles