ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
libpad.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  padButtonStatus
 

Macros

#define PAD_LEFT   0x0080
 
#define PAD_DOWN   0x0040
 
#define PAD_RIGHT   0x0020
 
#define PAD_UP   0x0010
 
#define PAD_START   0x0008
 
#define PAD_R3   0x0004
 
#define PAD_L3   0x0002
 
#define PAD_SELECT   0x0001
 
#define PAD_SQUARE   0x8000
 
#define PAD_CROSS   0x4000
 
#define PAD_CIRCLE   0x2000
 
#define PAD_TRIANGLE   0x1000
 
#define PAD_R1   0x0800
 
#define PAD_L1   0x0400
 
#define PAD_R2   0x0200
 
#define PAD_L2   0x0100
 
#define PAD_STATE_DISCONN   0x00
 
#define PAD_STATE_FINDPAD   0x01
 
#define PAD_STATE_FINDCTP1   0x02
 
#define PAD_STATE_EXECCMD   0x05
 
#define PAD_STATE_STABLE   0x06
 
#define PAD_STATE_ERROR   0x07
 
#define PAD_RSTAT_COMPLETE   0x00
 
#define PAD_RSTAT_FAILED   0x01
 
#define PAD_RSTAT_BUSY   0x02
 
#define PAD_TYPE_NEJICON   0x2
 
#define PAD_TYPE_KONAMIGUN   0x3
 
#define PAD_TYPE_DIGITAL   0x4
 
#define PAD_TYPE_ANALOG   0x5
 
#define PAD_TYPE_NAMCOGUN   0x6
 
#define PAD_TYPE_DUALSHOCK   0x7
 
#define PAD_TYPE_JOGCON   0xE
 
#define PAD_TYPE_EX_TSURICON   0x100
 
#define PAD_TYPE_EX_JOGCON   0x300
 
#define PAD_MODECURID   1
 
#define PAD_MODECUREXID   2
 
#define PAD_MODECUROFFS   3
 
#define PAD_MODETABLE   4
 
#define PAD_MMODE_DIGITAL   0
 
#define PAD_MMODE_DUALSHOCK   1
 
#define PAD_MMODE_UNLOCK   2
 
#define PAD_MMODE_LOCK   3
 
#define PAD_ACTFUNC   1
 
#define PAD_ACTSUB   2
 
#define PAD_ACTSIZE   3
 
#define PAD_ACTCURR   4
 

Functions

int padInit (int mode)
 
int padPortInit (int mode)
 
int padEnd (void)
 
int padPortOpen (int port, int slot, void *padArea)
 
int padPortClose (int port, int slot)
 
unsigned char padRead (int port, int slot, struct padButtonStatus *data)
 
int padGetState (int port, int slot)
 
unsigned char padGetReqState (int port, int slot)
 
int padSetReqState (int port, int slot, int state)
 
void padStateInt2String (int state, char buf[16])
 
void padReqStateInt2String (int state, char buf[16])
 
int padGetPortMax (void)
 
int padGetSlotMax (int port)
 
int padGetModVersion ()
 
int padInfoMode (int port, int slot, int infoMode, int index)
 
int padSetMainMode (int port, int slot, int mode, int lock)
 
int padInfoPressMode (int port, int slot)
 
int padEnterPressMode (int port, int slot)
 
int padExitPressMode (int port, int slot)
 
int padGetButtonMask (int port, int slot)
 
int padSetButtonInfo (int port, int slot, int buttonInfo)
 
unsigned char padInfoAct (int port, int slot, int word, int byte)
 
int padSetActAlign (int port, int slot, char act_align[6])
 
int padSetActDirect (int port, int slot, char act_align[6])
 
int padGetConnection (int port, int slot)
 

Detailed Description

Pad externals

Definition in file libpad.h.

Macro Definition Documentation

◆ PAD_ACTCURR

#define PAD_ACTCURR   4

Definition at line 92 of file libpad.h.

◆ PAD_ACTFUNC

#define PAD_ACTFUNC   1

Definition at line 89 of file libpad.h.

◆ PAD_ACTSIZE

#define PAD_ACTSIZE   3

Definition at line 91 of file libpad.h.

◆ PAD_ACTSUB

#define PAD_ACTSUB   2

Definition at line 90 of file libpad.h.

◆ PAD_CIRCLE

#define PAD_CIRCLE   0x2000

Definition at line 33 of file libpad.h.

◆ PAD_CROSS

#define PAD_CROSS   0x4000

Definition at line 32 of file libpad.h.

◆ PAD_DOWN

#define PAD_DOWN   0x0040

Definition at line 24 of file libpad.h.

◆ PAD_L1

#define PAD_L1   0x0400

Definition at line 36 of file libpad.h.

◆ PAD_L2

#define PAD_L2   0x0100

Definition at line 38 of file libpad.h.

◆ PAD_L3

#define PAD_L3   0x0002

Definition at line 29 of file libpad.h.

