ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
librm.c File Reference
#include <stdio.h>
#include <tamtypes.h>
#include <sifrpc.h>
#include <kernel.h>
#include <string.h>
#include "librm.h"
+ Include dependency graph for librm.c:

Go to the source code of this file.

Data Structures

struct  port_state
 

Functions

static struct rmEEDatarmGetDmaStr (int port, int slot)
 
int RMMan_Init (void)
 
u32 RMMan_GetModuleVersion (void)
 
int RMMan_Open (int port, int slot, void *pData)
 
int RMMan_End (void)
 
int RMMan_Close (int port, int slot)
 
void RMMan_Read (int port, int slot, struct remote_data *data)
 

Variables

static SifRpcClientData_t rmmanif
 
static struct rmRpcPacket buffer
 
static int rmman_init = 0
 
static struct port_state ports [2]
 

Detailed Description

RPC Interface for PS2 Remote Control Driver (RMMAN)

Definition in file librm.c.

Function Documentation

◆ rmGetDmaStr()

static struct rmEEData* rmGetDmaStr ( int  port,
int  slot 
)
static

Definition at line 36 of file librm.c.

38 {
39  struct rmEEData *pdata;
40 
41  pdata = ports[port].rmData;
42  SyncDCache(pdata, (u8 *)pdata + 256);
43 
44  return pdata;
45 
46  if(pdata[0].frame < pdata[1].frame) {
47  return &pdata[1];
48  }
49  else {
50  return &pdata[0];
51  }
52 }
void SyncDCache(void *start, void *end)
s32 port
Definition: libpad.c:176
static struct port_state ports[2]
Definition: librm.c:33
struct rmEEData * rmData
Definition: librm.c:30
unsigned char u8
Definition: tamtypes.h:23

References rmEEData::frame, port, ports, port_state::rmData, and SyncDCache().

Referenced by RMMan_Read().

◆ RMMan_Close()

int RMMan_Close ( int  port,
int  slot 
)

Definition at line 138 of file librm.c.

140 {
141  if((port < 0) || (port > 1) || (slot != 0))
142  {
143  printf("Error, port must be 0 or 1 and slot set to 0\n");
144  return 0;
145  }
146 
147  if(!ports[port].opened)
148  {
149  return 0;
150  }
151 
152  buffer.cmd.command = RMMAN_RPCFUNC_CLOSE;
153  buffer.cmd.port = port;
154  buffer.cmd.slot = slot;
155 
156  if (SifCallRpc(&rmmanif, 0, 0, &buffer, 128, &buffer, 128, NULL, NULL) < 0)
157  return 0;
158 
159  return buffer.cmd.result;
160 }
s32 slot
Definition: libpad.c:176
@ RMMAN_RPCFUNC_CLOSE
Definition: librm-common.h:47
static SifRpcClientData_t rmmanif
Definition: librm.c:23
static struct rmRpcPacket buffer
Definition: librm.c:24
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)
struct rmRpcPacket::@61::@63 cmd
#define NULL
Definition: tamtypes.h:91

References buffer, rmRpcPacket::cmd, NULL, port, ports, RMMAN_RPCFUNC_CLOSE, rmmanif, SifCallRpc(), and slot.

Referenced by main().

◆ RMMan_End()

int RMMan_End ( void  )

Definition at line 127 of file librm.c.

129 {
130  buffer.cmd.command = RMMAN_RPCFUNC_END;
131 
132  if (SifCallRpc(&rmmanif, 0, 0, &buffer, 128, &buffer, 128, NULL, NULL) < 0)
133  return 0;
134 
135  return buffer.cmd.result;
136 }
@ RMMAN_RPCFUNC_END
Definition: librm-common.h:45

References buffer, rmRpcPacket::cmd, NULL, RMMAN_RPCFUNC_END, rmmanif, and SifCallRpc().

Referenced by main().

◆ RMMan_GetModuleVersion()

u32 RMMan_GetModuleVersion ( void  )

Definition at line 87 of file librm.c.

89 {
91 
92  if (SifCallRpc(&rmmanif, 0, 0, &buffer, 128, &buffer, 128, NULL, NULL) < 0)
93  return 0;
94 
95  return buffer.cmd.result;
96 }
@ RMMAN_RPCFUNC_VERSION
Definition: librm-common.h:49

References buffer, rmRpcPacket::cmd, NULL, RMMAN_RPCFUNC_VERSION, rmmanif, and SifCallRpc().

Referenced by main().

◆ RMMan_Init()

int RMMan_Init ( void  )

Definition at line 54 of file librm.c.

