controller.c
1.31 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
#include <ultra64.h>
/* #include <rom.h> */
#include <ramrom.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <controller.h>
#include "gng.h"
OSContStatus statusdata[MAXCONTROLLERS];
OSContPad controllerdata[MAXCONTROLLERS];
/*
*
* Return the lowest number controller connected to system
*/
int initControllers()
{
int i;
u8 pattern;
if (osContInit(&siMessageQ, &pattern, &statusdata[0]) == -1) {
#ifndef _FINALROM
PRINTF("initControllers(): osContInit() returns in error.\n");
#endif
return -1;
}
for (i = 0; i < MAXCONTROLLERS; i++) {
if ((pattern & (1<<i)) &&
!(statusdata[i].errno & CONT_NO_RESPONSE_ERROR))
return i;
}
return -1;
}
int
readControllerButton(int controllerSlot)
{
u16 button;
s32 retval;
if (controllerSlot < 0) {
#ifndef _FINALROM
PRINTF("no controller connection\n");
#endif
return 0;
}
retval = osContStartReadData(&siMessageQ);
if (retval != 0) {
#ifndef _FINALROM
PRINTF("readControllerButton(): osContStartReadData returns 0x%x\n", retval);
#endif
return(0);
}
(void)osRecvMesg(&siMessageQ, NULL, OS_MESG_BLOCK);
osContGetReadData(controllerdata);
button = controllerdata[controllerSlot].button;
return button;
}