◆ PAD_LEFT

#define PAD_LEFT   0x0080

Definition at line 23 of file libpad.h.

◆ PAD_MMODE_DIGITAL

#define PAD_MMODE_DIGITAL   0

Definition at line 80 of file libpad.h.

◆ PAD_MMODE_DUALSHOCK

#define PAD_MMODE_DUALSHOCK   1

Definition at line 81 of file libpad.h.

◆ PAD_MMODE_LOCK

#define PAD_MMODE_LOCK   3

Definition at line 84 of file libpad.h.

◆ PAD_MMODE_UNLOCK

#define PAD_MMODE_UNLOCK   2

Definition at line 83 of file libpad.h.

◆ PAD_MODECUREXID

#define PAD_MODECUREXID   2

Definition at line 73 of file libpad.h.

◆ PAD_MODECURID

#define PAD_MODECURID   1

Definition at line 72 of file libpad.h.

◆ PAD_MODECUROFFS

#define PAD_MODECUROFFS   3

Definition at line 74 of file libpad.h.

◆ PAD_MODETABLE

#define PAD_MODETABLE   4

Definition at line 75 of file libpad.h.

◆ PAD_R1

#define PAD_R1   0x0800

Definition at line 35 of file libpad.h.

◆ PAD_R2

#define PAD_R2   0x0200

Definition at line 37 of file libpad.h.

◆ PAD_R3

#define PAD_R3   0x0004

Definition at line 28 of file libpad.h.

◆ PAD_RIGHT

#define PAD_RIGHT   0x0020

Definition at line 25 of file libpad.h.

◆ PAD_RSTAT_BUSY

#define PAD_RSTAT_BUSY   0x02

Definition at line 55 of file libpad.h.

◆ PAD_RSTAT_COMPLETE

#define PAD_RSTAT_COMPLETE   0x00

Definition at line 53 of file libpad.h.

◆ PAD_RSTAT_FAILED

#define PAD_RSTAT_FAILED   0x01

Definition at line 54 of file libpad.h.

◆ PAD_SELECT

#define PAD_SELECT   0x0001

Definition at line 30 of file libpad.h.

◆ PAD_SQUARE

#define PAD_SQUARE   0x8000

Definition at line 31 of file libpad.h.

◆ PAD_START

#define PAD_START   0x0008

Definition at line 27 of file libpad.h.

◆ PAD_STATE_DISCONN

#define PAD_STATE_DISCONN   0x00

Definition at line 43 of file libpad.h.

◆ PAD_STATE_ERROR

#define PAD_STATE_ERROR   0x07

Definition at line 48 of file libpad.h.

◆ PAD_STATE_EXECCMD

#define PAD_STATE_EXECCMD   0x05

Definition at line 46 of file libpad.h.

◆ PAD_STATE_FINDCTP1

#define PAD_STATE_FINDCTP1   0x02

Definition at line 45 of file libpad.h.

◆ PAD_STATE_FINDPAD

#define PAD_STATE_FINDPAD   0x01

Definition at line 44 of file libpad.h.

◆ PAD_STATE_STABLE

#define PAD_STATE_STABLE   0x06

Definition at line 47 of file libpad.h.

◆ PAD_TRIANGLE

#define PAD_TRIANGLE   0x1000

Definition at line 34 of file libpad.h.

◆ PAD_TYPE_ANALOG

#define PAD_TYPE_ANALOG   0x5

Definition at line 63 of file libpad.h.

◆ PAD_TYPE_DIGITAL

#define PAD_TYPE_DIGITAL   0x4

Definition at line 62 of file libpad.h.

◆ PAD_TYPE_DUALSHOCK

#define PAD_TYPE_DUALSHOCK   0x7

Definition at line 65 of file libpad.h.

◆ PAD_TYPE_EX_JOGCON

#define PAD_TYPE_EX_JOGCON   0x300

Definition at line 68 of file libpad.h.

◆ PAD_TYPE_EX_TSURICON

#define PAD_TYPE_EX_TSURICON   0x100

Definition at line 67 of file libpad.h.

◆ PAD_TYPE_JOGCON

#define PAD_TYPE_JOGCON   0xE

Definition at line 66 of file libpad.h.

◆ PAD_TYPE_KONAMIGUN

#define PAD_TYPE_KONAMIGUN   0x3

Definition at line 61 of file libpad.h.

◆ PAD_TYPE_NAMCOGUN

#define PAD_TYPE_NAMCOGUN   0x6

Definition at line 64 of file libpad.h.

◆ PAD_TYPE_NEJICON

#define PAD_TYPE_NEJICON   0x2

Definition at line 60 of file libpad.h.

◆ PAD_UP

#define PAD_UP   0x0010

Definition at line 26 of file libpad.h.

Function Documentation

◆ padEnd()

int padEnd ( void  )

