bananatools/kizunaio/kizunaio.c

132 lines
3.0 KiB
C

#include <windows.h>
#include <xinput.h>
#include <limits.h>
#include <stdint.h>
#include <stdbool.h>
#include "kizunaio/kizunaio.h"
#include "kizunaio/config.h"
#include "util/dprintf.h"
static bool kizuna_io_coin = false;
static bool kizuna_io_service = false;
static bool kizuna_test_toggle = false;
static bool kizuna_test_last_state = false;
static uint16_t kizuna_coin_ct = 0;
static uint16_t kizuna_service_ct = 0;
static struct kizuna_input_config cfg;
uint16_t kizuna_io_get_api_version(void)
{
return 0x0100;
}
HRESULT kizuna_io_init(void)
{
dprintf("Kizuna IO: Init\n");
kizuna_io_config_load(&cfg, L".\\bananatools.ini");
return S_OK;
}
void kizuna_io_get_opbtns(uint8_t *opbtn)
{
if ((GetAsyncKeyState(cfg.test) & 0x8000)) {
if (!kizuna_test_last_state) {
kizuna_test_toggle = !kizuna_test_toggle;
}
kizuna_test_last_state = true;
} else {
kizuna_test_last_state = false;
}
if (GetAsyncKeyState(cfg.service) & 0x8000) {
*opbtn |= KIZUNA_IO_OPBTN_SERVICE;
}
if (GetAsyncKeyState(cfg.up) & 0x8000) {
*opbtn |= KIZUNA_IO_OPBTN_UP;
}
if (GetAsyncKeyState(cfg.down) & 0x8000) {
*opbtn |= KIZUNA_IO_OPBTN_DOWN;
}
if (GetAsyncKeyState(cfg.enter) & 0x8000) {
*opbtn |= KIZUNA_IO_OPBTN_ENTER;
}
if (kizuna_test_toggle) {
*opbtn |= KIZUNA_IO_OPBTN_TEST;
}
}
void kizuna_io_get_gamebtns(uint8_t *gamebtns)
{
*gamebtns = 0;
if (GetAsyncKeyState(cfg.btn1) & 0x8000) {
*gamebtns |= KIZUNA_IO_GAMEBTN_1;
}
if (GetAsyncKeyState(cfg.btn2) & 0x8000) {
*gamebtns |= KIZUNA_IO_GAMEBTN_2;
}
if (GetAsyncKeyState(cfg.btn3) & 0x8000) {
*gamebtns |= KIZUNA_IO_GAMEBTN_3;
}
if (GetAsyncKeyState(cfg.stick_btn1) & 0x8000) {
*gamebtns |= KIZUNA_IO_GAMEBTN_STICK1;
}
if (GetAsyncKeyState(cfg.stick_btn2) & 0x8000) {
*gamebtns |= KIZUNA_IO_GAMEBTN_STICK2;
}
if (GetAsyncKeyState(cfg.stick_btn3) & 0x8000) {
*gamebtns |= KIZUNA_IO_GAMEBTN_STICK3;
}
}
void kizuna_io_get_analog(uint8_t *x, uint8_t *y)
{
*x = 128;
*y = 128;
if (GetAsyncKeyState(cfg.stick_up) & 0x8000) {
*y += 127;
}
if (GetAsyncKeyState(cfg.stick_down) & 0x8000) {
*y -= 128;
}
if (GetAsyncKeyState(cfg.stick_right) & 0x8000) {
*x += 127;
}
if (GetAsyncKeyState(cfg.stick_left) & 0x8000) {
*x -= 128;
}
}
void kizuna_io_read_coin_counter(uint16_t *coins, uint16_t *services)
{
if (GetAsyncKeyState(cfg.coin) & 0x8000) {
if (!kizuna_io_coin) {
kizuna_io_coin = true;
kizuna_coin_ct++;
}
} else {
kizuna_io_coin = false;
}
if (GetAsyncKeyState(cfg.service) & 0x8000) {
if (!kizuna_io_service) {
kizuna_io_service = true;
kizuna_service_ct++;
}
} else {
kizuna_io_service = false;
}
*coins = kizuna_coin_ct;
*services = kizuna_service_ct;
}