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

128 lines
2.9 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 "ferrumio/ferrumio.h"
#include "ferrumio/config.h"
#include "util/dprintf.h"
static bool ferrum_io_coin = false;
static bool ferrum_test_toggle = false;
static uint16_t ferrum_coin_ct = 0;
static struct ferrum_gamepad_config gamepad_cfg;
static struct ferrum_najv4_config najv4_cfg;
uint16_t ferrum_io_get_api_version(void)
{
return 0x0100;
}
HRESULT ferrum_io_jvs_init(void)
{
dprintf("Ferrum IO: JVS Init\n");
ferrum_io_najv4_config_load(&najv4_cfg, L".\\bananatools.ini");
return S_OK;
}
HRESULT ferrum_io_gamepad_init(void)
{
dprintf("Ferrum IO: Gamepad Init\n");
ferrum_io_gamepad_config_load(&gamepad_cfg, L".\\bananatools.ini");
return S_OK;
}
HRESULT ferrum_io_jvs_poll(uint8_t *opbtn)
{
*opbtn = 0;
if ((GetAsyncKeyState(najv4_cfg.test) & 0x8000)) {
*opbtn |= FERRUM_IO_OPBTN_TEST;
}
if (GetAsyncKeyState(najv4_cfg.service) & 0x8000) {
*opbtn |= FERRUM_IO_OPBTN_SERVICE;
}
if (GetAsyncKeyState(najv4_cfg.up) & 0x8000) {
*opbtn |= FERRUM_IO_OPBTN_UP;
}
if (GetAsyncKeyState(najv4_cfg.down) & 0x8000) {
*opbtn |= FERRUM_IO_OPBTN_DOWN;
}
if (GetAsyncKeyState(najv4_cfg.enter) & 0x8000) {
*opbtn |= FERRUM_IO_OPBTN_ENTER;
}
return S_OK;
}
HRESULT ferrum_io_gamepad_poll(uint16_t *gamepad)
{
*gamepad = 0;
if (GetAsyncKeyState(gamepad_cfg.dpad_up) & 0x8000) {
*gamepad |= FERRUM_IO_GAMEBTN_UP;
}
if (GetAsyncKeyState(gamepad_cfg.dpad_left) & 0x8000) {
*gamepad |= FERRUM_IO_GAMEBTN_LEFT;
}
if (GetAsyncKeyState(gamepad_cfg.dpad_down) & 0x8000) {
*gamepad |= FERRUM_IO_GAMEBTN_DOWN;
}
if (GetAsyncKeyState(gamepad_cfg.dpad_right) & 0x8000) {
*gamepad |= FERRUM_IO_GAMEBTN_RIGHT;
}
if (GetAsyncKeyState(gamepad_cfg.trigger_l) & 0x8000) {
*gamepad |= FERRUM_IO_GAMEBTN_TRIGGER_L;
}
if (GetAsyncKeyState(gamepad_cfg.trigger_r) & 0x8000) {
*gamepad |= FERRUM_IO_GAMEBTN_TRIGGER_R;
}
if (GetAsyncKeyState(gamepad_cfg.btn_a) & 0x8000) {
*gamepad |= FERRUM_IO_GAMEBTN_A;
}
if (GetAsyncKeyState(gamepad_cfg.btn_b) & 0x8000) {
*gamepad |= FERRUM_IO_GAMEBTN_B;
}
if (GetAsyncKeyState(gamepad_cfg.btn_x) & 0x8000) {
*gamepad |= FERRUM_IO_GAMEBTN_X;
}
if (GetAsyncKeyState(gamepad_cfg.btn_y) & 0x8000) {
*gamepad |= FERRUM_IO_GAMEBTN_Y;
}
if (GetAsyncKeyState(gamepad_cfg.btn_start) & 0x8000) {
*gamepad |= FERRUM_IO_GAMEBTN_START;
}
return S_OK;
}
void ferrum_io_jvs_read_coin_counter(uint16_t *coins)
{
if (GetAsyncKeyState(VK_INSERT) & 0x8000) {
if (!ferrum_io_coin) {
ferrum_io_coin = true;
ferrum_coin_ct++;
}
} else {
ferrum_io_coin = false;
}
*coins = ferrum_coin_ct;
}