voicegetreaddata.c
3.08 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*---------------------------------------------------------------------
Copyright (C) 1997,1998 Nintendo.
File voicegetreaddata.c
Coded by Koji Mitsunari. Oct 8, 1997.
Modified by Koji Mitsunari. Jun 22, 1998.
Comments Voice Recognition System
$Id: voicegetreaddata.c,v 1.2 2003/03/25 20:42:04 blythe Exp $
---------------------------------------------------------------------*/
#include "osint.h"
#include "controller.h"
#include "siint.h"
s32
osVoiceGetReadData(OSVoiceHandle *hd, OSVoiceData *micdata) {
#ifdef BBPLAYER
return CONT_ERR_DEVICE;
#else
s32 ret = 0, i;
u8 stat;
u8 temp[36];
static u8 c;
switch ( hd->__mode ) {
case 1:
if ((ret = __osVoiceGetStatus(hd->__mq, hd->__channel, &stat)) != 0 ) {
return(ret);
} else if (stat & VOICE_READ_READY) {
return(CONT_ERR_NOT_READY);
}
if ((ret = __osVoiceContRead2(hd->__mq, hd->__channel,
VOICE_RW_ADDR, temp)) != 0){
return(ret);
}
c = (temp[0] & 0x07);
hd->cmd_status = c;
if ( c != 0 && c != 7 ) { /* finished execution ? */
return(CONT_ERR_NOT_READY);
}
case 2: /* getting data */
hd->__mode = 2;
if ((ret = __osVoiceGetStatus(hd->__mq, hd->__channel, &stat)) != 0) {
return(ret);
}
if (stat & VOICE_WRITE_READY) {
return(CONT_ERR_VOICE_NO_RESPONSE);
}
((u32 *)temp)[0]=0x600;
ret = __osVoiceContWrite4(hd->__mq, hd->__channel, VOICE_RW_ADDR, temp);
if (ret != 0 ) {
return(ret);
}
case 3:
hd->__mode = 3;
if ((ret = __osVoiceGetStatus(hd->__mq, hd->__channel, &stat)) != 0 ) {
return(ret);
} else if (stat & VOICE_READ_READY) {
return(CONT_ERR_VOICE_NO_RESPONSE);
}
ret = __osVoiceContRead36(hd->__mq, hd->__channel, VOICE_RW_ADDR, temp);
if (ret != 0 ) {
return(ret);
}
micdata->warning = temp[4] + (temp[5]<<8);
#if 1
micdata->answer_num = temp[6];
#else
if (temp[6] == 0 ) {
micdata->answer_num = 5;
} else {
micdata->answer_num = temp[6];
}
#endif
micdata->voice_level = temp[8] + (temp[9]<<8);
micdata->voice_sn = temp[10] + (temp[11]<<8);
micdata->voice_time = temp[12] + (temp[13]<<8);
for ( i = 0 ; i < 5 ; i++ ) {
micdata->answer[i] = temp[14+(i<<2)] + (temp[15+(i<<2)]<<8);
micdata->distance[i] = temp[16+(i<<2)] + (temp[17+(i<<2)]<<8);
}
if (micdata->answer[0] == 0x7fff) {
micdata->answer_num = 0;
}
hd->cmd_status = (temp[34] & 7);
if (c == 0 || hd->cmd_status == 0) {
break;
}
case 4:
hd->__mode = 4;
if ((ret = __osVoiceGetStatus(hd->__mq, hd->__channel, &stat)) != 0 ) {
return(ret);
}
if (stat & VOICE_READ_READY) {
return(CONT_ERR_VOICE_NO_RESPONSE);
}
if ((ret = __osVoiceContRead2(hd->__mq, hd->__channel,
VOICE_RW_ADDR, temp)) != 0){
return(ret);
}
hd->cmd_status = (temp[0] & 7);
if ( (temp[0] & 0x07) != 0 ) { /* finished execution */
return(CONT_ERR_VOICE_NO_RESPONSE);
}
break;
default:
return(CONT_ERR_INVALID);
}
hd->__mode = 0;
return(ret);
#endif
}