bananatools/exvs2io/exvs2io.c
2023-09-23 01:58:56 -04:00

93 lines
2.0 KiB
C

#include <windows.h>
#include <xinput.h>
#include <limits.h>
#include <stdint.h>
#include <stdbool.h>
#include "exvs2io/exvs2io.h"
#include "exvs2io/config.h"
#include "util/dprintf.h"
static bool exvs2_io_coin = false;
static uint16_t exvs2_coin_ct = 0;
static struct exvs2_najv4_config najv4_cfg;
uint16_t exvs2_io_get_api_version(void)
{
return 0x0100;
}
HRESULT exvs2_io_jvs_init(void)
{
dprintf("exvs2 IO: JVS Init\n");
exvs2_io_najv4_config_load(&najv4_cfg, L".\\bananatools.ini");
return S_OK;
}
HRESULT exvs2_io_jvs_poll(uint8_t *opbtn, uint16_t *gamepad)
{
*opbtn = 0;
*gamepad = 0;
if ((GetAsyncKeyState(najv4_cfg.test) & 0x8000)) {
*opbtn |= EXVS2_IO_OPBTN_TEST;
}
if (GetAsyncKeyState(najv4_cfg.service) & 0x8000) {
*opbtn |= EXVS2_IO_OPBTN_SERVICE;
}
if (GetAsyncKeyState(najv4_cfg.up) & 0x8000) {
*gamepad |= EXVS2_IO_GAMEBTN_UP;
}
if (GetAsyncKeyState(najv4_cfg.down) & 0x8000) {
*gamepad |= EXVS2_IO_GAMEBTN_DOWN;
}
if (GetAsyncKeyState(najv4_cfg.left) & 0x8000) {
*gamepad |= EXVS2_IO_GAMEBTN_LEFT;
}
if (GetAsyncKeyState(najv4_cfg.right) & 0x8000) {
*gamepad |= EXVS2_IO_GAMEBTN_RIGHT;
}
if (GetAsyncKeyState(najv4_cfg.start) & 0x8000) {
*gamepad |= EXVS2_IO_GAMEBTN_START;
}
if (GetAsyncKeyState(najv4_cfg.btn1) & 0x8000) {
*gamepad |= EXVS2_IO_GAMEBTN_1;
}
if (GetAsyncKeyState(najv4_cfg.btn2) & 0x8000) {
*gamepad |= EXVS2_IO_GAMEBTN_2;
}
if (GetAsyncKeyState(najv4_cfg.btn3) & 0x8000) {
*gamepad |= EXVS2_IO_GAMEBTN_3;
}
if (GetAsyncKeyState(najv4_cfg.btn4) & 0x8000) {
*gamepad |= EXVS2_IO_GAMEBTN_4;
}
return S_OK;
}
void exvs2_io_jvs_read_coin_counter(uint16_t *coins)
{
if (GetAsyncKeyState(najv4_cfg.coin) & 0x8000) {
if (!exvs2_io_coin) {
exvs2_io_coin = true;
exvs2_coin_ct++;
}
} else {
exvs2_io_coin = false;
}
*coins = exvs2_coin_ct;
}