summaryrefslogtreecommitdiff
path: root/src/boot/libu64/pad.c
blob: 9b822122cb6d04b2e655059c106539c25acf3d98 (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
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
#include "libu64/pad.h"

void pad_init(Input* input) {
    bzero(input, sizeof(Input));
}

void pad_cleanup(void) {
}

void pad_flush(Input* input) {
    input->press.button = 0;
    input->rel.button = 0;
}

s32 pad_push_only(Input* input, u16 value) {
    return value == input->cur.button;
}

s32 pad_push_also(Input* input, u16 key) {
    return key == (input->cur.button & key);
}

s32 pad_on_trigger(Input* input, u16 key) {
    return key == (input->press.button & key);
}

s32 pad_off_trigger(Input* input, u16 key) {
    return key == (input->rel.button & key);
}

u16 pad_button(Input* input) {
    return input->cur.button;
}

u16 pad_trigger(Input* input) {
    return input->press.button;
}

s8 pad_physical_stick_x(Input* input) {
    return input->cur.stick_x;
}

s8 pad_physical_stick_y(Input* input) {
    return input->cur.stick_y;
}

void pad_set_logical_stick(Input* input, s32 x, s32 y) {
    input->rel.stick_x = x;
    input->rel.stick_y = y;
}

s8 pad_logical_stick_x(Input* input) {
    return input->rel.stick_x;
}

s8 pad_logical_stick_y(Input* input) {
    return input->rel.stick_y;
}

s8 pad_stick_x(Input* input) {
    return pad_logical_stick_x(input);
}

s8 pad_stick_y(Input* input) {
    return pad_logical_stick_y(input);
}

void pad_correct_stick(Input* input) {
    s32 curX = pad_physical_stick_x(input);
    s32 curY = pad_physical_stick_y(input);
    s32 relX;
    s32 relY;

    if (curX > 7) {
        relX = (curX < 0x43) ? curX - 7 : 0x43 - 7;
    } else if (curX < -7) {
        relX = (curX > -0x43) ? curX + 7 : -0x43 + 7;
    } else {
        relX = 0;
    }

    if (curY > 7) {
        relY = (curY < 0x43) ? curY - 7 : 0x43 - 7;

    } else if (curY < -7) {
        relY = (curY > -0x43) ? curY + 7 : -0x43 + 7;
    } else {
        relY = 0;
    }

    pad_set_logical_stick(input, relX, relY);
}