ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
libmtap.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 <tamtypes.h>
17 #include <string.h>
18 #include <kernel.h>
19 #include <sifrpc.h>
20 #include <stdarg.h>
21 
22 #include "libmtap.h"
23 
24 #define MTAPSERV_PORT_OPEN 0x80000901
25 #define MTAPSERV_PORT_CLOSE 0x80000902
26 #define MTAPSERV_GET_CONNECTION 0x80000903
27 
28 static unsigned int mtapRpcBuffer[32] __attribute__((aligned (64)));
29 static struct t_SifRpcClientData clientPortOpen __attribute__((aligned (64)));
30 static struct t_SifRpcClientData clientPortClose __attribute__((aligned (64)));
31 static struct t_SifRpcClientData clientGetConnection __attribute__((aligned (64)));
32 static int mtapInited = 0;
33 
34 int mtapInit(void)
35 {
36  if(mtapInited) return -1;
37 
38  while(1)
39  {
40  if (SifBindRpc(&clientPortOpen, MTAPSERV_PORT_OPEN, 0) < 0) return -1;
41  if (clientPortOpen.server != 0) break;
42 
43  nopdelay();
44  }
45 
46  while(1)
47  {
48  if (SifBindRpc(&clientPortClose, MTAPSERV_PORT_CLOSE, 0) < 0) return -1;
49  if (clientPortClose.server != 0) break;
50 
51  nopdelay();
52  }
53 
54  while(1)
55  {
57  if (clientGetConnection.server != 0) break;
58 
59  nopdelay();
60  }
61 
62  mtapInited = 1;
63 
64  return 1;
65 }
66 
68 {
69  if(!mtapInited) return -1;
70 
71  mtapRpcBuffer[0] = port;
73 
74  return mtapRpcBuffer[1];
75 }
76 
78 {
79  if(!mtapInited) return -1;
80 
81  mtapRpcBuffer[0] = port;
83 
84  return mtapRpcBuffer[1];
85 }
86 
88 {
89  if(!mtapInited) return -1;
90 
91  mtapRpcBuffer[0] = port;
93 
94  return mtapRpcBuffer[1];
95 }
static void nopdelay(void)
Definition: kernel.h:141
#define MTAPSERV_GET_CONNECTION
Definition: libmtap.c:26
static int mtapInited
Definition: libmtap.c:32
static struct t_SifRpcClientData clientGetConnection
Definition: libmtap.c:31
static struct t_SifRpcClientData clientPortClose
Definition: libmtap.c:30
int mtapInit(void)
Definition: libmtap.c:34
static unsigned int mtapRpcBuffer[32]
Definition: libmtap.c:28
int mtapGetConnection(int port)
Definition: libmtap.c:87
#define MTAPSERV_PORT_CLOSE
Definition: libmtap.c:25
static struct t_SifRpcClientData clientPortOpen
Definition: libmtap.c:29
int mtapPortClose(int port)
Definition: libmtap.c:77
int mtapPortOpen(int port)
Definition: libmtap.c:67
#define MTAPSERV_PORT_OPEN
Definition: libmtap.c:24
s32 port
Definition: libpad.c:176
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)
#define NULL
Definition: tamtypes.h:91