PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
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
28static unsigned int mtapRpcBuffer[32] __attribute__((aligned (64)));
29static struct t_SifRpcClientData clientPortOpen __attribute__((aligned (64)));
30static struct t_SifRpcClientData clientPortClose __attribute__((aligned (64)));
31static struct t_SifRpcClientData clientGetConnection __attribute__((aligned (64)));
32static int mtapInited = 0;
33
34int 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 {
56 if (SifBindRpc(&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
67int mtapPortOpen(int port)
68{
69 if(!mtapInited) return -1;
70
71 mtapRpcBuffer[0] = port;
72 SifCallRpc(&clientPortOpen, 1, 0, mtapRpcBuffer, 4, mtapRpcBuffer, 8, NULL, NULL);
73
74 return mtapRpcBuffer[1];
75}
76
77int mtapPortClose(int port)
78{
79 if(!mtapInited) return -1;
80
81 mtapRpcBuffer[0] = port;
82 SifCallRpc(&clientPortClose, 1, 0, mtapRpcBuffer, 4, mtapRpcBuffer, 8, NULL, NULL);
83
84 return mtapRpcBuffer[1];
85}
86
87int mtapGetConnection(int port)
88{
89 if(!mtapInited) return -1;
90
91 mtapRpcBuffer[0] = port;
92 SifCallRpc(&clientGetConnection, 1, 0, mtapRpcBuffer, 4, mtapRpcBuffer, 8, NULL, NULL);
93
94 return mtapRpcBuffer[1];
95}
int mtapInit(void)
Definition libmtap.c:34
int mtapGetConnection(int port)
Definition libmtap.c:87
int mtapPortClose(int port)
Definition libmtap.c:77
int mtapPortOpen(int port)
Definition libmtap.c:67