-
Notifications
You must be signed in to change notification settings - Fork 7
/
input.c
73 lines (65 loc) · 1.36 KB
/
input.c
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) 2017 FIX94
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <inttypes.h>
#include <string.h>
#include "input.h"
//used externally by main.c
uint8_t inValReads[8];
uint8_t modeSelect = 3;
#define DEBUG_INPUT 0
void inputInit()
{
modeSelect = 3;
}
void inputClear()
{
memset(inValReads, 0, 8);
}
void inputSet8(uint16_t addr, uint8_t in)
{
(void)addr;
modeSelect = ((in)>>4)&0x3;
#if DEBUG_INPUT
printf("Input: Set %02x->%02x\n",in,modeSelect);
#endif
}
uint8_t inputGet8(uint16_t addr)
{
(void)addr;
uint8_t outVal = 0;
if(modeSelect == 1)
{
if(inValReads[BUTTON_A])
outVal |= 1;
if(inValReads[BUTTON_B])
outVal |= 2;
if(inValReads[BUTTON_SELECT])
outVal |= 4;
if(inValReads[BUTTON_START])
outVal |= 8;
}
else if(modeSelect == 2)
{
if(inValReads[BUTTON_RIGHT])
outVal |= 1;
if(inValReads[BUTTON_LEFT])
outVal |= 2;
if(inValReads[BUTTON_UP])
outVal |= 4;
if(inValReads[BUTTON_DOWN])
outVal |= 8;
}
return (~(outVal|(modeSelect<<4)));
}
bool inputAny()
{
return !!(inValReads[BUTTON_A]|inValReads[BUTTON_B]|inValReads[BUTTON_SELECT]|inValReads[BUTTON_START]
|inValReads[BUTTON_RIGHT]|inValReads[BUTTON_LEFT]|inValReads[BUTTON_UP]|inValReads[BUTTON_DOWN]);
}