Ends all pad communication Note: PADMAN from release 1.3.4 does not have padPortInit implemented. As a result, it is impossible to reinitialize libpad after calling padEnd(). This was known as padClose in the really early official SDK releases.

Returns
== 1 => OK

Definition at line 372 of file libpad.c.

373 {
374 
375  int ret;
376 
377 
378  buffer.command=PAD_RPCCMD_END;
379 
380  if (SifCallRpc(&padsif[0], 1, 0, &buffer, 128, &buffer, 128, NULL, NULL) < 0)
381  return -1;
382 
383  ret = buffer.padResult.result;
384  if (ret == 1) {
385  padInitialised = 0;
386  }
387 
388  return ret;
389 }
static int padInitialised
Definition: libpad.c:151
static SifRpcClientData_t padsif[2]
Definition: libpad.c:154
char buffer[128]
Definition: libpad.c:232
#define PAD_RPCCMD_END
Definition: libpad.c:64
int SifCallRpc(SifRpcClientData_t *client, int rpc_number, int mode, void *send, int ssize, void *receive, int rsize, SifRpcEndFunc_t end_function, void *end_param)
#define NULL
Definition: tamtypes.h:91

References buffer, NULL, PAD_RPCCMD_END, padInitialised, padsif, and SifCallRpc().

◆ padEnterPressMode()

int padEnterPressMode ( int  port,
int  slot 
)

Pressure sensitive mode ON

Definition at line 690 of file libpad.c.

691 {
692  return padSetButtonInfo(port, slot, 0xFFF);
693 }
int padSetButtonInfo(int port, int slot, int buttonInfo)
Definition: libpad.c:717
s32 slot
Definition: libpad.c:176
s32 port
Definition: libpad.c:176

References padSetButtonInfo(), port, and slot.

Referenced by initializePad(), main(), and pad_set_sensitivity().

◆ padExitPressMode()

int padExitPressMode ( int  port,
int  slot 
)

Check for newer version Pressure sensitive mode OFF

Definition at line 696 of file libpad.c.

697 {
698  return padSetButtonInfo(port, slot, 0);
699 
700 }

References padSetButtonInfo(), port, and slot.

Referenced by main(), and pad_set_sensitivity().

◆ padGetButtonMask()

int padGetButtonMask ( int  port,
int  slot 
)

Definition at line 703 of file libpad.c.

704 {
705 
706  buffer.padGetButtonMaskArgs.command = PAD_RPCCMD_GET_BTNMASK;
707  buffer.padGetButtonMaskArgs.port = port;
708  buffer.padGetButtonMaskArgs.slot = slot;
709 
710  if (SifCallRpc(&padsif[0], 1, 0, &buffer, 128, &buffer, 128, NULL, NULL) < 0)
711  return 0;
712 
713  return buffer.padResult.result;
714 }
#define PAD_RPCCMD_GET_BTNMASK
Definition: libpad.c:58

References buffer, NULL, PAD_RPCCMD_GET_BTNMASK, padsif, port, SifCallRpc(), and slot.

Referenced by padInfoPressMode().

◆ padGetConnection()

int padGetConnection ( int  port,
int  slot 
)

Returns whether the device at port,slot is connected (1 = connected) Appears to have been removed very early during the PS2's lifetime. If possible, use the documented padGetState instead.

NOT SUPPORTED with module rom0:padman

Definition at line 823 of file libpad.c.

824 {
825 #ifdef _XPAD
826  struct open_slot *oslot;
827 
828  oslot = padGetConnDmaStr();
829 
830  return ((oslot->openSlots[port] >> slot) & 0x1);
831 #else
832  return 1;
833 #endif
834 }

References port, and slot.

◆ padGetModVersion()

int padGetModVersion ( )

Returns the padman.irx version NOT SUPPORTED on module rom0:padman

Definition at line 573 of file libpad.c.

574 {
575 #ifdef _XPAD
576  buffer.command = PAD_RPCCMD_GET_MODVER;
577 
578  if (SifCallRpc(&padsif[0], 1, 0, &buffer, 128, &buffer, 128, NULL, NULL) < 0)
579  return -1;
580 
581  return buffer.padResult.result;
582 #else
583  return 1; // Well.. return a low version #
584 #endif
585 }

References buffer, NULL, padsif, and SifCallRpc().

◆ padGetPortMax()

int padGetPortMax ( void  )

Returns # slots on the PS2 (usally 2)

Definition at line 548 of file libpad.c.

549 {
550 
551  buffer.command = PAD_RPCCMD_GET_PORTMAX;
552 
553  if (SifCallRpc(&padsif[0], 1, 0, &buffer, 128, &buffer, 128, NULL, NULL) < 0)
554  return -1;
555 
556  return buffer.padResult.result;
557 }
#define PAD_RPCCMD_GET_PORTMAX
Definition: libpad.c:61

References buffer, NULL, PAD_RPCCMD_GET_PORTMAX, padsif, and SifCallRpc().

Referenced by main().

◆ padGetReqState()

