1
0
mirror of synced 2024-12-18 07:05:52 +01:00
bananatools/taikoio/taikoio.c

123 lines
2.8 KiB
C
Raw Normal View History

2023-01-03 05:35:53 +01: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 05:35:53 +01:00
#include "util/dprintf.h"
static bool taiko_io_coin = false;
static bool taiko_io_service = false;
static bool taiko_test_toggle = false;
2023-07-29 08:51:58 +02:00
static bool taiko_test_last_state = false;
2023-01-03 05:35:53 +01:00
static uint16_t taiko_coin_ct = 0;
static uint16_t taiko_service_ct = 0;
static struct taiko_input_config cfg;
2023-01-03 05:35:53 +01: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 05:35:53 +01:00
return S_OK;
}
2023-07-29 08:51:58 +02:00
void taiko_io_get_opbtns(uint8_t *opbtn)
2023-01-03 05:35:53 +01:00
{
if ((GetAsyncKeyState(cfg.test) & 0x8000)) {
2023-07-29 08:51:58 +02:00
if (!taiko_test_last_state) {
taiko_test_toggle = !taiko_test_toggle;
}
taiko_test_last_state = true;
} else {
taiko_test_last_state = false;
2023-01-03 05:35:53 +01:00
}
if (GetAsyncKeyState(cfg.service) & 0x8000) {
2023-07-29 08:51:58 +02:00
*opbtn |= TAIKO_IO_OPBTN_SERVICE;
2023-01-03 05:35:53 +01:00
}
if (GetAsyncKeyState(cfg.up) & 0x8000) {
2023-07-29 08:51:58 +02:00
*opbtn |= TAIKO_IO_OPBTN_UP;
2023-01-03 05:35:53 +01:00
}
if (GetAsyncKeyState(cfg.down) & 0x8000) {
2023-07-29 08:51:58 +02:00
*opbtn |= TAIKO_IO_OPBTN_DOWN;
2023-01-03 05:35:53 +01:00
}
if (GetAsyncKeyState(cfg.enter) & 0x8000) {
2023-07-29 08:51:58 +02:00
*opbtn |= TAIKO_IO_OPBTN_ENTER;
}
if (taiko_test_toggle) {
*opbtn |= TAIKO_IO_OPBTN_TEST;
2023-01-03 05:35:53 +01:00
}
2023-07-29 08:51:58 +02:00
}
2023-01-03 05:35:53 +01:00
2023-07-29 08:51:58 +02:00
void taiko_io_get_drum_analog(uint8_t *gamebtn)
{
if (GetAsyncKeyState(cfg.p1_rim_l) & 0x8000) {
2023-07-29 08:51:58 +02:00
*gamebtn |= TAIKO_IO_P1_RIM_L;
2023-01-03 05:35:53 +01:00
}
if (GetAsyncKeyState(cfg.p1_center_l) & 0x8000) {
2023-07-29 08:51:58 +02:00
*gamebtn |= TAIKO_IO_P1_CENTER_L;
2023-01-03 05:35:53 +01:00
}
if (GetAsyncKeyState(cfg.p1_center_r) & 0x8000) {
2023-07-29 08:51:58 +02:00
*gamebtn |= TAIKO_IO_P1_CENTER_R;
2023-01-03 05:35:53 +01:00
}
if (GetAsyncKeyState(cfg.p1_rim_r) & 0x8000) {
2023-07-29 08:51:58 +02:00
*gamebtn |= TAIKO_IO_P1_RIM_R;
2023-01-03 05:35:53 +01:00
}
if (GetAsyncKeyState(cfg.p2_rim_l) & 0x8000) {
2023-07-29 08:51:58 +02:00
*gamebtn |= TAIKO_IO_P2_RIM_L;
2023-01-03 05:35:53 +01:00
}
if (GetAsyncKeyState(cfg.p2_center_l) & 0x8000) {
2023-07-29 08:51:58 +02:00
*gamebtn |= TAIKO_IO_P2_CENTER_L;
2023-01-03 05:35:53 +01:00
}
if (GetAsyncKeyState(cfg.p2_center_r) & 0x8000) {
2023-07-29 08:51:58 +02:00
*gamebtn |= TAIKO_IO_P2_CENTER_R;
2023-01-03 05:35:53 +01:00
}
if (GetAsyncKeyState(cfg.p2_rim_r) & 0x8000) {
2023-07-29 08:51:58 +02:00
*gamebtn |= TAIKO_IO_P2_RIM_R;
2023-01-03 05:35:53 +01:00
}
}
void taiko_io_read_coin_counter(uint16_t *coins, uint16_t *services)
{
2023-07-29 08:51:58 +02:00
if (GetAsyncKeyState(cfg.coin) & 0x8000) {
2023-01-03 05:35:53 +01:00
if (!taiko_io_coin) {
taiko_io_coin = true;
taiko_coin_ct++;
}
} else {
taiko_io_coin = false;
}
2023-07-29 08:51:58 +02:00
if (GetAsyncKeyState(cfg.service) & 0x8000) {
2023-01-03 05:35:53 +01:00
if (!taiko_io_service) {
taiko_io_service = true;
taiko_service_ct++;
}
} else {
taiko_io_service = false;
}
*coins = taiko_coin_ct;
*services = taiko_service_ct;
}