1
0
mirror of synced 2024-11-27 23:10:49 +01:00
bananatools/mkacio/mkacio.c

128 lines
2.8 KiB
C
Raw 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 "mkacio/mkacio.h"
#include "mkacio/config.h"
#include "util/dprintf.h"
static bool mkac_io_coin = false;
static bool mkac_test_toggle = false;
static uint16_t mkac_coin_ct = 0;
static struct mkac_gamepad_config gamepad_cfg;
static struct mkac_najv4_config najv4_cfg;
uint16_t mkac_io_get_api_version(void)
{
return 0x0100;
}
HRESULT mkac_io_jvs_init(void)
{
dprintf("mkac IO: JVS Init\n");
mkac_io_najv4_config_load(&najv4_cfg, L".\\bananatools.ini");
return S_OK;
}
HRESULT mkac_io_gamepad_init(void)
{
dprintf("mkac IO: Gamepad Init\n");
mkac_io_gamepad_config_load(&gamepad_cfg, L".\\bananatools.ini");
return S_OK;
}
HRESULT mkac_io_jvs_poll(uint8_t *opbtn)
{
*opbtn = 0;
if ((GetAsyncKeyState(najv4_cfg.test) & 0x8000)) {
*opbtn |= mkac_IO_OPBTN_TEST;
}
if (GetAsyncKeyState(najv4_cfg.service) & 0x8000) {
*opbtn |= mkac_IO_OPBTN_SERVICE;
}
if (GetAsyncKeyState(najv4_cfg.up) & 0x8000) {
*opbtn |= mkac_IO_OPBTN_UP;
}
if (GetAsyncKeyState(najv4_cfg.down) & 0x8000) {
*opbtn |= mkac_IO_OPBTN_DOWN;
}
if (GetAsyncKeyState(najv4_cfg.enter) & 0x8000) {
*opbtn |= mkac_IO_OPBTN_ENTER;
}
return S_OK;
}
HRESULT mkac_io_gamepad_poll(uint16_t *gamepad)
{
*gamepad = 0;
if (GetAsyncKeyState(gamepad_cfg.dpad_up) & 0x8000) {
*gamepad |= mkac_IO_GAMEBTN_UP;
}
if (GetAsyncKeyState(gamepad_cfg.dpad_left) & 0x8000) {
*gamepad |= mkac_IO_GAMEBTN_LEFT;
}
if (GetAsyncKeyState(gamepad_cfg.dpad_down) & 0x8000) {
*gamepad |= mkac_IO_GAMEBTN_DOWN;
}
if (GetAsyncKeyState(gamepad_cfg.dpad_right) & 0x8000) {
*gamepad |= mkac_IO_GAMEBTN_RIGHT;
}
if (GetAsyncKeyState(gamepad_cfg.trigger_l) & 0x8000) {
*gamepad |= mkac_IO_GAMEBTN_TRIGGER_L;
}
if (GetAsyncKeyState(gamepad_cfg.trigger_r) & 0x8000) {
*gamepad |= mkac_IO_GAMEBTN_TRIGGER_R;
}
if (GetAsyncKeyState(gamepad_cfg.btn_a) & 0x8000) {
*gamepad |= mkac_IO_GAMEBTN_A;
}
if (GetAsyncKeyState(gamepad_cfg.btn_b) & 0x8000) {
*gamepad |= mkac_IO_GAMEBTN_B;
}
if (GetAsyncKeyState(gamepad_cfg.btn_x) & 0x8000) {
*gamepad |= mkac_IO_GAMEBTN_X;
}
if (GetAsyncKeyState(gamepad_cfg.btn_y) & 0x8000) {
*gamepad |= mkac_IO_GAMEBTN_Y;
}
if (GetAsyncKeyState(gamepad_cfg.btn_start) & 0x8000) {
*gamepad |= mkac_IO_GAMEBTN_START;
}
return S_OK;
}
void mkac_io_jvs_read_coin_counter(uint16_t *coins)
{
if (GetAsyncKeyState(VK_INSERT) & 0x8000) {
if (!mkac_io_coin) {
mkac_io_coin = true;
mkac_coin_ct++;
}
} else {
mkac_io_coin = false;
}
*coins = mkac_coin_ct;
}