unsigned char padGetReqState ( int  port,
int  slot 
)

Get pad request state

Definition at line 511 of file libpad.c.

512 {
513 
514  struct pad_data *pdata;
515 
516  pdata = padGetDmaStr(port, slot);
517  return pdata->reqState;
518 }
static struct pad_data * padGetDmaStr(int port, int slot)
Definition: libpad.c:253
unsigned char reqState
Definition: libpad.c:124

References padGetDmaStr(), port, pad_data::reqState, and slot.

Referenced by padGetState(), and padWait().

◆ padGetSlotMax()

int padGetSlotMax ( int  port)

Returns # slots the port has (usually 1) probably 4 if using a multi tap (not tested)

Definition at line 560 of file libpad.c.

561 {
562 
563  buffer.padSlotMaxArgs.command = PAD_RPCCMD_GET_SLOTMAX;
564  buffer.padSlotMaxArgs.port = port;
565 
566  if (SifCallRpc(&padsif[0], 1, 0, &buffer, 128, &buffer, 128, NULL, NULL) < 0)
567  return -1;
568 
569  return buffer.padResult.result;
570 }
#define PAD_RPCCMD_GET_SLOTMAX
Definition: libpad.c:62

References buffer, NULL, PAD_RPCCMD_GET_SLOTMAX, padsif, port, and SifCallRpc().

Referenced by main().

◆ padGetState()

int padGetState ( int  port,
int  slot 
)

Get current pad state Wait until state == 6 (Ready) before trying to access the pad

Definition at line 482 of file libpad.c.

483 {
484  struct pad_data *pdata;
485  unsigned char state;
486 
487 
488  pdata = padGetDmaStr(port, slot);
489 
490  state = pdata->state;
491 
492 #ifdef _XPAD
493  if (state == PAD_STATE_ERROR)
494  {
495  if (pdata->findPadRetries)
496  {
497  return PAD_STATE_FINDPAD;
498  }
499  }
500 #endif
501 
502  if (state == PAD_STATE_STABLE) { // Ok
504  return PAD_STATE_EXECCMD;
505  }
506  }
507  return state;
508 }
unsigned char padGetReqState(int port, int slot)
Definition: libpad.c:511
#define PAD_STATE_ERROR
Definition: libpad.h:48
#define PAD_STATE_EXECCMD
Definition: libpad.h:46
#define PAD_RSTAT_BUSY
Definition: libpad.h:55
#define PAD_STATE_FINDPAD
Definition: libpad.h:44
#define PAD_STATE_STABLE
Definition: libpad.h:47
unsigned char state
Definition: libpad.c:123

References PAD_RSTAT_BUSY, PAD_STATE_ERROR, PAD_STATE_EXECCMD, PAD_STATE_FINDPAD, PAD_STATE_STABLE, padGetDmaStr(), padGetReqState(), port, slot, and pad_data::state.

Referenced by find_controllers(), main(), pad_get_state(), padWait(), and waitPadReady().

◆ padInfoAct()

unsigned char padInfoAct ( int  port,
int  slot,
int  word,
int  byte 
)

Get actuator status for this controller If padInfoAct(port, slot, -1, 0) != 0, the controller has actuators (i think ;) )

Definition at line 738 of file libpad.c.

739 {
740 #ifdef _XPAD
741  struct pad_data *pdata;
742 
743  pdata = padGetDmaStr(port, slot);
744 
745  if (pdata->currentTask != 1)
746  return 0;
747  if (pdata->modeConfig < 2)
748  return 0;
749  if (actuator >= pdata->nrOfActuators)
750  return 0;
751 
752  if (actuator == -1)
753  return pdata->nrOfActuators; // # of acutators?
754 
755  if (cmd >= 4)
756  return 0;
757 
758  return pdata->actData[actuator*4+cmd];
759 #else
760  buffer.padInfoActArgs.command = PAD_RPCCMD_INFO_ACT;
761  buffer.padInfoActArgs.port = port;
762  buffer.padInfoActArgs.slot = slot;
763  buffer.padInfoActArgs.actuator = actuator;
764  buffer.padInfoActArgs.act_cmd = cmd;
765 
766  if (SifCallRpc(&padsif[0], 1, 0, &buffer, 128, &buffer, 128, NULL, NULL) < 0)
767  return 0;
768 
769  if (buffer.padModeResult.result == 1) {
771  }
772  return buffer.padModeResult.result;
773 #endif
774 }
int padSetReqState(int port, int slot, int state)
Definition: libpad.c:521
s32 actuator
Definition: libpad.c:223
#define PAD_RPCCMD_INFO_ACT
Definition: libpad.c:52

References actuator, buffer, NULL, PAD_RPCCMD_INFO_ACT, PAD_RSTAT_BUSY, padGetDmaStr(), padSetReqState(), padsif, port, SifCallRpc(), and slot.

Referenced by initializePad(), main(), and pad_init_actuators().

