summaryrefslogtreecommitdiff
path: root/src/libultra/voice/voicestopreaddata.c
blob: 31d4d6dd5d3af63704e8a631036524f63f3c8350 (plain)
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
/**
 * File: voicestopreaddata.c
 *
 * Forcibly stops voice recognition processing by the Voice Recognition System
 */

#include "PR/controller_voice.h"
#include "PR/os_voice.h"
#include "PR/controller.h"

s32 osVoiceStopReadData(OSVoiceHandle* hd) {
    s32 errorCode;
    s32 i;
    u8 status;
    u8 data[4];

    errorCode = __osVoiceGetStatus(hd->__mq, hd->__channel, &status);
    if (errorCode != 0) {
        return errorCode;
    }

    if (status & 2) {
        return CONT_ERR_VOICE_NO_RESPONSE;
    }

    if (hd->__mode == VOICE_HANDLE_MODE_0) {
        return CONT_ERR_INVALID;
    }

    /**
     * data[0] = 0
     * data[1] = 0
     * data[2] = 7
     * data[3] = 0
     */
    *(u32*)data = 0x700;
    errorCode = __osVoiceContWrite4(hd->__mq, hd->__channel, 0, data);

    if (errorCode == 0) {
        i = 0;
        do {
            errorCode = __osVoiceCheckResult(hd, &status);
            if (errorCode & 0xFF00) {
                if (((errorCode & 7) == 0) || ((errorCode & 7) == 7)) {
                    errorCode = 0;
                    hd->__mode = VOICE_HANDLE_MODE_0;
                } else {
                    errorCode = CONT_ERR_INVALID;
                }
            } else {
                hd->__mode = VOICE_HANDLE_MODE_0;
            }
            i++;
        } while ((errorCode == CONT_ERR_VOICE_NO_RESPONSE) && (i < 20));
    }

    if (i >= 20) {}

    return errorCode;
}