-
Notifications
You must be signed in to change notification settings - Fork 16
/
input.c
70 lines (63 loc) · 1.23 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
/*
* Copyright (C) 2017 - 2018 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 <inttypes.h>
#include <string.h>
#include "input.h"
//used externally by main.c
uint8_t inValReads[8];
uint8_t inPollMode = 0;
uint8_t inPos = 0;
#define DEBUG_INPUT 0
void inputInit()
{
memset(inValReads, 0, 8);
}
void inputSet(uint16_t addr, uint8_t in)
{
(void)addr;
inPollMode = in;
#if DEBUG_INPUT
printf("Set %02x\n",in);
#endif
if(!(in&1))
inPos = 0;
}
extern uint8_t memLastVal;
uint8_t inputGetP1(uint16_t addr)
{
(void)addr;
uint8_t ret = 1;
if(inPollMode&1)
ret = inValReads[BUTTON_A];
else if(inPos < 8)
{
if((inPos == BUTTON_DOWN && inValReads[BUTTON_UP]) || (inPos == BUTTON_RIGHT && inValReads[BUTTON_LEFT]))
ret = 0; //dont allow up+down/left+right
else
ret = inValReads[inPos];
#if DEBUG_INPUT
printf("%d:%d\n",ret,inPos);
#endif
inPos++;
}
else
{
#if DEBUG_INPUT
printf("keeps reading\n");
#endif
}
return (memLastVal&(~0x1F))|(ret&1);
}
extern uint8_t memLastVal;
uint8_t inputGetP2(uint16_t addr)
{
(void)addr;
//no player 2 set up yet
return (memLastVal&(~0x1F));
}