◆ padInfoMode()

int padInfoMode ( int  port,
int  slot,
int  infoMode,
int  index 
)

Get pad info (digital (4), dualshock (7), etc..)

Returns
3 - KONAMI GUN; 4 - DIGITAL PAD; 5 - JOYSTICK; 6 - NAMCO GUN; 7 - DUAL SHOCK

Definition at line 588 of file libpad.c.

589 {
590 #ifdef _XPAD
591  struct pad_data *pdata;
592 
593  pdata = padGetDmaStr(port, slot);
594 
595  if (pdata->currentTask != 1)
596  return 0;
597  if (pdata->reqState == PAD_RSTAT_BUSY)
598  return 0;
599 
600  switch(infoMode) {
601  case PAD_MODECURID:
602  if (pdata->modeCurId == 0xF3)
603  return 0;
604  else
605  return (pdata->modeCurId >> 4);
606  break;
607 
608  case PAD_MODECUREXID:
609  if (pdata->modeConfig == pdata->currentTask)
610  return 0;
611  return pdata->modeTable[pdata->modeCurOffs];
612  break;
613 
614  case PAD_MODECUROFFS:
615  if (pdata->modeConfig != 0)
616  return pdata->modeCurOffs;
617  else
618  return 0;
619  break;
620 
621  case PAD_MODETABLE:
622  if (pdata->modeConfig != 0) {
623  if(index == -1) {
624  return pdata->nrOfModes;
625  }
626  else if (index < pdata->nrOfModes) {
627  return pdata->modeTable[index];
628  }
629  else {
630  return 0;
631  }
632  }
633  else
634  return 0;
635  break;
636  }
637  return 0;
638 #else
639  buffer.padInfoModeArgs.command = PAD_RPCCMD_INFO_MODE;
640  buffer.padInfoModeArgs.port = port;
641  buffer.padInfoModeArgs.slot = slot;
642  buffer.padInfoModeArgs.infoMode = infoMode;
643  buffer.padInfoModeArgs.index = index;
644 
645  if (SifCallRpc(&padsif[0], 1, 0, &buffer, 128, &buffer, 128, NULL, NULL) < 0)
646  return 0;
647 
648  if (buffer.padModeResult.result == 1) {
650  }
651  return buffer.padModeResult.result;
652 #endif
653 }
s32 index
Definition: libpad.c:194
#define PAD_RPCCMD_INFO_MODE
Definition: libpad.c:54
s32 infoMode
Definition: libpad.c:193
#define PAD_MODECUREXID
Definition: libpad.h:73
#define PAD_MODECUROFFS
Definition: libpad.h:74
#define PAD_MODECURID
Definition: libpad.h:72
#define PAD_MODETABLE
Definition: libpad.h:75

References buffer, index, infoMode, NULL, PAD_MODECUREXID, PAD_MODECURID, PAD_MODECUROFFS, PAD_MODETABLE, PAD_RPCCMD_INFO_MODE, PAD_RSTAT_BUSY, padGetDmaStr(), padSetReqState(), padsif, port, pad_data::reqState, SifCallRpc(), and slot.

Referenced by initializePad(), main(), pad_get_num_modes(), pad_get_type(), pad_has_type(), and pad_init_actuators().

◆ padInfoPressMode()

int padInfoPressMode ( int  port,
int  slot 
)

Check if the pad has pressure sensitive buttons

Definition at line 675 of file libpad.c.

676 {
677  int mask;
678 
679  mask = padGetButtonMask(port, slot);
680 
681  if (mask^0x3ffff) {
682  return 0;
683  }
684  else {
685  return 1;
686  }
687 }
int padGetButtonMask(int port, int slot)
Definition: libpad.c:703

References padGetButtonMask(), port, and slot.

Referenced by initializePad(), main(), and pad_set_sensitivity().

◆ padInit()

int padInit ( int  mode)

Initialise libpad

Parameters
modeMust be set to 0.
Returns
== 1 => OK

Definition at line 297 of file libpad.c.

298 {
299  // Version check isn't used by default
300  // int ver;
301  static int _rb_count = 0;
302 
303  if (_rb_count != _iop_reboot_count)
304  {
305  _rb_count = _iop_reboot_count;
306  padInitialised = 0;
307  }
308 
309  if(padInitialised)
310  return 0;
311 
312  padInitialised = 1;
313 
314  padsif[0].server = NULL;
315  padsif[1].server = NULL;
316 
317  do {
318  if (SifBindRpc(&padsif[0], PAD_BIND_RPC_ID1, 0) < 0) {
319  return -1;
320  }
321  nopdelay();
322  } while(!padsif[0].server);
323 
324  do {
325  if (SifBindRpc(&padsif[1], PAD_BIND_RPC_ID2, 0) < 0) {
326  return -3;
327  }
328  nopdelay();
329  } while(!padsif[1].server);
330 
331  // If you require a special version of the padman, check for that here (uncomment)
332  // ver = padGetModVersion();
333 
334  //At v1.3.4, this used to return 1 (and padPortInit is not used). But we are interested in the better design from release 1.4.
335  return padPortInit(mode);
336 }
static void nopdelay(void)
Definition: kernel.h:141
int padPortInit(int mode)
Definition: libpad.c:338
int _iop_reboot_count
s32 mode
Definition: libpad.c:184
#define PAD_BIND_RPC_ID1
Definition: libpad.c:48
#define PAD_BIND_RPC_ID2
Definition: libpad.c:49
int SifBindRpc(SifRpcClientData_t *client, int rpc_number, int mode)
struct t_SifRpcServerData * server
Definition: sifrpc.h:142

