2017-05-12 03:22:59 +00:00
|
|
|
/*
|
|
|
|
* 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>
|
2017-05-27 14:04:25 +00:00
|
|
|
#include <string.h>
|
2017-05-12 03:22:59 +00:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include "input.h"
|
|
|
|
|
|
|
|
//used externally by main.c
|
|
|
|
uint8_t inValReads[8];
|
2017-05-29 03:19:19 +00:00
|
|
|
uint8_t modeSelect = 3;
|
2017-05-12 03:22:59 +00:00
|
|
|
|
|
|
|
#define DEBUG_INPUT 0
|
|
|
|
|
|
|
|
void inputInit()
|
|
|
|
{
|
|
|
|
memset(inValReads, 0, 8);
|
2017-05-29 03:19:19 +00:00
|
|
|
modeSelect = 3;
|
2017-05-12 03:22:59 +00:00
|
|
|
}
|
|
|
|
|
2017-05-27 01:11:58 +00:00
|
|
|
void inputSet8(uint16_t addr, uint8_t in)
|
2017-05-12 03:22:59 +00:00
|
|
|
{
|
2017-05-27 01:11:58 +00:00
|
|
|
(void)addr;
|
2017-05-29 03:19:19 +00:00
|
|
|
modeSelect = ((in)>>4)&0x3;
|
2017-05-12 03:22:59 +00:00
|
|
|
#if DEBUG_INPUT
|
2017-06-07 20:25:30 +00:00
|
|
|
printf("Input: Set %02x->%02x\n",in,modeSelect);
|
2017-05-12 03:22:59 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-05-27 01:11:58 +00:00
|
|
|
uint8_t inputGet8(uint16_t addr)
|
2017-05-12 03:22:59 +00:00
|
|
|
{
|
2017-05-27 01:11:58 +00:00
|
|
|
(void)addr;
|
2017-05-12 03:22:59 +00:00
|
|
|
uint8_t outVal = 0;
|
2017-05-29 03:19:19 +00:00
|
|
|
if(modeSelect == 1)
|
2017-05-12 03:22:59 +00:00
|
|
|
{
|
|
|
|
if(inValReads[BUTTON_A])
|
|
|
|
outVal |= 1;
|
|
|
|
if(inValReads[BUTTON_B])
|
|
|
|
outVal |= 2;
|
|
|
|
if(inValReads[BUTTON_SELECT])
|
|
|
|
outVal |= 4;
|
|
|
|
if(inValReads[BUTTON_START])
|
|
|
|
outVal |= 8;
|
|
|
|
}
|
2017-05-29 03:19:19 +00:00
|
|
|
else if(modeSelect == 2)
|
2017-05-12 03:22:59 +00:00
|
|
|
{
|
|
|
|
if(inValReads[BUTTON_RIGHT])
|
|
|
|
outVal |= 1;
|
|
|
|
if(inValReads[BUTTON_LEFT])
|
|
|
|
outVal |= 2;
|
|
|
|
if(inValReads[BUTTON_UP])
|
|
|
|
outVal |= 4;
|
|
|
|
if(inValReads[BUTTON_DOWN])
|
|
|
|
outVal |= 8;
|
|
|
|
}
|
2017-05-29 03:19:19 +00:00
|
|
|
return (~(outVal|(modeSelect<<4)));
|
2017-05-12 03:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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]);
|
|
|
|
}
|