ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
mtap_sample.c File Reference
#include <tamtypes.h>
#include <kernel.h>
#include <sifrpc.h>
#include <loadfile.h>
#include <stdio.h>
#include <string.h>
#include "gs_privileged.h"
#include "libpad.h"
#include "libmtap.h"
+ Include dependency graph for mtap_sample.c:

Go to the source code of this file.

Functions

int wait_vsync (void)
 
void loadmodules (int free)
 
void find_controllers ()
 
int main (int argc, char **argv)
 

Variables

static char * padBuf [2][4]
 
static u32 padConnected [2][4]
 
static u32 padOpen [2][4]
 
static u32 mtapConnected [2]
 
static u32 maxslot [2]
 

Function Documentation

◆ find_controllers()

void find_controllers ( )

Definition at line 105 of file mtap_sample.c.

106 {
107  u32 port, slot;
108  u32 mtapcon;
109 
110  // Look for multitaps and controllers on both ports
111  for(port = 0; port < 2; port++)
112  {
113  //if(mtapConnected[port] == 0) mtapPortOpen(port);
114 
115  mtapcon = mtapGetConnection(port);
116 
117  // if(mtapcon == 0) mtapPortClose(port);
118 
119  if((mtapcon == 1) && (mtapConnected[port] == 0))
120  {
121  printf("Multitap (%i) connected\n", (int)port);
122  }
123 
124  if((mtapcon == 0) && (mtapConnected[port] == 1))
125  {
126  printf("Multitap (%i) disconnected(int argc, char **argv)\n", (int)port);
127  }
128 
129  mtapConnected[port] = mtapcon;
130 
131  // Check for multitap
132  if(mtapConnected[port] == 1)
133  maxslot[port] = 4;
134  else
135  maxslot[port] = 1;
136 
137  // Find any connected controllers
138  for(slot=0; slot < maxslot[port]; slot++)
139  {
140  if(padOpen[port][slot] == 0)
141  {
143  //if(padOpen[port][slot])
144  // printf("padOpen(%i, %i) = %i\n", port, slot, padOpen[port][slot] );
145  }
146 
147  if(padOpen[port][slot] == 1)
148  {
149 
151  {
152  if(padConnected[port][slot] == 0)
153  {
154  printf("Controller (%i,%i) connected\n", (int)port, (int)slot);
155  }
156 
157  padConnected[port][slot] = 1;
158  }
159  else
160  {
162  {
163  printf("Controller (%i,%i) disconnected\n", (int)port, (int)slot);
164  padConnected[port][slot] = 0;
165  }
166  }
167 
168  }
169  }
170 
171  // Close controllers when multitap is disconnected
172 
173  if(mtapConnected[port] == 0)
174  {
175  for(slot=1; slot < 4; slot++)
176  {
177  if(padOpen[port][slot] == 1)
178  {
180  padOpen[port][slot] = 0;
181  }
182  }
183  }
184  }
185 
186 
187 }
int mtapGetConnection(int port)
Definition: libmtap.c:87
s32 slot
Definition: libpad.c:176
s32 port
Definition: libpad.c:176
int padPortOpen(int port, int slot, void *padArea)
Definition: libpad.c:392
#define PAD_STATE_STABLE
Definition: libpad.h:47
int padPortClose(int port, int slot)
Definition: libpad.c:449
int padGetState(int port, int slot)
Definition: libpad.c:482
#define PAD_STATE_DISCONN
Definition: libpad.h:43
static char * padBuf[2][4]
Definition: mtap_sample.c:24
static u32 mtapConnected[2]
Definition: mtap_sample.c:27
static u32 maxslot[2]
Definition: mtap_sample.c:28
static u32 padConnected[2][4]
Definition: mtap_sample.c:25
static u32 padOpen[2][4]
Definition: mtap_sample.c:26
unsigned int u32
Definition: tamtypes.h:30

References maxslot, mtapConnected, mtapGetConnection(), PAD_STATE_DISCONN, PAD_STATE_STABLE, padBuf, padConnected, padGetState(), padOpen, padPortClose(), padPortOpen(), port, and slot.

Referenced by main().

◆ loadmodules()

void loadmodules ( int  free)

Definition at line 48 of file mtap_sample.c.