References _iop_reboot_count, mode, nopdelay(), NULL, PAD_BIND_RPC_ID1, PAD_BIND_RPC_ID2, padInitialised, padPortInit(), padsif, SifRpcClientData_t::server, and SifBindRpc().

Referenced by main().

◆ padPortClose()

int padPortClose ( int  port,
int  slot 
)

Closes an opened port.

Parameters
portPort to close
slotSlot to close
Returns
!= 0 => OK

Definition at line 449 of file libpad.c.

450 {
451 
452  int ret;
453 
454  buffer.padCloseArgs.command = PAD_RPCCMD_CLOSE;
455  buffer.padCloseArgs.port = port;
456  buffer.padCloseArgs.slot = slot;
457  buffer.padCloseArgs.mode = 1;
458 
459  ret = SifCallRpc(&padsif[0], 1, 0, &buffer, 128, &buffer, 128, NULL, NULL);
460 
461  if(ret < 0)
462  return ret;
463  else {
464  PadState[port][slot].open = 0;
465  return buffer.padResult.result;
466  }
467 }
#define PAD_RPCCMD_CLOSE
Definition: libpad.c:63
static struct pad_state PadState[2][8]
Definition: libpad.c:244
int open
Definition: libpad.c:74

References buffer, NULL, pad_state::open, PAD_RPCCMD_CLOSE, padsif, PadState, port, SifCallRpc(), and slot.

Referenced by find_controllers(), and pad_close().

◆ padPortInit()

int padPortInit ( int  mode)

Initialise pad ports. Automatically called by padInit(), there is no need to call this function directly.

Parameters
modeMust be set to 0.
Returns
== 1 => OK

Note: PADMAN from release 1.3.4 does not have this function implemented. As a result, it is impossible to reinitialize libpad after calling padEnd().

Returns
== 1 => OK

Definition at line 338 of file libpad.c.

339 {
340 #ifdef _XPAD //Unofficial: libpad EE client from v1.3.4 has this RPC function implemented, but is not implemented within its PADMAN module.
341  int ret;
342 #endif
343  int i;
344 
345  for(i = 0; i<8; i++)
346  {
347  PadState[0][i].open = 0;
348  PadState[0][i].port = 0;
349  PadState[0][i].slot = 0;
350  PadState[1][i].open = 0;
351  PadState[1][i].port = 0;
352  PadState[1][i].slot = 0;
353  }
354 
355 #ifdef _XPAD //Unofficial: libpad EE client from v1.3.4 has this RPC function implemented, but is not implemented within its PADMAN module.
356 
357 #ifdef _XPAD
358  buffer.padInitArgs.command = PAD_RPCCMD_INIT;
359  buffer.padInitArgs.statBuf = openSlot;
360 #else
361  buffer.command = PAD_RPCCMD_INIT;
362 #endif
363  ret = SifCallRpc( &padsif[0], 1, 0, &buffer, 128, &buffer, 128, NULL, NULL);
364 
365  return(ret >= 0 ? buffer.padResult.result : 0);
366 #else
367  return 1;
368 #endif
369 }
#define PAD_RPCCMD_INIT
Definition: libpad.c:65
unsigned int port
Definition: libpad.c:75
unsigned int slot
Definition: libpad.c:76

References buffer, NULL, pad_state::open, PAD_RPCCMD_INIT, padsif, PadState, pad_state::port, SifCallRpc(), and pad_state::slot.

Referenced by padInit().

◆ padPortOpen()

