cont.c
2.18 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
/*---------------------------------------------------------------------*
Copyright (C) 1998 Nintendo.
$RCSfile: cont.c,v $
$Revision: 1.1.1.1 $
$Date: 2002/05/02 03:27:30 $
*---------------------------------------------------------------------*/
/*====================================================================
File : cont.c Ver 1.0
Created by Koji Mitsunari. Jun,19 1997.
Copyright by Nintendo, Co., Ltd. 1997.
====================================================================*/
#include <ultra64.h>
#include "cont.h"
OSContPad contdata[MAXCONTROLLERS];
OSContStatus contstat[MAXCONTROLLERS];
Conts conts[MAXCONTROLLERS];
/*---------------------------------------------------------------------
Initialize Controller
---------------------------------------------------------------------*/
void initcont(OSMesgQueue *siMesgQ)
{
int i;
u8 pattern;
osContInit(siMesgQ, &pattern, contstat);
for (i = 0 ; i < MAXCONTROLLERS ; i ++) {
conts[i].stat = contstat[i].status;
conts[i].nowcon = 0;
if ( ((pattern >> i) & 1) != 0 &&
((contstat[i].type & CONT_TYPE_MASK) == CONT_TYPE_NORMAL)) {
conts[i].flag = 1;
} else {
conts[i].flag = 0;
}
}
}
/*---------------------------------------------------------------------
Read Controller
---------------------------------------------------------------------*/
void readcont(void)
{
int i;
osContGetReadData(contdata);
for(i = 0 ; i < MAXCONTROLLERS ; i ++){
if (!(contdata[i].errno & CONT_NO_RESPONSE_ERROR)) {
conts[i].flag = 1;
conts[i].oldcon = conts[i].nowcon;
conts[i].nowcon = (int)contdata[i].button;
conts[i].nowtrg = conts[i].nowcon & ~conts[i].oldcon;
conts[i].sx = contdata[i].stick_x;
conts[i].sy = contdata[i].stick_y;
conts[i].repeat = conts[i].nowcon & conts[i].oldcon;
if (conts[i].repeat) {
conts[i].repcnt ++;
if (conts[i].repcnt < 12) {
conts[i].repeat = 0;
} else if (conts[i].repcnt < 32) {
if (conts[i].repcnt & 3) {
conts[i].repeat = 0;
}
}
} else {
conts[i].repcnt = 0;
}
} else {
conts[i].flag = 0;
}
}
}