56 {
57  if(rmman_init)
58  {
59  printf("RMMan Library already initialised\n");
60  return 0;
61  }
62 
64 
65  do {
66  if (SifBindRpc(&rmmanif, RMMAN_RPC_ID, 0) < 0) {
67  return -1;
68  }
69  nopdelay();
70  } while(!rmmanif.server);
71 
72  buffer.cmd.command = RMMAN_RPCFUNC_INIT;
73 
74  if (SifCallRpc(&rmmanif, 0, 0, &buffer, 128, &buffer, 128, NULL, NULL) < 0)
75  return -1;
76 
77  ports[0].opened = 0;
78  ports[0].rmData = NULL;
79  ports[1].opened = 1;
80  ports[1].rmData = NULL;
81 
82  rmman_init = 1;
83 
84  return buffer.cmd.result;
85 }
static void nopdelay(void)
Definition: kernel.h:141
#define RMMAN_RPC_ID
Definition: librm-common.h:42
@ RMMAN_RPCFUNC_INIT
Definition: librm-common.h:46
static int rmman_init
Definition: librm.c:25
int SifBindRpc(SifRpcClientData_t *client, int rpc_number, int mode)
struct t_SifRpcServerData * server
Definition: sifrpc.h:142
int opened
Definition: librm.c:29

References buffer, rmRpcPacket::cmd, nopdelay(), NULL, port_state::opened, ports, port_state::rmData, rmman_init, RMMAN_RPC_ID, RMMAN_RPCFUNC_INIT, rmmanif, SifRpcClientData_t::server, SifBindRpc(), and SifCallRpc().

Referenced by main().

◆ RMMan_Open()

int RMMan_Open ( int  port,
int  slot,
void *  pData 
)

Definition at line 98 of file librm.c.

100 {
101  if((port < 0) || (port > 1) || (slot != 0))
102  {
103  printf("Error, port must be 0 or 1 and slot set to 0\n");
104  return 0;
105  }
106 
107  if((u32) pData & 0x3F)
108  {
109  printf("Error, pData not aligned to 64byte boundary");
110  return 0;
111  }
112 
113  buffer.cmd.command = RMMAN_RPCFUNC_OPEN;
114  buffer.cmd.port = port;
115  buffer.cmd.slot = slot;
116  buffer.cmd.data = pData;
117 
118  if (SifCallRpc(&rmmanif, 0, 0, &buffer, 128, &buffer, 128, NULL, NULL) < 0)
119  return 0;
120 
121  ports[port].opened = 1;
122  ports[port].rmData = pData;
123 
124  return buffer.cmd.result;
125 }
@ RMMAN_RPCFUNC_OPEN
Definition: librm-common.h:48
unsigned int u32
Definition: tamtypes.h:30

References buffer, rmRpcPacket::cmd, NULL, port_state::opened, port, ports, port_state::rmData, RMMAN_RPCFUNC_OPEN, rmmanif, SifCallRpc(), and slot.

Referenced by main().

◆ RMMan_Read()

void RMMan_Read ( int  port,
int  slot,
struct remote_data data 
)

Definition at line 162 of file librm.c.

163 {
164  struct rmEEData *pdata;
165 
166  if((port < 0) || (port > 1) || (slot != 0))
167  {
168  printf("Error, port must be 0 or 1 and slot set to 0\n");
169  return;
170  }
171 
172  pdata = rmGetDmaStr(port, slot);
173 
174  memcpy(data, pdata->data, 8);
175 }
u32 data
Definition: libmouse.c:36
static struct rmEEData * rmGetDmaStr(int port, int slot)
Definition: librm.c:36
u8 data[32]
Definition: librm-common.h:35

References rmEEData::data, data, port, rmGetDmaStr(), and slot.

Referenced by main().

Variable Documentation

◆ buffer

struct rmRpcPacket buffer
static

Definition at line 23 of file librm.c.

Referenced by RMMan_Close(), RMMan_End(), RMMan_GetModuleVersion(), RMMan_Init(), and RMMan_Open().

◆ ports

struct port_state ports[2]
static

Definition at line 25 of file librm.c.

Referenced by rmGetDmaStr(), RMMan_Close(), RMMan_Init(), and RMMan_Open().

◆ rmman_init

int rmman_init = 0
static

Definition at line 25 of file librm.c.

Referenced by RMMan_Init().

◆ rmmanif

SifRpcClientData_t rmmanif
static

Definition at line 23 of file librm.c.

Referenced by RMMan_Close(), RMMan_End(), RMMan_GetModuleVersion(), RMMan_Init(), and RMMan_Open().