-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathlibmtap.c
More file actions
102 lines (79 loc) · 2.36 KB
/
libmtap.c
File metadata and controls
102 lines (79 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
# _____ ___ ____ ___ ____
# ____| | ____| | | |____|
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
#-----------------------------------------------------------------------
# Copyright 2001-2004, ps2dev - http://www.ps2dev.org
# Licenced under Academic Free License version 2.0
# Review ps2sdk README & LICENSE files for further details.
*/
/**
* @file
* Functions to provide access to multi-taps.
*/
#include <tamtypes.h>
#include <string.h>
#include <kernel.h>
#include <loadfile.h>
#include <sifrpc.h>
#include <stdarg.h>
#include "libmtap.h"
#define MTAPSERV_PORT_OPEN 0x80000901
#define MTAPSERV_PORT_CLOSE 0x80000902
#define MTAPSERV_GET_CONNECTION 0x80000903
static unsigned int mtapRpcBuffer[32] __attribute__((aligned (64)));
static struct t_SifRpcClientData clientPortOpen __attribute__((aligned (64)));
static struct t_SifRpcClientData clientPortClose __attribute__((aligned (64)));
static struct t_SifRpcClientData clientGetConnection __attribute__((aligned (64)));
static int mtapInited = 0;
int mtapInit(void)
{
int bind_retry = 100;
if(mtapInited) return -1;
while(1)
{
if (SifBindRpc(&clientPortOpen, MTAPSERV_PORT_OPEN, 0) < 0) return -1;
if (clientPortOpen.server != 0) break;
if (--bind_retry < 1) return -SCE_EBINDMISS;
nopdelay();
}
bind_retry = 100;
while(1)
{
if (SifBindRpc(&clientPortClose, MTAPSERV_PORT_CLOSE, 0) < 0) return -1;
if (clientPortClose.server != 0) break;
if (--bind_retry < 1) return -SCE_EBINDMISS;
nopdelay();
}
bind_retry = 100;
while(1)
{
if (SifBindRpc(&clientGetConnection, MTAPSERV_GET_CONNECTION, 0) < 0) return -1;
if (clientGetConnection.server != 0) break;
if (--bind_retry < 1) return -SCE_EBINDMISS;
nopdelay();
}
mtapInited = 1;
return 1;
}
int mtapPortOpen(int port)
{
if(!mtapInited) return -1;
mtapRpcBuffer[0] = port;
SifCallRpc(&clientPortOpen, 1, 0, mtapRpcBuffer, 4, mtapRpcBuffer, 8, NULL, NULL);
return mtapRpcBuffer[1];
}
int mtapPortClose(int port)
{
if(!mtapInited) return -1;
mtapRpcBuffer[0] = port;
SifCallRpc(&clientPortClose, 1, 0, mtapRpcBuffer, 4, mtapRpcBuffer, 8, NULL, NULL);
return mtapRpcBuffer[1];
}
int mtapGetConnection(int port)
{
if(!mtapInited) return -1;
mtapRpcBuffer[0] = port;
SifCallRpc(&clientGetConnection, 1, 0, mtapRpcBuffer, 4, mtapRpcBuffer, 8, NULL, NULL);
return mtapRpcBuffer[1];
}