49 {
50  int ret;
51 
52  if(free == 1)
53  {
54  ret = SifLoadModule("host0:sio2man.irx", 0, NULL);
55 
56  if (ret < 0) {
57  printf("SifLoadModule sio2man.irx failed: %d\n", ret);
58  SleepThread();
59  }
60 
61  ret = SifLoadModule("host0:mtapman.irx", 0, NULL);
62 
63  if (ret < 0) {
64  printf("SifLoadModule mtapman.irx failed: %d\n", ret);
65  SleepThread();
66  }
67 
68  ret = SifLoadModule("host0:padman.irx", 0, NULL);
69 
70  if (ret < 0) {
71  printf("SifLoadModule padman.irx failed: %d\n", ret);
72  SleepThread();
73  }
74 
75  }
76  else
77  {
78 
79  ret = SifLoadModule("rom0:XSIO2MAN", 0, NULL);
80 
81  if (ret < 0) {
82  printf("SifLoadModule XSIO2MAN failed: %d\n", ret);
83  SleepThread();
84  }
85 
86  ret = SifLoadModule("rom0:XMTAPMAN", 0, NULL);
87 
88  if (ret < 0) {
89  printf("SifLoadModule XMTAPMAN failed: %d\n", ret);
90  SleepThread();
91  }
92 
93  ret = SifLoadModule("rom0:XPADMAN", 0, NULL);
94 
95  if (ret < 0) {
96  printf("SifLoadModule XPADMAN failed: %d\n", ret);
97  SleepThread();
98  }
99 
100  }
101 
102 
103 }
int SifLoadModule(const char *path, int arg_len, const char *args)
s32 SleepThread(void)
#define NULL
Definition: tamtypes.h:91

References NULL, SifLoadModule(), and SleepThread().

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 193 of file mtap_sample.c.

194 {
195  u32 i;
196 
197  struct padButtonStatus buttons;
198  u32 paddata;
199  u32 old_pad[2][4];
200  u32 new_pad[2][4];
201  s32 ret;
202 
203  SifInitRpc(0);
204 
205  printf("libmtap sample");
206 
207  if((argc == 2) && (strncmp(argv[1], "free", 4) == 0))
208  {
209  printf(" - Using PS2SDK sio2man.irx, mtapman.irx and padman.irx modules.\n");
210  loadmodules(1);
211  }
212  else
213  {
214  printf(" - Using ROM XSIO2MAN, XMTAP and XPADMAN modules.\n");
215  printf("Start this sample with 'free' as an argument to load sio2man.irx, mtapman.irx and padman.irx\n");
216  printf("Example: ps2client execee host:mtap_sample.elf free\n");
217  loadmodules(0);
218  }
219 
220 
221 
222 
223  mtapInit();
224  padInit(0);
225 
226  mtapConnected[0] = 0;
227  mtapConnected[1] = 0;
228 
229  mtapPortOpen(0);
230  mtapPortOpen(1);
231 
232  for(i = 0; i < 4; i++)
233  {
234  padConnected[0][i] = 0;
235  padConnected[1][i] = 0;
236  padOpen[0][i] = 0;
237  padOpen[1][i] = 0;
238  old_pad[0][i] = 0;
239  old_pad[1][i] = 0;
240  new_pad[0][i] = 0;
241  new_pad[1][i] = 0;
242 
243  padBuf[0][i] = memalign(64, 256);
244  padBuf[1][i] = memalign(64, 256);
245  }
246 
247  while(1)
248  {
249  u32 port, slot;
250 
252 
253  for(port = 0; port < 2 ; port++)
254  {
255  for(slot=0; slot < maxslot[port]; slot++)
256  {
258  {
259  ret = padRead(port, slot, &buttons);
260 
261  if (ret != 0)
262  {
263  paddata = 0xffff ^ buttons.btns;
264 
266  old_pad[port][slot] = paddata;
267 
268  if(new_pad[port][slot]) printf("Controller (%i,%i) button(s) pressed: ", (int)port, (int)slot);
269 
270  if(new_pad[port][slot] & PAD_LEFT) printf("LEFT ");
271  if(new_pad[port][slot] & PAD_RIGHT) printf("RIGHT ");
272  if(new_pad[port][slot] & PAD_UP) printf("UP ");
273  if(new_pad[port][slot] & PAD_DOWN) printf("DOWN ");
274  if(new_pad[port][slot] & PAD_START) printf("START ");
275  if(new_pad[port][slot] & PAD_SELECT) printf("SELECT ");
276  if(new_pad[port][slot] & PAD_SQUARE) printf("SQUARE ");
277  if(new_pad[port][slot] & PAD_TRIANGLE) printf("TRIANGLE ");
278  if(new_pad[port][slot] & PAD_CIRCLE) printf("CIRCLE ");
279  if(new_pad[port][slot] & PAD_CROSS) printf("CROSS ");
280  if(new_pad[port][slot] & PAD_L1) printf("L1 ");
281  if(new_pad[port][slot] & PAD_L2) printf("L2 ");
282  if(new_pad[port][slot] & PAD_L3) printf("L3 ");
283  if(new_pad[port][slot] & PAD_R1) printf("R1 ");
284  if(new_pad[port][slot] & PAD_R2) printf("R2 ");
285  if(new_pad[port][slot] & PAD_R3) printf("R3 ");
286 
287  if(new_pad[port][slot]) printf("\n");
288 
289 
290  }
291  }
292  }
293  }
294 
295  wait_vsync();
296  }
297  return 0;
298 }
#define PAD_CROSS
Definition: input.h:26
#define PAD_SELECT
Definition: input.h:24
#define PAD_START
Definition: input.h:21
#define PAD_R3
Definition: input.h:22
#define PAD_CIRCLE
Definition: input.h:27
#define PAD_DOWN
Definition: input.h:18
#define PAD_RIGHT
Definition: input.h:19
#define PAD_SQUARE
Definition: input.h:25
#define PAD_TRIANGLE
Definition: input.h:28
#define PAD_L2
Definition: input.h:32
#define PAD_L3
Definition: input.h:23
#define PAD_UP
Definition: input.h:20
#define PAD_L1
Definition: input.h:30
#define PAD_LEFT
Definition: input.h:17
#define PAD_R2
Definition: input.h:31
#define PAD_R1
Definition: input.h:29
int mtapInit(void)
Definition: libmtap.c:34
int mtapPortOpen(int port)
Definition: libmtap.c:67
unsigned char padRead(int port, int slot, struct padButtonStatus *data)
Definition: libpad.c:470
int padInit(int mode)
Definition: libpad.c:297
void loadmodules(int free)
Definition: mtap_sample.c:48
void find_controllers()
Definition: mtap_sample.c:105
int wait_vsync(void)
Definition: mtap_sample.c:31
static u32 new_pad[2]
Definition: padx.c:20
static u32 old_pad[2]
Definition: padx.c:19
static u32 paddata[2]
Definition: padx.c:18
void SifInitRpc(int mode)
signed int s32
Definition: tamtypes.h:58

