segatools2/mai2io/mai2io.c

84 lines
2.6 KiB
C
Raw Normal View History

2023-11-30 07:29:27 +00:00
#include <windows.h>
#include <xinput.h>
#include <limits.h>
#include <stdint.h>
#include "mai2io/mai2io.h"
#include "mai2io/config.h"
static struct mai2_io_config mai2_io_cfg;
uint16_t mai2_io_get_api_version(void)
{
return 0x0100;
}
HRESULT mai2_io_init(void)
{
mai2_io_config_load(&mai2_io_cfg, L".\\segatools.ini");
return S_OK;
}
HRESULT mai2_io_poll(uint8_t *opbtn, uint8_t *player1, uint8_t *player2)
{
uint8_t opts = 0;
uint8_t p1 = 0;
uint8_t p2 = 0;
if (GetAsyncKeyState(mai2_io_cfg.vk_test) & 0x8000) {
opts |= MAI2_IO_OPBTN_TEST;
}if (GetAsyncKeyState(mai2_io_cfg.vk_service) & 0x8000) {
opts |= MAI2_IO_OPBTN_SERVICE;
}if (GetAsyncKeyState(mai2_io_cfg.vk_coin) & 0x8000) {
opts |= MAI2_IO_OPBTN_COIN;
}if (GetAsyncKeyState(mai2_io_cfg.vk_p1_start) & 0x8000) {
opts |= MAI2_IO_P1_START;
}if (GetAsyncKeyState(mai2_io_cfg.vk_p2_start) & 0x8000) {
opts |= MAI2_IO_P2_START;
}
*opbtn = opts;
if (GetAsyncKeyState(mai2_io_cfg.vk_p1_btn[0]) & 0x8000) {
p1 |= MAI2_IO_GAMEBTN_1;
}if (GetAsyncKeyState(mai2_io_cfg.vk_p1_btn[1]) & 0x8000) {
p1 |= MAI2_IO_GAMEBTN_2;
}if (GetAsyncKeyState(mai2_io_cfg.vk_p1_btn[2]) & 0x8000) {
p1 |= MAI2_IO_GAMEBTN_3;
}if (GetAsyncKeyState(mai2_io_cfg.vk_p1_btn[3]) & 0x8000) {
p1 |= MAI2_IO_GAMEBTN_4;
}if (GetAsyncKeyState(mai2_io_cfg.vk_p1_btn[4]) & 0x8000) {
p1 |= MAI2_IO_GAMEBTN_5;
}if (GetAsyncKeyState(mai2_io_cfg.vk_p1_btn[5]) & 0x8000) {
p1 |= MAI2_IO_GAMEBTN_6;
}if (GetAsyncKeyState(mai2_io_cfg.vk_p1_btn[6]) & 0x8000) {
p1 |= MAI2_IO_GAMEBTN_7;
}if (GetAsyncKeyState(mai2_io_cfg.vk_p1_btn[7]) & 0x8000) {
p1 |= MAI2_IO_GAMEBTN_8;
}
*player1 = p1;
if (GetAsyncKeyState(mai2_io_cfg.vk_p2_btn[0]) & 0x8000) {
p2 |= MAI2_IO_GAMEBTN_1;
}if (GetAsyncKeyState(mai2_io_cfg.vk_p2_btn[1]) & 0x8000) {
p2 |= MAI2_IO_GAMEBTN_2;
}if (GetAsyncKeyState(mai2_io_cfg.vk_p2_btn[2]) & 0x8000) {
p2 |= MAI2_IO_GAMEBTN_3;
}if (GetAsyncKeyState(mai2_io_cfg.vk_p2_btn[3]) & 0x8000) {
p2 |= MAI2_IO_GAMEBTN_4;
}if (GetAsyncKeyState(mai2_io_cfg.vk_p2_btn[4]) & 0x8000) {
p2 |= MAI2_IO_GAMEBTN_5;
}if (GetAsyncKeyState(mai2_io_cfg.vk_p2_btn[5]) & 0x8000) {
p2 |= MAI2_IO_GAMEBTN_6;
}if (GetAsyncKeyState(mai2_io_cfg.vk_p2_btn[6]) & 0x8000) {
p2 |= MAI2_IO_GAMEBTN_7;
}if (GetAsyncKeyState(mai2_io_cfg.vk_p2_btn[7]) & 0x8000) {
p2 |= MAI2_IO_GAMEBTN_8;
}
*player2 = p2;
return S_OK;
}