ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
librm.c
Go to the documentation of this file.
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # Copyright 2001-2004, ps2dev - http://www.ps2dev.org
7 # Licenced under Academic Free License version 2.0
8 # Review ps2sdk README & LICENSE files for further details.
9 */
10 
16 #include <stdio.h>
17 #include <tamtypes.h>
18 #include <sifrpc.h>
19 #include <kernel.h>
20 #include <string.h>
21 #include "librm.h"
22 
23 static SifRpcClientData_t rmmanif __attribute__((aligned(64)));
24 static struct rmRpcPacket buffer __attribute__((aligned(64)));
25 static int rmman_init = 0;
26 
27 struct port_state
28 {
29  int opened;
30  struct rmEEData *rmData;
31 };
32 
33 static struct port_state ports[2];
34 
35 static struct rmEEData*
37 
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 }
53 
54 int RMMan_Init(void)
55 
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 }
86 
88 
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 }
97 
98 int RMMan_Open(int port, int slot, void *pData)
99 
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 }
126 
127 int RMMan_End(void)
128 
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 }
137 
138 int RMMan_Close(int port, int slot)
139 
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 }
161 
162 void RMMan_Read(int port, int slot, struct remote_data *data)
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 }
static void nopdelay(void)
Definition: kernel.h:141
void SyncDCache(void *start, void *end)
u32 data
Definition: libmouse.c:36
s32 slot
Definition: libpad.c:176
s32 port
Definition: libpad.c:176
#define RMMAN_RPC_ID
Definition: librm-common.h:42
@ RMMAN_RPCFUNC_CLOSE
Definition: librm-common.h:47
@ RMMAN_RPCFUNC_OPEN
Definition: librm-common.h:48
@ RMMAN_RPCFUNC_VERSION
Definition: librm-common.h:49
@ RMMAN_RPCFUNC_END
Definition: librm-common.h:45
@ RMMAN_RPCFUNC_INIT
Definition: librm-common.h:46
void RMMan_Read(int port, int slot, struct remote_data *data)
Definition: librm.c:162
int RMMan_End(void)
Definition: librm.c:127
static SifRpcClientData_t rmmanif
Definition: librm.c:23
static struct rmRpcPacket buffer
Definition: librm.c:24
static int rmman_init
Definition: librm.c:25
int RMMan_Close(int port, int slot)
Definition: librm.c:138
int RMMan_Init(void)
Definition: librm.c:54
static struct port_state ports[2]
Definition: librm.c:33
int RMMan_Open(int port, int slot, void *pData)
Definition: librm.c:98
static struct rmEEData * rmGetDmaStr(int port, int slot)
Definition: librm.c:36
u32 RMMan_GetModuleVersion(void)
Definition: librm.c:87
int SifBindRpc(SifRpcClientData_t *client, int rpc_number, int mode)
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 t_SifRpcServerData * server
Definition: sifrpc.h:142
struct rmEEData * rmData
Definition: librm.c:30
int opened
Definition: librm.c:29
u8 data[32]
Definition: librm-common.h:35
struct rmRpcPacket::@61::@63 cmd
#define NULL
Definition: tamtypes.h:91
unsigned int u32
Definition: tamtypes.h:30
unsigned char u8
Definition: tamtypes.h:23