PS2SDK
PS2 Homebrew Libraries
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 (sceSifBindRpc(&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 (sceSifBindRpc(&clientPortClose, MTAPSERV_PORT_CLOSE, 0) < 0) return -1;
49  if (clientPortClose.server != 0) break;
50 
51  nopdelay();
52  }
53 
54  while(1)
55  {
56  if (sceSifBindRpc(&clientGetConnection, MTAPSERV_GET_CONNECTION, 0) < 0) return -1;
57  if (clientGetConnection.server != 0) break;
58 
59  nopdelay();
60  }
61 
62  mtapInited = 1;
63 
64  return 1;
65 }
66 
67 int mtapPortOpen(int port)
68 {
69  if(!mtapInited) return -1;
70 
71  mtapRpcBuffer[0] = port;
72  sceSifCallRpc(&clientPortOpen, 1, 0, mtapRpcBuffer, 4, mtapRpcBuffer, 8, NULL, NULL);
73 
74  return mtapRpcBuffer[1];
75 }
76 
77 int mtapPortClose(int port)
78 {
79  if(!mtapInited) return -1;
80 
81  mtapRpcBuffer[0] = port;
82  sceSifCallRpc(&clientPortClose, 1, 0, mtapRpcBuffer, 4, mtapRpcBuffer, 8, NULL, NULL);
83 
84  return mtapRpcBuffer[1];
85 }
86 
87 int mtapGetConnection(int port)
88 {
89  if(!mtapInited) return -1;
90 
91  mtapRpcBuffer[0] = port;
92  sceSifCallRpc(&clientGetConnection, 1, 0, mtapRpcBuffer, 4, mtapRpcBuffer, 8, NULL, NULL);
93 
94  return mtapRpcBuffer[1];
95 }
mtapPortClose
int mtapPortClose(int port)
Definition: libmtap.c:77
kernel.h
mtapInit
int mtapInit(void)
Definition: libmtap.c:34
mtapGetConnection
int mtapGetConnection(int port)
Definition: libmtap.c:87
tamtypes.h
mtapPortOpen
int mtapPortOpen(int port)
Definition: libmtap.c:67
t_SifRpcClientData
Definition: sifrpc-common.h:134
__attribute__
Definition: gif_registers.h:38
libmtap.h