1
0
mirror of synced 2024-11-24 05:50:12 +01:00
bananatools/saoio/saoio.c

132 lines
2.9 KiB
C
Raw Permalink Normal View History

2023-09-18 10:05:22 +02:00
#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_gamebtns(uint8_t *gamebtns)
2023-09-18 10:05:22 +02:00
{
*gamebtns = 0;
if (GetAsyncKeyState(cfg.btn1) & 0x8000) {
*gamebtns |= SAO_IO_GAMEBTN_1;
2023-09-18 10:05:22 +02:00
}
if (GetAsyncKeyState(cfg.btn2) & 0x8000) {
*gamebtns |= SAO_IO_GAMEBTN_2;
2023-09-18 10:05:22 +02:00
}
if (GetAsyncKeyState(cfg.btn3) & 0x8000) {
*gamebtns |= SAO_IO_GAMEBTN_3;
2023-09-18 10:05:22 +02:00
}
if (GetAsyncKeyState(cfg.stick_btn1) & 0x8000) {
*gamebtns |= SAO_IO_GAMEBTN_STICK1;
}
if (GetAsyncKeyState(cfg.stick_btn2) & 0x8000) {
*gamebtns |= SAO_IO_GAMEBTN_STICK2;
2023-09-18 10:05:22 +02:00
}
if (GetAsyncKeyState(cfg.stick_btn3) & 0x8000) {
*gamebtns |= SAO_IO_GAMEBTN_STICK3;
}
}
2023-09-18 10:05:22 +02:00
void sao_io_get_analog(uint8_t *x, uint8_t *y)
{
*x = 128;
*y = 128;
if (GetAsyncKeyState(cfg.stick_up) & 0x8000) {
*y += 127;
2023-09-18 10:05:22 +02:00
}
if (GetAsyncKeyState(cfg.stick_down) & 0x8000) {
*y -= 128;
2023-09-18 10:05:22 +02:00
}
if (GetAsyncKeyState(cfg.stick_right) & 0x8000) {
*x += 127;
2023-09-18 10:05:22 +02:00
}
if (GetAsyncKeyState(cfg.stick_left) & 0x8000) {
*x -= 128;
2023-09-18 10:05:22 +02:00
}
}
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;
}