References padButtonStatus::btns, find_controllers(), loadmodules(), maxslot, mtapConnected, mtapInit(), mtapPortOpen(), new_pad, old_pad, PAD_CIRCLE, PAD_CROSS, PAD_DOWN, PAD_L1, PAD_L2, PAD_L3, PAD_LEFT, PAD_R1, PAD_R2, PAD_R3, PAD_RIGHT, PAD_SELECT, PAD_SQUARE, PAD_START, PAD_TRIANGLE, PAD_UP, padBuf, padConnected, paddata, padInit(), padOpen, padRead(), port, SifInitRpc(), slot, and wait_vsync().

◆ wait_vsync()

int wait_vsync ( void  )

Definition at line 31 of file mtap_sample.c.

32  {
33 
34  // Enable the vsync interrupt.
35  *GS_REG_CSR |= GS_SET_CSR(0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0);
36 
37  // Wait for the vsync interrupt.
38  while (!(*GS_REG_CSR & (GS_SET_CSR(0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0)))) { }
39 
40  // Disable the vsync interrupt.
41  *GS_REG_CSR &= ~GS_SET_CSR(0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0);
42 
43  // End function.
44  return 0;
45 
46  }
#define GS_REG_CSR
Definition: gs_privileged.h:45
#define GS_SET_CSR(signal_evnt, finish_evnt, hsync_intrupt, vsync_intrupt, write_terminate, flush, reset, nfield, current_field, fifo_status, gs_rev_number, gs_id)
Definition: libgs.h:1249

References GS_REG_CSR, and GS_SET_CSR.

Referenced by main().

Variable Documentation

◆ maxslot

u32 maxslot[2]
static

Definition at line 28 of file mtap_sample.c.

Referenced by find_controllers(), and main().

◆ mtapConnected

u32 mtapConnected[2]
static

Definition at line 27 of file mtap_sample.c.

Referenced by find_controllers(), and main().

◆ padBuf

char* padBuf[2][4]
static

Definition at line 24 of file mtap_sample.c.

Referenced by find_controllers(), and main().

◆ padConnected

u32 padConnected[2][4]
static

Definition at line 25 of file mtap_sample.c.

Referenced by find_controllers(), and main().

◆ padOpen

u32 padOpen[2][4]
static

Definition at line 26 of file mtap_sample.c.

Referenced by find_controllers(), and main().