int padPortOpen ( int  port,
int  slot,
void *  padArea 
)
Parameters
portPort to open
slotSlot to open
padAreaThe address of the buffer for storing the pad status. Must be a 256-byte region (2xsizeof(struct pad_data). Must be a 64-byte aligned address. For the old libpad, at least 16-bytes alignment.
Returns
!= 0 => OK

Definition at line 392 of file libpad.c.

393 {
394 
395  int i;
396  struct pad_data *dma_buf = (struct pad_data *)padArea;
397 
398 #ifndef _XPAD
399  // Check 16 byte alignment
400  if((u32)padArea & 0xf) {
401  printf("Address is not 16-byte aligned.\n");
402  return 0;
403  }
404 #else
405  // Check 64 byte alignment
406  if((u32)padArea & 0x3f) {
407  printf("Address is not 16-byte aligned.\n");
408  return 0;
409  }
410 #endif
411 
412  for (i=0; i<2; i++) { // Pad data is double buffered
413  memset(dma_buf[i].data, 0xff, 32); // 'Clear' data area
414  dma_buf[i].frame = 0;
415  dma_buf[i].length = 0;
416  dma_buf[i].state = PAD_STATE_EXECCMD;
417  dma_buf[i].reqState = PAD_RSTAT_BUSY;
418 #ifndef _XPAD
419  dma_buf[i].ok = 0;
420 #endif
421 #ifdef _XPAD
422  dma_buf[i].currentTask = 0;
423 #endif
424  dma_buf[i].length = 0;
425 #ifdef _XPAD
426  dma_buf[i].buttonDataReady = 0; // Should be cleared in newer padman
427 #endif
428  }
429 
430 
431  buffer.padOpenArgs.command = PAD_RPCCMD_OPEN;
432  buffer.padOpenArgs.port = port;
433  buffer.padOpenArgs.slot = slot;
434  buffer.padOpenArgs.padArea = padArea;
435 
436  if(SifCallRpc(&padsif[0], 1, 0, &buffer, 128, &buffer, 128, NULL, NULL) < 0)
437  {
438  return 0;
439  }
440 
441  PadState[port][slot].open = 1;
443  PadState[port][slot].padBuf = buffer.padOpenResult.padBuf;
444 
445  return buffer.padOpenResult.result;
446 }
u32 data
Definition: libmouse.c:36
#define PAD_RPCCMD_OPEN
Definition: libpad.c:51
void * padArea
Definition: libpad.c:178
unsigned char ok
Definition: libpad.c:125
unsigned int frame
Definition: libpad.c:122
unsigned int length
Definition: libpad.c:128
struct pad_data * padData
Definition: libpad.c:77
unsigned char * padBuf
Definition: libpad.c:78
unsigned int u32
Definition: tamtypes.h:30

References buffer, data, pad_data::frame, pad_data::length, NULL, pad_data::ok, pad_state::open, PAD_RPCCMD_OPEN, PAD_RSTAT_BUSY, PAD_STATE_EXECCMD, padArea, pad_state::padBuf, pad_state::padData, padsif, PadState, port, pad_data::reqState, SifCallRpc(), slot, and pad_data::state.

Referenced by find_controllers(), main(), and pad_open().

◆ padRead()

unsigned char padRead ( int  port,
int  slot,
struct padButtonStatus data 
)

Read pad data

Parameters
portPort number of the pad to get the status for.
slotSlot number of the pad to get the status for.
dataA pointer to a 32 byte array where the result is stored
Returns
!= 0 => OK

Definition at line 470 of file libpad.c.

471 {
472 
473  struct pad_data *pdata;
474 
475  pdata = padGetDmaStr(port, slot);
476 
477  memcpy(data, pdata->data, pdata->length);
478  return pdata->length;
479 }
unsigned char data[32]
Definition: libpad.c:127

References data, pad_data::data, pad_data::length, padGetDmaStr(), port, and slot.

Referenced by main(), and pad_get_buttons().

◆ padReqStateInt2String()

void padReqStateInt2String ( int  state,
char  buf[16] 
)

Definition at line 541 of file libpad.c.

542 {
543  if(state < 4)
544  strcpy(buf, padReqStateString[state]);
545 }
static const char padReqStateString[3][16]
Definition: libpad.c:149

References padReqStateString, and pad_data::state.

◆ padSetActAlign()

int padSetActAlign ( int  port,
int  slot,
char  act_align[6] 
)

Initalise actuators. On dual shock controller: act_align[0] = 0 enables 'small' engine act_align[1] = 1 enables 'big' engine set act_align[2-5] to 0xff (disable)

Definition at line 777 of file libpad.c.

778 {
779  int i;
780  s8 *ptr;
781 
782  buffer.padActDirAlignArgs.command = PAD_RPCCMD_SET_ACTALIGN;
783  buffer.padActDirAlignArgs.port = port;
784  buffer.padActDirAlignArgs.slot = slot;
785 
786  ptr = buffer.padActDirAlignArgs.align;
787  for (i=0; i<6; i++)
788  ptr[i]=actAlign[i];
789 
790  if (SifCallRpc(&padsif[0], 1, 0, &buffer, 128, &buffer, 128, NULL, NULL) < 0)
791  return 0;
792 
793  if (buffer.padModeResult.result == 1) {
795  }
796  return buffer.padModeResult.result;
797 }
#define PAD_RPCCMD_SET_ACTALIGN
Definition: libpad.c:57
static char actAlign[6]
Definition: pad.c:30
signed char s8
Definition: tamtypes.h:51

References actAlign, buffer, NULL, PAD_RPCCMD_SET_ACTALIGN, PAD_RSTAT_BUSY, padSetReqState(), padsif, port, SifCallRpc(), and slot.

Referenced by initializePad(), main(), and pad_init_actuators().

◆ padSetActDirect()

int padSetActDirect ( int  port,
int  slot,
char  act_align[6] 
)

Set actuator status on dual shock controller, act_align[0] = 0/1 turns off/on 'small' engine act_align[1] = 0-255 sets 'big' engine speed

Definition at line 800 of file libpad.c.

801 {
802  int i;
803  s8 *ptr;
804 
805  buffer.padActDirAlignArgs.command = PAD_RPCCMD_SET_ACTDIR;
806  buffer.padActDirAlignArgs.port = port;
807  buffer.padActDirAlignArgs.slot = slot;
808 
809  ptr = buffer.padActDirAlignArgs.align;
810  for (i=0; i<6; i++)
811  ptr[i]=actAlign[i];
812 
813  if (SifCallRpc(&padsif[0], 1, 0, &buffer, 128, &buffer, 128, NULL, NULL) < 0)
814  return 0;
815 
816  return buffer.padModeResult.result;
817 }
#define PAD_RPCCMD_SET_ACTDIR
Definition: libpad.c:56

References actAlign, buffer, NULL, PAD_RPCCMD_SET_ACTDIR, padsif, port, SifCallRpc(), and slot.

Referenced by main(), pad_set_actuators(), and padStartAct().

◆ padSetButtonInfo()

int padSetButtonInfo ( int  port,
int  slot,
int  buttonInfo 
)

Definition at line 717 of file libpad.c.

718 {
719  int val;
720 
721  buffer.padSetButtonInfoArgs.command = PAD_RPCCMD_SET_BTNINFO;
722  buffer.padSetButtonInfoArgs.port = port;
723  buffer.padSetButtonInfoArgs.slot = slot;
724  buffer.padSetButtonInfoArgs.buttonInfo = buttonInfo;
725 
726  if (SifCallRpc(&padsif[0], 1, 0, &buffer, 128, &buffer, 128, NULL, NULL) < 0)
727  return 0;
728 
729  val = buffer.padSetButtonInfoResult.result;
730 
731  if (val == 1) {
733  }
734  return buffer.padSetButtonInfoResult.result;
735 }
s32 buttonInfo
Definition: libpad.c:213
#define PAD_RPCCMD_SET_BTNINFO
Definition: libpad.c:59

References buffer, buttonInfo, NULL, PAD_RPCCMD_SET_BTNINFO, PAD_RSTAT_BUSY, padSetReqState(), padsif, port, SifCallRpc(), and slot.

Referenced by padEnterPressMode(), and padExitPressMode().

◆ padSetMainMode()

int padSetMainMode ( int  port,
int  slot,
int  mode,
int  lock 
)

mode = 1, -> Analog/dual shock enabled; mode = 0 -> Digital lock = 3 -> Mode not changeable by user

Definition at line 656 of file libpad.c.

657 {
658 
659  buffer.padSetMainModeArgs.command = PAD_RPCCMD_SET_MMODE;
660  buffer.padSetMainModeArgs.port = port;
661  buffer.padSetMainModeArgs.slot = slot;
662  buffer.padSetMainModeArgs.mode = mode;
663  buffer.padSetMainModeArgs.lock = lock;
664 
665  if (SifCallRpc(&padsif[0], 1, 0, &buffer, 128, &buffer, 128, NULL, NULL) < 0)
666  return 0;
667 
668  if (buffer.padModeResult.result == 1) {
670  }
671  return buffer.padModeResult.result;
672 }
s32 lock
Definition: libpad.c:200
#define PAD_RPCCMD_SET_MMODE
Definition: libpad.c:55

References buffer, lock, mode, NULL, PAD_RPCCMD_SET_MMODE, PAD_RSTAT_BUSY, padSetReqState(), padsif, port, SifCallRpc(), and slot.

Referenced by initializePad(), main(), and pad_set_mode().

◆ padSetReqState()

int padSetReqState ( int  port,
int  slot,
int  state 
)

Set pad request state (after a param setting) No need to export this one perhaps..

Definition at line 521 of file libpad.c.

522 {
523 
524  struct pad_data *pdata;
525 
526  pdata = padGetDmaStr(port, slot);
527  pdata->reqState = state;
528  return 1;
529 }

References padGetDmaStr(), port, pad_data::reqState, slot, and pad_data::state.

Referenced by padInfoAct(), padInfoMode(), padSetActAlign(), padSetButtonInfo(), and padSetMainMode().

◆ padStateInt2String()

void padStateInt2String ( int  state,
char  buf[16] 
)

Definition at line 532 of file libpad.c.

533 {
534 
535  if(state < 8) {
536  strcpy(buf, padStateString[state]);
537  }
538 }
static const char padStateString[8][16]
Definition: libpad.c:146

References padStateString, and pad_data::state.

Referenced by waitPadReady().