bananatools/saoio/saoio.c

123 lines
2.7 KiB
C

#include <windows.h>
#include <xinput.h>
#include <limits.h>
#include <stdint.h>
#include <stdbool.h>
#include "saoio/saoio.h"
#include "saoio/config.h"
#include "util/dprintf.h"
static bool sao_io_coin = false;
static bool sao_io_service = false;
static bool sao_test_toggle = false;
static bool sao_test_last_state = false;
static uint16_t sao_coin_ct = 0;
static uint16_t sao_service_ct = 0;
static struct sao_input_config cfg;
uint16_t sao_io_get_api_version(void)
{
return 0x0100;
}
HRESULT sao_io_init(void)
{
dprintf("Sao IO: Init\n");
sao_io_config_load(&cfg, L".\\bananatools.ini");
return S_OK;
}
void sao_io_get_opbtns(uint8_t *opbtn)
{
if ((GetAsyncKeyState(cfg.test) & 0x8000)) {
if (!sao_test_last_state) {
sao_test_toggle = !sao_test_toggle;
}
sao_test_last_state = true;
} else {
sao_test_last_state = false;
}
if (GetAsyncKeyState(cfg.service) & 0x8000) {
*opbtn |= SAO_IO_OPBTN_SERVICE;
}
if (GetAsyncKeyState(cfg.up) & 0x8000) {
*opbtn |= SAO_IO_OPBTN_UP;
}
if (GetAsyncKeyState(cfg.down) & 0x8000) {
*opbtn |= SAO_IO_OPBTN_DOWN;
}
if (GetAsyncKeyState(cfg.enter) & 0x8000) {
*opbtn |= SAO_IO_OPBTN_ENTER;
}
if (sao_test_toggle) {
*opbtn |= SAO_IO_OPBTN_TEST;
}
}
void sao_io_get_drum_analog(uint8_t *gamebtn)
{
if (GetAsyncKeyState(cfg.p1_rim_l) & 0x8000) {
*gamebtn |= SAO_IO_P1_RIM_L;
}
if (GetAsyncKeyState(cfg.p1_center_l) & 0x8000) {
*gamebtn |= SAO_IO_P1_CENTER_L;
}
if (GetAsyncKeyState(cfg.p1_center_r) & 0x8000) {
*gamebtn |= SAO_IO_P1_CENTER_R;
}
if (GetAsyncKeyState(cfg.p1_rim_r) & 0x8000) {
*gamebtn |= SAO_IO_P1_RIM_R;
}
if (GetAsyncKeyState(cfg.p2_rim_l) & 0x8000) {
*gamebtn |= SAO_IO_P2_RIM_L;
}
if (GetAsyncKeyState(cfg.p2_center_l) & 0x8000) {
*gamebtn |= SAO_IO_P2_CENTER_L;
}
if (GetAsyncKeyState(cfg.p2_center_r) & 0x8000) {
*gamebtn |= SAO_IO_P2_CENTER_R;
}
if (GetAsyncKeyState(cfg.p2_rim_r) & 0x8000) {
*gamebtn |= SAO_IO_P2_RIM_R;
}
}
void sao_io_read_coin_counter(uint16_t *coins, uint16_t *services)
{
if (GetAsyncKeyState(cfg.coin) & 0x8000) {
if (!sao_io_coin) {
sao_io_coin = true;
sao_coin_ct++;
}
} else {
sao_io_coin = false;
}
if (GetAsyncKeyState(cfg.service) & 0x8000) {
if (!sao_io_service) {
sao_io_service = true;
sao_service_ct++;
}
} else {
sao_io_service = false;
}
*coins = sao_coin_ct;
*services = sao_service_ct;
}