bananatools/taikoio/taikoio.c

131 lines
2.8 KiB
C
Raw Normal View History

2023-01-03 04:35:53 +00:00
#include <windows.h>
#include <xinput.h>
#include <limits.h>
#include <stdint.h>
#include <stdbool.h>
#include "taikoio/taikoio.h"
#include "taikoio/config.h"
2023-01-03 04:35:53 +00:00
#include "util/dprintf.h"
static bool taiko_io_coin = false;
static bool taiko_io_service = false;
static bool taiko_test_toggle = false;
static uint8_t taiko_opbtn = 0;
static uint16_t taiko_gamebtn = 0;
static uint16_t taiko_coin_ct = 0;
static uint16_t taiko_service_ct = 0;
static struct taiko_input_config cfg;
2023-01-03 04:35:53 +00:00
uint16_t taiko_io_get_api_version(void)
{
return 0x0100;
}
HRESULT taiko_io_init(void)
{
dprintf("Taiko IO: Init\n");
taiko_io_config_load(&cfg, L".\\bananatools.ini");
2023-01-03 04:35:53 +00:00
return S_OK;
}
HRESULT taiko_io_poll(void)
{
taiko_opbtn = 0;
taiko_gamebtn = 0;
if ((GetAsyncKeyState(cfg.test) & 0x8000)) {
2023-01-03 04:35:53 +00:00
taiko_opbtn |= TAIKO_IO_OPBTN_TEST;
}
if (GetAsyncKeyState(cfg.service) & 0x8000) {
2023-01-03 04:35:53 +00:00
taiko_opbtn |= TAIKO_IO_OPBTN_SERVICE;
}
if (GetAsyncKeyState(cfg.up) & 0x8000) {
2023-01-03 04:35:53 +00:00
taiko_opbtn |= TAIKO_IO_OPBTN_UP;
}
if (GetAsyncKeyState(cfg.down) & 0x8000) {
2023-01-03 04:35:53 +00:00
taiko_opbtn |= TAIKO_IO_OPBTN_DOWN;
}
if (GetAsyncKeyState(cfg.enter) & 0x8000) {
2023-01-03 04:35:53 +00:00
taiko_opbtn |= TAIKO_IO_OPBTN_ENTER;
}
if (GetAsyncKeyState(cfg.p1_rim_l) & 0x8000) {
2023-01-03 04:35:53 +00:00
taiko_gamebtn |= TAIKO_IO_P1_RIM_L;
}
if (GetAsyncKeyState(cfg.p1_center_l) & 0x8000) {
2023-01-03 04:35:53 +00:00
taiko_gamebtn |= TAIKO_IO_P1_CENTER_L;
}
if (GetAsyncKeyState(cfg.p1_center_r) & 0x8000) {
2023-01-03 04:35:53 +00:00
taiko_gamebtn |= TAIKO_IO_P1_CENTER_R;
}
if (GetAsyncKeyState(cfg.p1_rim_r) & 0x8000) {
2023-01-03 04:35:53 +00:00
taiko_gamebtn |= TAIKO_IO_P1_RIM_R;
}
if (GetAsyncKeyState(cfg.p2_rim_l) & 0x8000) {
2023-01-03 04:35:53 +00:00
taiko_gamebtn |= TAIKO_IO_P2_RIM_L;
}
if (GetAsyncKeyState(cfg.p2_center_l) & 0x8000) {
2023-01-03 04:35:53 +00:00
taiko_gamebtn |= TAIKO_IO_P2_CENTER_L;
}
if (GetAsyncKeyState(cfg.p2_center_r) & 0x8000) {
2023-01-03 04:35:53 +00:00
taiko_gamebtn |= TAIKO_IO_P2_CENTER_R;
}
if (GetAsyncKeyState(cfg.p2_rim_r) & 0x8000) {
2023-01-03 04:35:53 +00:00
taiko_gamebtn |= TAIKO_IO_P2_RIM_R;
}
return S_OK;
}
void taiko_io_get_opbtns(uint8_t *opbtn)
{
if (opbtn != NULL) {
*opbtn = taiko_opbtn;
}
}
void taiko_io_get_gamebtns(uint8_t *gamebtn)
{
if (gamebtn != NULL) {
*gamebtn = taiko_gamebtn;
}
}
void taiko_io_read_coin_counter(uint16_t *coins, uint16_t *services)
{
if (GetAsyncKeyState(VK_INSERT) & 0x8000) {
if (!taiko_io_coin) {
taiko_io_coin = true;
taiko_coin_ct++;
}
} else {
taiko_io_coin = false;
}
if (GetAsyncKeyState(VK_DELETE) & 0x8000) {
if (!taiko_io_service) {
taiko_io_service = true;
taiko_service_ct++;
}
} else {
taiko_io_service = false;
}
*coins = taiko_coin_ct;
*services = taiko_service_ct;
}